From 8009b1878712272d5f75cbcf1a9aad0f5d71307c Mon Sep 17 00:00:00 2001 From: ZJH <> Date: Sun, 28 Sep 2025 01:03:01 +0800 Subject: [PATCH 1/4] Fix issue #2706: Add proper constraints for macOS dev loading view - Add contentView initialization and container constraints for macOS - Fix layout issues with the dev loading view on macOS platform - Ensure proper positioning and sizing of the loading message window Fixes #2706 --- .../React/CoreModules/RCTDevLoadingView.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index 3298232b47e981..aad9a3a6bd61d7 100644 --- a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm +++ b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm @@ -175,6 +175,22 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo [self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5], ]]; #else // [macOS + self->_window.contentView = [[NSView alloc] init]; + [self->_window.contentView addSubview:self->_container]; + // Container constraints + [NSLayoutConstraint activateConstraints:@[ + [self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor], + [self->_container.leadingAnchor constraintEqualToAnchor:self->_window.contentView.leadingAnchor], + [self->_container.trailingAnchor constraintEqualToAnchor:self->_window.contentView.trailingAnchor], + [self->_container.bottomAnchor constraintEqualToAnchor:self->_window.contentView.bottomAnchor], + + // Label constraints + [self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor], + [self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor], + [self->_label.leadingAnchor constraintGreaterThanOrEqualToAnchor:self->_container.leadingAnchor constant:10], + [self->_label.trailingAnchor constraintLessThanOrEqualToAnchor:self->_container.trailingAnchor constant:-10], + ]]; + if (![[RCTKeyWindow() sheets] doesContain:self->_window]) { [RCTKeyWindow() beginSheet:self->_window completionHandler:^(NSModalResponse returnCode) { [self->_window orderOut:self]; From 1f48e258030ee62ab8188afb7d8a0f56aad10e8c Mon Sep 17 00:00:00 2001 From: ZJH <> Date: Wed, 1 Oct 2025 10:06:10 +0800 Subject: [PATCH 2/4] Fix macOS dev loading view constraints - Replace contentViewController.view with contentView for proper view hierarchy - Unify constraint logic across iOS and macOS platforms - Use shared constraint array for better code organization - Fix container constraints to properly fill parent view on macOS - Maintain platform-specific label positioning (bottom on iOS, center on macOS) Fixes issue #2706 --- .../React/CoreModules/RCTDevLoadingView.mm | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index aad9a3a6bd61d7..ffaee347c1506c 100644 --- a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm +++ b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm @@ -150,7 +150,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo #if !TARGET_OS_OSX // [macOS] [self->_window.rootViewController.view addSubview:self->_container]; #else // [macOS - [self->_window.contentViewController.view addSubview:self->_container]; + [self->_window.contentView addSubview:self->_container]; #endif // macOS] [self->_container addSubview:self->_label]; @@ -162,35 +162,50 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo self->_window.hidden = NO; [self->_window layoutIfNeeded]; +#endif // macOS] - [NSLayoutConstraint activateConstraints:@[ - // Container constraints - [self->_container.topAnchor constraintEqualToAnchor:self->_window.rootViewController.view.topAnchor], - [self->_container.leadingAnchor constraintEqualToAnchor:self->_window.rootViewController.view.leadingAnchor], - [self->_container.trailingAnchor constraintEqualToAnchor:self->_window.rootViewController.view.trailingAnchor], - [self->_container.heightAnchor constraintEqualToConstant:height], - - // Label constraints - [self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor], - [self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5], + // Shared layout constraints + NSMutableArray *constraints = [NSMutableArray array]; + + // Container constraints - shared across all platforms +#if !TARGET_OS_OSX // [macOS] + RCTUIView *parentView = self->_window.rootViewController.view; +#else // [macOS + RCTUIView *parentView = self->_window.contentView; +#endif // macOS] + + [constraints addObjectsFromArray:@[ + [self->_container.topAnchor constraintEqualToAnchor:parentView.topAnchor], + [self->_container.leadingAnchor constraintEqualToAnchor:parentView.leadingAnchor], + [self->_container.trailingAnchor constraintEqualToAnchor:parentView.trailingAnchor], ]]; + +#if !TARGET_OS_OSX // [macOS] + // iOS-specific: fixed height + [constraints addObject:[self->_container.heightAnchor constraintEqualToConstant:height]]; #else // [macOS - self->_window.contentView = [[NSView alloc] init]; - [self->_window.contentView addSubview:self->_container]; - // Container constraints - [NSLayoutConstraint activateConstraints:@[ - [self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor], - [self->_container.leadingAnchor constraintEqualToAnchor:self->_window.contentView.leadingAnchor], - [self->_container.trailingAnchor constraintEqualToAnchor:self->_window.contentView.trailingAnchor], - [self->_container.bottomAnchor constraintEqualToAnchor:self->_window.contentView.bottomAnchor], - - // Label constraints + // macOS-specific: fill entire contentView + [constraints addObject:[self->_container.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor]]; +#endif // macOS] + + // Label constraints - shared across all platforms + [constraints addObjectsFromArray:@[ [self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor], - [self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor], [self->_label.leadingAnchor constraintGreaterThanOrEqualToAnchor:self->_container.leadingAnchor constant:10], [self->_label.trailingAnchor constraintLessThanOrEqualToAnchor:self->_container.trailingAnchor constant:-10], ]]; +#if !TARGET_OS_OSX // [macOS] + // iOS: label aligned to bottom + [constraints addObject:[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5]]; +#else // [macOS + // macOS: label vertically centered + [constraints addObject:[self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor]]; +#endif // macOS] + + [NSLayoutConstraint activateConstraints:constraints]; + +#if TARGET_OS_OSX // [macOS] if (![[RCTKeyWindow() sheets] doesContain:self->_window]) { [RCTKeyWindow() beginSheet:self->_window completionHandler:^(NSModalResponse returnCode) { [self->_window orderOut:self]; @@ -373,4 +388,4 @@ - (void)hide Class RCTDevLoadingViewCls(void) { return RCTDevLoadingView.class; -} +} \ No newline at end of file From bf00fd9d8c8ca08be0e3edf329e0c28edef66d7e Mon Sep 17 00:00:00 2001 From: ZJH <> Date: Sat, 11 Oct 2025 14:50:45 +0800 Subject: [PATCH 3/4] Refactor: Simplify constraint setup and fix macOS contentView usage - Fix macOS contentView usage by using contentViewController.view instead of contentView - Simplify constraint setup by separating iOS and macOS specific logic - Remove shared constraint array approach for better code clarity - Ensure proper initialization of contentView for macOS platform This addresses the layout issues in issue #2706 with a cleaner implementation. --- .../React/CoreModules/RCTDevLoadingView.mm | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index ffaee347c1506c..45e0e70fb84d82 100644 --- a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm +++ b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm @@ -150,7 +150,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo #if !TARGET_OS_OSX // [macOS] [self->_window.rootViewController.view addSubview:self->_container]; #else // [macOS - [self->_window.contentView addSubview:self->_container]; + [self->_window.contentViewController.view addSubview:self->_container]; #endif // macOS] [self->_container addSubview:self->_label]; @@ -162,50 +162,35 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo self->_window.hidden = NO; [self->_window layoutIfNeeded]; -#endif // macOS] - // Shared layout constraints - NSMutableArray *constraints = [NSMutableArray array]; - - // Container constraints - shared across all platforms -#if !TARGET_OS_OSX // [macOS] - RCTUIView *parentView = self->_window.rootViewController.view; -#else // [macOS - RCTUIView *parentView = self->_window.contentView; -#endif // macOS] - - [constraints addObjectsFromArray:@[ - [self->_container.topAnchor constraintEqualToAnchor:parentView.topAnchor], - [self->_container.leadingAnchor constraintEqualToAnchor:parentView.leadingAnchor], - [self->_container.trailingAnchor constraintEqualToAnchor:parentView.trailingAnchor], + [NSLayoutConstraint activateConstraints:@[ + // Container constraints + [self->_container.topAnchor constraintEqualToAnchor:self->_window.rootViewController.view.topAnchor], + [self->_container.leadingAnchor constraintEqualToAnchor:self->_window.rootViewController.view.leadingAnchor], + [self->_container.trailingAnchor constraintEqualToAnchor:self->_window.rootViewController.view.trailingAnchor], + [self->_container.heightAnchor constraintEqualToConstant:height], + + // Label constraints + [self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor], + [self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5], ]]; - -#if !TARGET_OS_OSX // [macOS] - // iOS-specific: fixed height - [constraints addObject:[self->_container.heightAnchor constraintEqualToConstant:height]]; #else // [macOS - // macOS-specific: fill entire contentView - [constraints addObject:[self->_container.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor]]; -#endif // macOS] - - // Label constraints - shared across all platforms - [constraints addObjectsFromArray:@[ + self->_window.contentView = [[NSView alloc] init]; + [self->_window.contentView addSubview:self->_container]; + // Container constraints + [NSLayoutConstraint activateConstraints:@[ + [self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor], + [self->_container.leadingAnchor constraintEqualToAnchor:self->_window.contentView.leadingAnchor], + [self->_container.trailingAnchor constraintEqualToAnchor:self->_window.contentView.trailingAnchor], + [self->_container.bottomAnchor constraintEqualToAnchor:self->_window.contentView.bottomAnchor], + + // Label constraints [self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor], + [self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor], [self->_label.leadingAnchor constraintGreaterThanOrEqualToAnchor:self->_container.leadingAnchor constant:10], [self->_label.trailingAnchor constraintLessThanOrEqualToAnchor:self->_container.trailingAnchor constant:-10], ]]; -#if !TARGET_OS_OSX // [macOS] - // iOS: label aligned to bottom - [constraints addObject:[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5]]; -#else // [macOS - // macOS: label vertically centered - [constraints addObject:[self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor]]; -#endif // macOS] - - [NSLayoutConstraint activateConstraints:constraints]; - -#if TARGET_OS_OSX // [macOS] if (![[RCTKeyWindow() sheets] doesContain:self->_window]) { [RCTKeyWindow() beginSheet:self->_window completionHandler:^(NSModalResponse returnCode) { [self->_window orderOut:self]; From 08bfac03e92793a81872d8bd08bce44f35c9c26d Mon Sep 17 00:00:00 2001 From: ZJH <> Date: Sat, 11 Oct 2025 15:18:47 +0800 Subject: [PATCH 4/4] Clean up: Remove redundant contentView initialization and fix formatting - Remove duplicate contentView initialization in macOS code path - Fix file ending newline formatting - Simplify the constraint setup by removing unnecessary contentView creation - The contentView is already properly initialized by the NSWindow This further refines the fix for issue #2706 with cleaner code. --- .../react-native/React/CoreModules/RCTDevLoadingView.mm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index 45e0e70fb84d82..64276ea56676ad 100644 --- a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm +++ b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm @@ -150,7 +150,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo #if !TARGET_OS_OSX // [macOS] [self->_window.rootViewController.view addSubview:self->_container]; #else // [macOS - [self->_window.contentViewController.view addSubview:self->_container]; + [self->_window.contentView addSubview:self->_container]; #endif // macOS] [self->_container addSubview:self->_label]; @@ -175,8 +175,6 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo [self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5], ]]; #else // [macOS - self->_window.contentView = [[NSView alloc] init]; - [self->_window.contentView addSubview:self->_container]; // Container constraints [NSLayoutConstraint activateConstraints:@[ [self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor], @@ -373,4 +371,4 @@ - (void)hide Class RCTDevLoadingViewCls(void) { return RCTDevLoadingView.class; -} \ No newline at end of file +}