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