Skip to content

Commit 98eb33d

Browse files
fix: Add proper constraints for macOS dev loading view (#2707)
- 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 <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The four fields below are mandatory. --> <!-- This fork of react-native provides React Native for macOS for the community. It also contains some changes that are required for usage internal to Microsoft. We are working on reducing the diff between Facebook's public version of react-native and our microsoft/react-native-macos fork. Long term, we want this fork to only contain macOS concerns and have the other iOS and Android concerns contributed upstream. If you are making a new change then one of the following should be done: - Consider if it is possible to achieve the desired behavior without making a change to microsoft/react-native-macos. Often a change can be made in a layer above in facebook/react-native instead. - Create a corresponding PR against [facebook/react-native](https://github.com/facebook/react-native) **Note:** Ideally you would wait for Facebook feedback before submitting to Microsoft, since we want to ensure that this fork doesn't deviate from upstream. --> ## Summary: <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> ## Test Plan: <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. --> --------- Co-authored-by: ZJH <>
1 parent 6e895c3 commit 98eb33d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
150150
#if !TARGET_OS_OSX // [macOS]
151151
[self->_window.rootViewController.view addSubview:self->_container];
152152
#else // [macOS
153-
[self->_window.contentViewController.view addSubview:self->_container];
153+
[self->_window.contentView addSubview:self->_container];
154154
#endif // macOS]
155155
[self->_container addSubview:self->_label];
156156

@@ -175,6 +175,20 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
175175
[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5],
176176
]];
177177
#else // [macOS
178+
// Container constraints
179+
[NSLayoutConstraint activateConstraints:@[
180+
[self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor],
181+
[self->_container.leadingAnchor constraintEqualToAnchor:self->_window.contentView.leadingAnchor],
182+
[self->_container.trailingAnchor constraintEqualToAnchor:self->_window.contentView.trailingAnchor],
183+
[self->_container.bottomAnchor constraintEqualToAnchor:self->_window.contentView.bottomAnchor],
184+
185+
// Label constraints
186+
[self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor],
187+
[self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor],
188+
[self->_label.leadingAnchor constraintGreaterThanOrEqualToAnchor:self->_container.leadingAnchor constant:10],
189+
[self->_label.trailingAnchor constraintLessThanOrEqualToAnchor:self->_container.trailingAnchor constant:-10],
190+
]];
191+
178192
if (![[RCTKeyWindow() sheets] doesContain:self->_window]) {
179193
[RCTKeyWindow() beginSheet:self->_window completionHandler:^(NSModalResponse returnCode) {
180194
[self->_window orderOut:self];

0 commit comments

Comments
 (0)