From 89c2e3c9b7ad700edaf4fb0a6433157461a98a20 Mon Sep 17 00:00:00 2001
From: war-in <war-in@users.noreply.github.com>
Date: Mon, 17 Feb 2025 16:56:07 +0100
Subject: [PATCH 1/2] centralize boot splash in iOS

---
 ios/NewExpensify/RCTBootSplash.h  |  3 +-
 ios/NewExpensify/RCTBootSplash.mm | 63 ++++++++++++++++++-------------
 2 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/ios/NewExpensify/RCTBootSplash.h b/ios/NewExpensify/RCTBootSplash.h
index f25f3e28f561..f499fe59f916 100644
--- a/ios/NewExpensify/RCTBootSplash.h
+++ b/ios/NewExpensify/RCTBootSplash.h
@@ -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
diff --git a/ios/NewExpensify/RCTBootSplash.mm b/ios/NewExpensify/RCTBootSplash.mm
index ddb3f2d047ce..068bfdf7e7b2 100644
--- a/ios/NewExpensify/RCTBootSplash.mm
+++ b/ios/NewExpensify/RCTBootSplash.mm
@@ -25,16 +25,14 @@ + (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;
 }
@@ -42,7 +40,7 @@ + (bool)hasResolveQueue {
 + (void)clearResolveQueue {
   if (![self hasResolveQueue])
     return;
-    
+
   while ([_resolveQueue count] > 0) {
     RCTPromiseResolveBlock resolve = [_resolveQueue objectAtIndex:0];
     [_resolveQueue removeObjectAtIndex:0];
@@ -79,12 +77,17 @@ + (void)hideAndClearPromiseQueue {
   }
 }
 
+
 + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
                   rootView:(UIView * _Nullable)rootView {
   if (RCTRunningInAppExtension()) {
     return;
   }
 
+  if ([self isInitialized]) {
+    return;
+  }
+
   [NSTimer scheduledTimerWithTimeInterval:0.35
                                   repeats:NO
                                     block:^(NSTimer * _Nonnull timer) {
@@ -108,8 +111,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)
@@ -145,24 +154,31 @@ - (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
@@ -170,9 +186,4 @@ - (void)isVisibleImpl:(RCTPromiseResolveBlock)resolve {
   [self hideImpl:0 resolve:resolve];
 }
 
-RCT_EXPORT_METHOD(isVisible:(RCTPromiseResolveBlock)resolve
-                  reject:(RCTPromiseRejectBlock)reject) {
-  [self isVisibleImpl:resolve];
-}
-
 @end

From 0f8ec90c14015de4ebc737e2b784fdd8e1f6b3ef Mon Sep 17 00:00:00 2001
From: war-in <war-in@users.noreply.github.com>
Date: Wed, 26 Feb 2025 10:24:02 +0100
Subject: [PATCH 2/2] fix lint

---
 ios/NewExpensify/RCTBootSplash.mm | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/ios/NewExpensify/RCTBootSplash.mm b/ios/NewExpensify/RCTBootSplash.mm
index 068bfdf7e7b2..fe2dcd9ba646 100644
--- a/ios/NewExpensify/RCTBootSplash.mm
+++ b/ios/NewExpensify/RCTBootSplash.mm
@@ -77,14 +77,9 @@ + (void)hideAndClearPromiseQueue {
   }
 }
 
-
 + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
                   rootView:(UIView * _Nullable)rootView {
-  if (RCTRunningInAppExtension()) {
-    return;
-  }
-
-  if ([self isInitialized]) {
+  if (RCTRunningInAppExtension() || [self isInitialized]) {
     return;
   }
 
