diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index 3298232b47e981..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,19 +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 + // 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 + // 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.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5], + [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]; @@ -357,4 +388,4 @@ - (void)hide Class RCTDevLoadingViewCls(void) { return RCTDevLoadingView.class; -} +} \ No newline at end of file