Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HybridApp] Adjust RCTBootSplash.mm to HybridApp requirements #56953

3 changes: 2 additions & 1 deletion ios/NewExpensify/RCTBootSplash.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

@interface RCTBootSplash : NSObject <RCTBridgeModule>

+ (void)invalidateBootSplash;
+ (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
rootView:(UIView * _Nullable)rootView;
+ (void)hide:(BOOL)fade;
+ (void)bringSubviewToFrontIfInitialized;

@end
60 changes: 33 additions & 27 deletions ios/NewExpensify/RCTBootSplash.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,22 @@ + (BOOL)requiresMainQueueSetup {
return NO;
}

+ (void)invalidateBootSplash {
_resolveQueue = nil;
_rootView = nil;
_nativeHidden = false;
}

+ (bool)isLoadingViewVisible {
return _loadingView != nil && ![_loadingView isHidden];
}

+ (BOOL)isInitialized {
return _loadingView && _rootView;
}

+ (bool)hasResolveQueue {
return _resolveQueue != nil;
}

+ (void)clearResolveQueue {
if (![self hasResolveQueue])
return;

while ([_resolveQueue count] > 0) {
RCTPromiseResolveBlock resolve = [_resolveQueue objectAtIndex:0];
[_resolveQueue removeObjectAtIndex:0];
Expand Down Expand Up @@ -81,7 +79,7 @@ + (void)hideAndClearPromiseQueue {

+ (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
rootView:(UIView * _Nullable)rootView {
if (RCTRunningInAppExtension()) {
if (RCTRunningInAppExtension() || [self isInitialized]) {
return;
}

Expand All @@ -108,8 +106,14 @@ + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
_loadingView.center = (CGPoint){CGRectGetMidX(_rootView.bounds), CGRectGetMidY(_rootView.bounds)};
_loadingView.hidden = NO;

[_rootView disableActivityIndicatorAutoHide:YES];
[_rootView setLoadingView:_loadingView];
[_rootView addSubview:_loadingView];

if ([_rootView respondsToSelector:@selector(disableActivityIndicatorAutoHide:)]) {
[_rootView disableActivityIndicatorAutoHide:YES];
}
if ([_rootView respondsToSelector:@selector(setLoadingView:)]) {
[_rootView setLoadingView:_loadingView];
}

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onJavaScriptDidLoad)
Expand Down Expand Up @@ -145,34 +149,36 @@ - (NSDictionary *)constantsToExport {
};
}

- (void)hideImpl:(BOOL)fade
resolve:(RCTPromiseResolveBlock)resolve {
if (_resolveQueue == nil)
_resolveQueue = [[NSMutableArray alloc] init];
+ (void)bringSubviewToFrontIfInitialized {
if(![self isInitialized]) {
return;
}

[_resolveQueue addObject:resolve];
[_rootView bringSubviewToFront:_loadingView];
}

if (![RCTBootSplash isLoadingViewVisible] || RCTRunningInAppExtension())
return [RCTBootSplash clearResolveQueue];
+ (void)hide:(BOOL)fade {
if (![RCTBootSplash isLoadingViewVisible] || RCTRunningInAppExtension())
return [RCTBootSplash clearResolveQueue];

_fade = fade;
_fade = fade;

if (_nativeHidden)
return [RCTBootSplash hideAndClearPromiseQueue];
return [RCTBootSplash hideAndClearPromiseQueue];
}

- (void)isVisibleImpl:(RCTPromiseResolveBlock)resolve {
resolve(@([RCTBootSplash isLoadingViewVisible]));
- (void)hideImpl:(BOOL)fade
resolve:(RCTPromiseResolveBlock)resolve {
if (_resolveQueue == nil)
_resolveQueue = [[NSMutableArray alloc] init];

[_resolveQueue addObject:resolve];

[RCTBootSplash hide:fade];
}

RCT_EXPORT_METHOD(hide:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self hideImpl:0 resolve:resolve];
}

RCT_EXPORT_METHOD(isVisible:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self isVisibleImpl:resolve];
}

@end
Loading