Fix React Native splash screen "white flash" on ios when using an AppDelegate.swift file and not AppDelegate.m

Viewed 184

So I'm facing an issue where there's various fixes for this known problem with ios apps in React Native, where between the splash screen and the login screen, there's a white flash that interupts the flow of the app.

My task is to fix this white flash and make it flow directly into the app. The problem is that all of the solutions that are online use the AppDelegate.m file, where we are only using AppDelegate.swift.

I've worked with React Native extensively, but this is really a native issue I haven't had to think about before.

A few of the fixes I've looked at are:

The fast fix I guess

and then this package that is supposed to fix the issue

Unfortunately these both use AppDelegate.m in the fix description. I've even converted the Objective-C code to swift, and pasted it in the same block. It causes build errors immediately when importing the RNSplashScreen package. Please help!

My AppDelegate.swift looks like so

//
//  AppDelegate.swift
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate /* , MessagingDelegate */ {
  var bridge: RCTBridge!
  var window: UIWindow? = UIWindow(frame: UIScreen.main.bounds)

  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions
                   launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    var jsCodeLocation: URL

    AppCenterReactNativeCrashes.registerWithAutomaticProcessing()  // Initialize AppCenter crashes
    AppCenterReactNativeAnalytics.register(withInitiallyEnabled: true)
    AppCenterReactNative.register()

    jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(
      forBundleRoot: "index.ios",
      fallbackResource: nil)
    
    self.window?.backgroundColor = UIColor.white

//    let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "northwellHealth", initialProperties: nil, launchOptions: launchOptions)

    let rootView: RCTRootView = RCTRootView(
      bundleURL: jsCodeLocation,
      moduleName: "NorthwellHealth",
      initialProperties: nil,
      launchOptions: launchOptions)
    
    rootView.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1)
    let rootViewController: UIViewController = UIViewController()

    rootViewController.view = rootView
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = rootViewController
    self.window?.makeKeyAndVisible()
---------- This is the translated into swift code from link 1 ----------
    let launchScreenView = Bundle.main.loadNibNamed("LaunchScreen", owner: self, options: nil)?[0] as? UIView
    launchScreenView?.frame = window!.bounds
    rootView.loadingView = launchScreenView
------------------------------------------------------------------------
    return true
  }

  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    return true
  }


  func applicationWillResignActive(_ application: UIApplication) {
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks.
    // Games should use this method to pause the game.
  }

  func applicationDidEnterBackground(_ application: UIApplication) {
    // If your application supports background execution, this method is called instead of
    // applicationWillTerminate: when the user quits.
  }

  func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state;
    // here you can undo many of the changes made on entering the background.
  }

  func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive.
    // If the application was previously in the background, optionally refresh the user interface.
  }

  func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate.
    // See also applicationDidEnterBackground:.
  }
}
this gives me a "Thread 1: "Could not load NIB in bundle: 'NSBundle </Users/jacobirwin/Library/Developer/CoreSimulator/Devices/A324EAF6-89FB-48D7-B8AE-E7B2E45060A7/data/Containers/Bundle/Application/5375EBFB-E6F6-4F78-A6F1-690E4C5D16C1/Northwell.app> (loaded)' with name 'LaunchScreen'" error

Then I've tried so many things with the react-native-splash-screen package, and can't seem to get anywhere meaningful with it..

Please let me know if you have insight on these, thank you.

0 Answers
Related