Skip to content

Commit f9f8340

Browse files
committed
reduce the ifdef diff from upstream
1 parent 92ec320 commit f9f8340

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

packages/react-native/React/CoreModules/RCTDevLoadingView.mm

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,51 +122,35 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
122122
}
123123

124124
self->_showDate = [NSDate date];
125+
126+
#if !TARGET_OS_OSX // [macOS]
127+
UIWindow *mainWindow = RCTKeyWindow();
128+
self->_window = [[UIWindow alloc] initWithWindowScene:mainWindow.windowScene];
129+
self->_window.windowLevel = UIWindowLevelStatusBar + 1;
130+
self->_window.rootViewController = [UIViewController new];
125131

126-
if (!self->_label) {
127-
self->_label = [[RCTUILabel alloc] init]; // [macOS]
128-
self->_label.translatesAutoresizingMaskIntoConstraints = NO;
129-
self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
130-
self->_label.textAlignment = NSTextAlignmentCenter;
131-
}
132+
self->_container = [[UIView alloc] init];
133+
self->_container.backgroundColor = backgroundColor;
134+
self->_container.translatesAutoresizingMaskIntoConstraints = NO;
135+
136+
self->_label = [[UILabel alloc] init];
137+
self->_label.translatesAutoresizingMaskIntoConstraints = NO;
138+
self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
139+
self->_label.textAlignment = NSTextAlignmentCenter;
132140
self->_label.textColor = color;
133141
self->_label.text = message;
134142

135-
if (!self->_container) {
136-
self->_container = [[RCTUIView alloc] init]; // [macOS]
137-
self->_container.translatesAutoresizingMaskIntoConstraints = NO;
138-
[self->_container addSubview:self->_label];
139-
}
140-
self->_container.backgroundColor = backgroundColor;
141-
142-
#if !TARGET_OS_OSX // [macOS]
143-
UIWindow *mainWindow = RCTKeyWindow();
144-
if (!self->_window) {
145-
self->_window = [[UIWindow alloc] initWithWindowScene:mainWindow.windowScene];
146-
self->_window.windowLevel = UIWindowLevelStatusBar + 1;
147-
self->_window.rootViewController = [UIViewController new];
148-
[self->_window.rootViewController.view addSubview:self->_container];
149-
}
150-
#else // [macOS
151-
if (!self->_window) {
152-
self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20)
153-
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
154-
backing:NSBackingStoreBuffered
155-
defer:YES];
156-
[self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier];
157-
[self->_window.contentView addSubview:self->_container];
158-
}
159-
#endif // macOS]
143+
[self->_window.rootViewController.view addSubview:self->_container];
144+
[self->_container addSubview:self->_label];
160145

161-
#if !TARGET_OS_OSX // [macOS]
162146
CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets.top;
163147
CGFloat height = topSafeAreaHeight + 25;
164148
self->_window.frame = CGRectMake(0, 0, mainWindow.frame.size.width, height);
165149

166150
self->_window.hidden = NO;
167151

168152
[self->_window layoutIfNeeded];
169-
153+
170154
[NSLayoutConstraint activateConstraints:@[
171155
// Container constraints
172156
[self->_container.topAnchor constraintEqualToAnchor:self->_window.rootViewController.view.topAnchor],
@@ -179,6 +163,31 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
179163
[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5],
180164
]];
181165
#else // [macOS
166+
if (!self->_label) {
167+
self->_label = [[RCTUILabel alloc] init]; // [macOS]
168+
self->_label.translatesAutoresizingMaskIntoConstraints = NO;
169+
self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
170+
self->_label.textAlignment = NSTextAlignmentCenter;
171+
}
172+
self->_label.textColor = color;
173+
self->_label.text = message;
174+
175+
if (!self->_container) {
176+
self->_container = [[RCTUIView alloc] init]; // [macOS]
177+
self->_container.translatesAutoresizingMaskIntoConstraints = NO;
178+
[self->_container addSubview:self->_label];
179+
}
180+
self->_container.backgroundColor = backgroundColor;
181+
182+
if (!self->_window) {
183+
self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20)
184+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
185+
backing:NSBackingStoreBuffered
186+
defer:YES];
187+
[self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier];
188+
[self->_window.contentView addSubview:self->_container];
189+
}
190+
182191
// Container constraints
183192
[NSLayoutConstraint activateConstraints:@[
184193
[self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor],

0 commit comments

Comments
 (0)