Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions packages/react-native/React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant by share code with iOS is share the actual code blocks so there are less merge conflicts when we sync forward 1000 commits (which is what we do every release). In this case, I think your previous solution was better, which is to have 1 big ifdef.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification! I’ve reverted to the previous approach and switched back to a single big #ifdef, updating the iOS/macOS blocks as requested to reduce merge conflicts.


// 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];
Expand Down Expand Up @@ -357,4 +388,4 @@ - (void)hide
Class RCTDevLoadingViewCls(void)
{
return RCTDevLoadingView.class;
}
}