Skip to content
Open
Changes from all 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
25 changes: 18 additions & 7 deletions packages/react-native/React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,21 @@ - (void)showMessage:(NSString *)message color:(RCTPlatformColor *)color backgrou
if (!self->_container) {
self->_container = [[RCTUIView alloc] init]; // [macOS]
self->_container.translatesAutoresizingMaskIntoConstraints = NO;
self->_container.wantsLayer = YES;
self->_container.layer.cornerRadius = 4;
self->_container.layer.cornerCurve = kCACornerCurveContinuous;
self->_container.layer.masksToBounds = YES;
[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
styleMask:NSWindowStyleMaskBorderless
backing:NSBackingStoreBuffered
defer:YES];
self->_window.backgroundColor = [NSColor clearColor];
self->_window.opaque = NO;
[self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier];
[self->_window.contentView addSubview:self->_container];
}
Expand All @@ -202,10 +208,14 @@ - (void)showMessage:(NSString *)message color:(RCTPlatformColor *)color backgrou
[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];
}];
NSWindow *parentWindow = RCTKeyWindow();
if (![[parentWindow childWindows] doesContain:self->_window]) {
NSRect parentFrame = parentWindow.frame;
NSRect loadingFrame = self->_window.frame;
[self->_window setFrameOrigin:NSMakePoint(
NSMidX(parentFrame) - NSWidth(loadingFrame) / 2,
NSMidY(parentFrame) - NSHeight(loadingFrame) / 2)];
[parentWindow addChildWindow:self->_window ordered:NSWindowAbove];
}
#endif // macOS]

Expand Down Expand Up @@ -250,9 +260,10 @@ - (void)showMessage:(NSString *)message color:(RCTPlatformColor *)color backgrou
self->_hiding = false;
}];
#else // [macOS]
for (NSWindow *window in [RCTKeyWindow() sheets]) {
for (NSWindow *window in NSApp.windows) {
if ([[window identifier] isEqualToString:sRCTDevLoadingViewWindowIdentifier]) {
[RCTKeyWindow() endSheet:window];
[window.parentWindow removeChildWindow:window];
[window orderOut:self];
}
}
self->_window = nil;
Expand Down