Skip to content

Commit 9699933

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Add hostname to loading banner on iOS
Summary: This diff adds a hostname to the loading banner on iOS so it's clear which server you're loading from. Changelog: [Added] [iOS] Added hostname to loading banner. Reviewed By: PeteTheHeat Differential Revision: D21280252 fbshipit-source-id: d7733c056f5fb63e32b247a4fa1476ab42c7da17
1 parent e9f29a3 commit 9699933

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

React/CoreModules/RCTDevLoadingView.mm

+39-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ @interface RCTDevLoadingView () <NativeDevLoadingViewSpec>
2929
@implementation RCTDevLoadingView {
3030
UIWindow *_window;
3131
UILabel *_label;
32+
UILabel *_host;
3233
NSDate *_showDate;
3334
}
3435

@@ -64,6 +65,24 @@ - (void)setBridge:(RCTBridge *)bridge
6465
}
6566
}
6667

68+
- (UIColor *)dimColor:(UIColor *)c
69+
{
70+
// Given a color, return a slightly lighter or darker color for dim effect.
71+
CGFloat h, s, b, a;
72+
if ([c getHue:&h saturation:&s brightness:&b alpha:&a])
73+
return [UIColor colorWithHue:h saturation:s brightness:b < 0.5 ? b * 1.25 : b * 0.75 alpha:a];
74+
return nil;
75+
}
76+
77+
- (NSString *)getTextForHost
78+
{
79+
if (self->_bridge.bundleURL == nil || self->_bridge.bundleURL.fileURL) {
80+
return @"React Native";
81+
}
82+
83+
return [NSString stringWithFormat:@"%@:%@", self->_bridge.bundleURL.host, self->_bridge.bundleURL.port];
84+
}
85+
6786
- (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(UIColor *)backgroundColor
6887
{
6988
if (!RCTDevLoadingViewGetEnabled()) {
@@ -78,18 +97,25 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
7897
if (@available(iOS 11.0, *)) {
7998
UIWindow *window = RCTSharedApplication().keyWindow;
8099
self->_window =
81-
[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, window.safeAreaInsets.top + 30)];
82-
self->_label = [[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top, screenSize.width, 30)];
100+
[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, window.safeAreaInsets.top + 52)];
101+
self->_label = [[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top, screenSize.width, 22)];
102+
self->_host =
103+
[[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top + 20, screenSize.width, 22)];
104+
self->_host.font = [UIFont monospacedDigitSystemFontOfSize:10.0 weight:UIFontWeightRegular];
105+
self->_host.textAlignment = NSTextAlignmentCenter;
106+
107+
[self->_window addSubview:self->_label];
108+
[self->_window addSubview:self->_host];
109+
83110
} else {
84111
self->_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, 22)];
85112
self->_label = [[UILabel alloc] initWithFrame:self->_window.bounds];
113+
114+
[self->_window addSubview:self->_label];
115+
// TODO: Add host to iOS < 11.0
86116
}
87-
[self->_window addSubview:self->_label];
88-
#if TARGET_OS_TV
89-
self->_window.windowLevel = UIWindowLevelNormal + 1;
90-
#else
117+
91118
self->_window.windowLevel = UIWindowLevelStatusBar + 1;
92-
#endif
93119
// set a root VC so rotation is supported
94120
self->_window.rootViewController = [UIViewController new];
95121

@@ -99,6 +125,12 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
99125

100126
self->_label.text = message;
101127
self->_label.textColor = color;
128+
129+
if (self->_host != nil) {
130+
self->_host.text = [self getTextForHost];
131+
self->_host.textColor = [self dimColor:color];
132+
}
133+
102134
self->_window.backgroundColor = backgroundColor;
103135
self->_window.hidden = NO;
104136

0 commit comments

Comments
 (0)