1// Copyright © 2018 650 Industries. All rights reserved. 2 3#import <EXSplashScreen/EXSplashScreenViewNativeProvider.h> 4#import <ExpoModulesCore/EXLogManager.h> 5 6@implementation EXSplashScreenViewNativeProvider 7 8- (nonnull UIView *)createSplashScreenView 9{ 10 NSString *splashScreenFilename = (NSString *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"] ?: @"SplashScreen"; 11 UIStoryboard *storyboard; 12 @try { 13 storyboard = [UIStoryboard storyboardWithName:splashScreenFilename bundle:[NSBundle mainBundle]]; 14 } @catch (NSException *_) { 15 EXLogWarn([NSString stringWithFormat:@"'%@.storyboard' file is missing. Fallbacking to '%@.xib' file.", splashScreenFilename, splashScreenFilename]); 16 } 17 if (storyboard) { 18 @try { 19 UIViewController *splashScreenViewController = [storyboard instantiateInitialViewController]; 20 UIView *splashScreenView = splashScreenViewController.view; 21 return splashScreenView; 22 } @catch (NSException *_) { 23 @throw [NSException exceptionWithName:@"ERR_INVALID_SPLASH_SCREEN" 24 reason:[NSString stringWithFormat:@"'%@.storyboard'does not contain proper ViewController. Add correct ViewController to your '%@.storyboard' file (https://github.com/expo/expo/tree/main/packages/expo-splash-screen#-configure-ios).", splashScreenFilename, splashScreenFilename] 25 userInfo:nil]; 26 } 27 } 28 29 NSArray *views; 30 @try { 31 views = [[NSBundle mainBundle] loadNibNamed:splashScreenFilename owner:self options:nil]; 32 } @catch (NSException *_) { 33 EXLogWarn([NSString stringWithFormat:@"'%@.xib' file is missing - 'expo-splash-screen' will not work as expected.", splashScreenFilename]); 34 } 35 if (views) { 36 if (!views.firstObject) { 37 @throw [NSException exceptionWithName:@"ERR_INVALID_SPLASH_SCREEN" 38 reason:[NSString stringWithFormat:@"'%@.xib' does not contain any views. Add a view to the '%@.xib' or create '%@.storyboard' (https://github.com/expo/expo/tree/main/packages/expo-splash-screen#-configure-ios).", splashScreenFilename, splashScreenFilename, splashScreenFilename] 39 userInfo:nil]; 40 } 41 UIView *view = views.firstObject; 42 view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 43 return view; 44 } 45 46 @throw [NSException exceptionWithName:@"ERR_NO_SPLASH_SCREEN" 47 reason:[NSString stringWithFormat:@"Couln't locate neither '%@.storyboard' file nor '%@.xib' file. Create one of these in the project to make 'expo-splash-screen' work (https://github.com/expo/expo/tree/main/packages/expo-splash-screen#-configure-ios).", splashScreenFilename, splashScreenFilename] 48 userInfo:nil]; 49} 50 51@end 52