From fdf5f2519ead7de4d91a9e1a01d184cef14bfcd4 Mon Sep 17 00:00:00 2001 From: Jamie Birch <14055146+shirakaba@users.noreply.github.com> Date: Sat, 22 Nov 2025 09:57:21 +0900 Subject: [PATCH] fix: avoid reallocating views on RCTDevLoadingView progress updates --- .../React/CoreModules/RCTDevLoadingView.mm | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index 64276ea56676ad..ff71221beb16bd 100644 --- a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm +++ b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm @@ -128,33 +128,21 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo self->_window = [[UIWindow alloc] initWithWindowScene:mainWindow.windowScene]; self->_window.windowLevel = UIWindowLevelStatusBar + 1; self->_window.rootViewController = [UIViewController new]; -#else // [macOS - self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20) - styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView - backing:NSBackingStoreBuffered - defer:YES]; - [self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier]; -#endif // macOS] - self->_container = [[RCTUIView alloc] init]; // [macOS] + self->_container = [[UIView alloc] init]; self->_container.backgroundColor = backgroundColor; self->_container.translatesAutoresizingMaskIntoConstraints = NO; - self->_label = [[RCTUILabel alloc] init]; // [macOS] + self->_label = [[UILabel alloc] init]; self->_label.translatesAutoresizingMaskIntoConstraints = NO; self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular]; self->_label.textAlignment = NSTextAlignmentCenter; self->_label.textColor = color; self->_label.text = message; -#if !TARGET_OS_OSX // [macOS] [self->_window.rootViewController.view addSubview:self->_container]; -#else // [macOS - [self->_window.contentView addSubview:self->_container]; -#endif // macOS] [self->_container addSubview:self->_label]; -#if !TARGET_OS_OSX // [macOS] CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets.top; CGFloat height = topSafeAreaHeight + 25; self->_window.frame = CGRectMake(0, 0, mainWindow.frame.size.width, height); @@ -175,6 +163,31 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo [self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5], ]]; #else // [macOS + if (!self->_label) { + self->_label = [[RCTUILabel alloc] init]; // [macOS] + self->_label.translatesAutoresizingMaskIntoConstraints = NO; + self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular]; + self->_label.textAlignment = NSTextAlignmentCenter; + } + self->_label.textColor = color; + self->_label.text = message; + + if (!self->_container) { + self->_container = [[RCTUIView alloc] init]; // [macOS] + self->_container.translatesAutoresizingMaskIntoConstraints = NO; + [self->_container addSubview:self->_label]; + } + self->_container.backgroundColor = backgroundColor; + + if (!self->_window) { + self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20) + styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView + backing:NSBackingStoreBuffered + defer:YES]; + [self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier]; + [self->_window.contentView addSubview:self->_container]; + } + // Container constraints [NSLayoutConstraint activateConstraints:@[ [self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor],