Skip to content

Commit fdf5f25

Browse files
committed
fix: avoid reallocating views on RCTDevLoadingView progress updates
1 parent 0ee9be8 commit fdf5f25

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,21 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
128128
self->_window = [[UIWindow alloc] initWithWindowScene:mainWindow.windowScene];
129129
self->_window.windowLevel = UIWindowLevelStatusBar + 1;
130130
self->_window.rootViewController = [UIViewController new];
131-
#else // [macOS
132-
self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20)
133-
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
134-
backing:NSBackingStoreBuffered
135-
defer:YES];
136-
[self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier];
137-
#endif // macOS]
138131

139-
self->_container = [[RCTUIView alloc] init]; // [macOS]
132+
self->_container = [[UIView alloc] init];
140133
self->_container.backgroundColor = backgroundColor;
141134
self->_container.translatesAutoresizingMaskIntoConstraints = NO;
142135

143-
self->_label = [[RCTUILabel alloc] init]; // [macOS]
136+
self->_label = [[UILabel alloc] init];
144137
self->_label.translatesAutoresizingMaskIntoConstraints = NO;
145138
self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
146139
self->_label.textAlignment = NSTextAlignmentCenter;
147140
self->_label.textColor = color;
148141
self->_label.text = message;
149142

150-
#if !TARGET_OS_OSX // [macOS]
151143
[self->_window.rootViewController.view addSubview:self->_container];
152-
#else // [macOS
153-
[self->_window.contentView addSubview:self->_container];
154-
#endif // macOS]
155144
[self->_container addSubview:self->_label];
156145

157-
#if !TARGET_OS_OSX // [macOS]
158146
CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets.top;
159147
CGFloat height = topSafeAreaHeight + 25;
160148
self->_window.frame = CGRectMake(0, 0, mainWindow.frame.size.width, height);
@@ -175,6 +163,31 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
175163
[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5],
176164
]];
177165
#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+
178191
// Container constraints
179192
[NSLayoutConstraint activateConstraints:@[
180193
[self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor],

0 commit comments

Comments
 (0)