1#import <React/RCTImageSource.h> 2#import <React/RCTImageView.h> 3#import <UMCore/UMDefines.h> 4 5#import "EXKernel.h" 6#import "EXManagedAppSplashScreenConfiguration.h" 7#import "EXManagedAppSplashScreenConfigurationBuilder.h" 8#import "EXManagedAppSplashScreenViewProvider.h" 9#import "EXReactAppManager.h" 10 11@interface EXManagedAppSplashScreenViewProvider () 12 13@property (nonatomic, weak) UIView *splashScreenView; 14@property (nonatomic, strong) EXManagedAppSplashScreenConfiguration *configuration; 15@property (nonatomic, strong, nullable) RCTImageView *splashImageView; 16 17@end 18 19@implementation EXManagedAppSplashScreenViewProvider 20 21- (instancetype)initWithManifest:(NSDictionary *)manifest 22{ 23 if (self = [super init]) { 24 _configuration = [EXManagedAppSplashScreenConfigurationBuilder parseManifest:manifest]; 25 } 26 return self; 27} 28 29- (void)updateSplashScreenViewWithManifest:(NSDictionary *)manifest 30{ 31 _configuration = [EXManagedAppSplashScreenConfigurationBuilder parseManifest:manifest]; 32 if (_splashScreenView) { 33 [self configureSplashScreenView:_splashScreenView]; 34 } 35} 36 37- (UIView *)createSplashScreenView 38{ 39 UIView *splashScreenView = [UIView new]; 40 [self configureSplashScreenView:splashScreenView]; 41 _splashScreenView = splashScreenView; 42 return splashScreenView; 43} 44 45- (void)configureSplashScreenView:(UIView *)splashScreenView 46{ 47 UM_WEAKIFY(self); 48 dispatch_async(dispatch_get_main_queue(), ^{ 49 UM_ENSURE_STRONGIFY(self); 50 splashScreenView.backgroundColor = self.configuration.backgroundColor; 51 52 if (self.configuration.imageUrl) { 53 EXKernelAppRecord *homeAppRecord = [EXKernel sharedInstance].appRegistry.homeAppRecord; 54 55 if (homeAppRecord.appManager.reactBridge) { 56 // remove old splashImageView 57 if (self.splashImageView) { 58 [self.splashImageView removeFromSuperview]; 59 } 60 61 RCTImageSource *imageSource = [RCTConvert RCTImageSource:@{ @"uri": self.configuration.imageUrl }]; 62 63 // splash image loading is taking some time that, what can result in no image visually presented during loading phase 64 // despite the fact the RCTImageView is mounted in the view hierarchy 65 self.splashImageView = [[RCTImageView alloc] initWithBridge:homeAppRecord.appManager.reactBridge]; 66 self.splashImageView.frame = splashScreenView.bounds; 67 self.splashImageView.imageSources = @[imageSource]; 68 self.splashImageView.resizeMode = self.configuration.imageResizeMode == EXSplashScreenImageResizeModeCover ? RCTResizeModeCover : RCTResizeModeContain; 69 [splashScreenView addSubview:self.splashImageView]; 70 } 71 } 72 }); 73} 74 75@end 76 77