Skip to content
Closed
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
63 changes: 40 additions & 23 deletions packages/react-native/React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#import <React/RCTDevLoadingView.h>
#include <UIKit/UIKit.h>

#import <QuartzCore/QuartzCore.h>

Expand All @@ -30,6 +31,7 @@ @interface RCTDevLoadingView () <NativeDevLoadingViewSpec>
@implementation RCTDevLoadingView {
UIWindow *_window;
UILabel *_label;
UIView *_container;
NSDate *_showDate;
BOOL _hiding;
dispatch_block_t _initialMessageBlock;
Expand Down Expand Up @@ -112,38 +114,53 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
}

dispatch_async(dispatch_get_main_queue(), ^{
if (RCTRunningInTestEnvironment()) {
return;
}

self->_showDate = [NSDate date];

if (!self->_window && !RCTRunningInTestEnvironment()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this check because we teardown the window every time inside of hide method anyway.

UIWindow *window = RCTKeyWindow();
CGFloat windowWidth = window.bounds.size.width;
UIWindow *mainWindow = RCTKeyWindow();
self->_window = [[UIWindow alloc] initWithWindowScene:mainWindow.windowScene];
self->_window.windowLevel = UIWindowLevelStatusBar + 1;
self->_window.rootViewController = [UIViewController new];

self->_window = [[UIWindow alloc] initWithWindowScene:window.windowScene];
#if TARGET_OS_MACCATALYST
self->_window.frame = CGRectMake(0, window.safeAreaInsets.top, windowWidth, 20);
self->_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, windowWidth, 20)];
#else
self->_window.frame = CGRectMake(0, 0, windowWidth, window.safeAreaInsets.top + 10);
self->_label = [[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top - 10, windowWidth, 20)];
#endif
[self->_window addSubview:self->_label];
self->_container = [[UIView alloc] init];
self->_container.backgroundColor = backgroundColor;
self->_container.translatesAutoresizingMaskIntoConstraints = NO;

self->_window.windowLevel = UIWindowLevelStatusBar + 1;
// set a root VC so rotation is supported
self->_window.rootViewController = [UIViewController new];
self->_label = [[UILabel alloc] init];
self->_label.translatesAutoresizingMaskIntoConstraints = NO;
self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
self->_label.textAlignment = NSTextAlignmentCenter;
self->_label.textColor = color;
self->_label.text = message;

self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
self->_label.textAlignment = NSTextAlignmentCenter;
}
[self->_window.rootViewController.view addSubview:self->_container];
[self->_container addSubview:self->_label];

self->_label.text = message;
self->_label.textColor = color;
CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets.top;
CGFloat height = topSafeAreaHeight + 25;
self->_window.frame = CGRectMake(0, 0, mainWindow.frame.size.width, height);

self->_window.backgroundColor = backgroundColor;
self->_window.hidden = NO;
});

[self hideBannerAfter:15.0];
[self->_window layoutIfNeeded];

[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],
]];

[self hideBannerAfter:15.0];
});
}

RCT_EXPORT_METHOD(showMessage
Expand Down