Skip to content

Commit

Permalink
Input Validation - RCTDevLoadingView
Browse files Browse the repository at this point in the history
  • Loading branch information
admirsaheta committed Dec 21, 2022
1 parent 79f32b4 commit be8c03e
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,35 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
return;
}

// Input validation
if (message == nil || [message isEqualToString:@""]) {
NSLog(@"Error: message cannot be nil or empty");
return;
}
if (color == nil) {
NSLog(@"Error: color cannot be nil");
return;
}
if (backgroundColor == nil) {
NSLog(@"Error: backgroundColor cannot be nil");
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
self->_showDate = [NSDate date];
if (!self->_window && !RCTRunningInTestEnvironment()) {
if (!self->_uiWindow && !RCTRunningInTestEnvironment()) {
CGSize screenSize = [UIScreen mainScreen].bounds.size;

UIWindow *window = RCTSharedApplication().keyWindow;
self->_window =
self->_uiWindow =
[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, window.safeAreaInsets.top + 10)];
self->_label =
[[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top - 10, screenSize.width, 20)];
[self->_window addSubview:self->_label];
[self->_uiWindow addSubview:self->_label];

self->_window.windowLevel = UIWindowLevelStatusBar + 1;
self->_uiWindow.windowLevel = UIWindowLevelStatusBar + 1;
// set a root VC so rotation is supported
self->_window.rootViewController = [UIViewController new];
self->_uiWindow.rootViewController = [UIViewController new];

self->_label.font = [UIFont monospacedDigitSystemFontOfSize:12.0 weight:UIFontWeightRegular];
self->_label.textAlignment = NSTextAlignmentCenter;
Expand All @@ -133,14 +147,14 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
self->_label.text = message;
self->_label.textColor = color;

self->_window.backgroundColor = backgroundColor;
self->_window.hidden = NO;
self->_uiWindow.backgroundColor = backgroundColor;
self->_uiWindow.hidden = NO;

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
UIWindowScene *scene = (UIWindowScene *)RCTSharedApplication().connectedScenes.anyObject;
self->_window.windowScene = scene;
self->_uiWindow.windowScene = scene;
}
#endif
});
Expand Down

0 comments on commit be8c03e

Please sign in to comment.