1*9fcddb20Sandy// 2*9fcddb20Sandy// EXManagedAppSplashScreenViewController.m 3*9fcddb20Sandy// Expo Go (unversioned) 4*9fcddb20Sandy// 5*9fcddb20Sandy// Created by andrew on 2021-06-07. 6*9fcddb20Sandy// Copyright © 2021 650 Industries. All rights reserved. 7*9fcddb20Sandy// 8*9fcddb20Sandy 9*9fcddb20Sandy#import "EXManagedAppSplashScreenViewController.h" 10*9fcddb20Sandy#import "MBProgressHUD.h" 11*9fcddb20Sandy#import "EXSplashScreenHUDButton.h" 12*9fcddb20Sandy 13*9fcddb20Sandy 14*9fcddb20Sandy@interface EXManagedAppSplashScreenViewController() 15*9fcddb20Sandy 16*9fcddb20Sandy@property (nonatomic, weak) NSTimer *warningTimer; 17*9fcddb20Sandy@property (nonatomic, weak) MBProgressHUD *warningHud; 18*9fcddb20Sandy 19*9fcddb20Sandy@end 20*9fcddb20Sandy 21*9fcddb20Sandy@implementation EXManagedAppSplashScreenViewController 22*9fcddb20Sandy 23*9fcddb20Sandy- (instancetype)initWithRootView:(UIView *)rootView splashScreenView:(UIView *)splashScreenView 24*9fcddb20Sandy{ 25*9fcddb20Sandy if (self = [super initWithRootView:rootView splashScreenView:splashScreenView]) { 26*9fcddb20Sandy self.splashScreenView.userInteractionEnabled = YES; 27*9fcddb20Sandy } 28*9fcddb20Sandy 29*9fcddb20Sandy return self; 30*9fcddb20Sandy} 31*9fcddb20Sandy 32*9fcddb20Sandy- (void)showWithCallback:(void (^)(void))successCallback failureCallback:(void (^)(NSString * _Nonnull))failureCallback 33*9fcddb20Sandy{ 34*9fcddb20Sandy [super showWithCallback:^{ 35*9fcddb20Sandy [self startSplashScreenVisibleTimer]; 36*9fcddb20Sandy if (successCallback) { 37*9fcddb20Sandy successCallback(); 38*9fcddb20Sandy } 39*9fcddb20Sandy } failureCallback:failureCallback]; 40*9fcddb20Sandy} 41*9fcddb20Sandy 42*9fcddb20Sandy- (void)hideWithCallback:(void (^)(BOOL))successCallback failureCallback:(void (^)(NSString * _Nonnull))failureCallback 43*9fcddb20Sandy{ 44*9fcddb20Sandy [super hideWithCallback:^(BOOL isSuccess){ 45*9fcddb20Sandy if (self.warningTimer) { 46*9fcddb20Sandy [self.warningTimer invalidate]; 47*9fcddb20Sandy } 48*9fcddb20Sandy 49*9fcddb20Sandy if (successCallback) { 50*9fcddb20Sandy successCallback(YES); 51*9fcddb20Sandy } 52*9fcddb20Sandy } failureCallback:failureCallback]; 53*9fcddb20Sandy} 54*9fcddb20Sandy 55*9fcddb20Sandy 56*9fcddb20Sandy-(void)startSplashScreenVisibleTimer 57*9fcddb20Sandy{ 58*9fcddb20Sandy self.warningTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 59*9fcddb20Sandy target:self 60*9fcddb20Sandy selector:@selector(showSplashScreenVisibleWarning) 61*9fcddb20Sandy userInfo:nil 62*9fcddb20Sandy repeats:NO]; 63*9fcddb20Sandy} 64*9fcddb20Sandy 65*9fcddb20Sandy- (void)showSplashScreenVisibleWarning 66*9fcddb20Sandy{ 67*9fcddb20Sandy#if DEBUG 68*9fcddb20Sandy _warningHud = [MBProgressHUD showHUDAddedTo: self.splashScreenView animated:YES]; 69*9fcddb20Sandy _warningHud.mode = MBProgressHUDModeCustomView; 70*9fcddb20Sandy 71*9fcddb20Sandy EXSplashScreenHUDButton *button = [EXSplashScreenHUDButton buttonWithType: UIButtonTypeSystem]; 72*9fcddb20Sandy [button addTarget:self action:@selector(navigateToFYI) forControlEvents:UIControlEventTouchUpInside]; 73*9fcddb20Sandy 74*9fcddb20Sandy _warningHud.customView = button; 75*9fcddb20Sandy _warningHud.offset = CGPointMake(0.f, MBProgressMaxOffset); 76*9fcddb20Sandy 77*9fcddb20Sandy [_warningHud hideAnimated:YES afterDelay:8.f]; 78*9fcddb20Sandy#endif 79*9fcddb20Sandy} 80*9fcddb20Sandy 81*9fcddb20Sandy- (void)navigateToFYI 82*9fcddb20Sandy{ 83*9fcddb20Sandy NSURL *fyiURL = [[NSURL alloc] initWithString:@"https://expo.fyi/splash-screen-hanging"]; 84*9fcddb20Sandy [[UIApplication sharedApplication] openURL:fyiURL]; 85*9fcddb20Sandy [_warningHud hideAnimated: YES]; 86*9fcddb20Sandy} 87*9fcddb20Sandy 88*9fcddb20Sandy@end 89