Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-26047] iOS: Fix Fix launch-screen + forceSplashAsSnapshot combination, fix related unit-test #10054

Merged
merged 8 commits into from
Jun 30, 2018
5 changes: 5 additions & 0 deletions iphone/Classes/AppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ - (void)setForceSplashAsSnapshot:(id)args
[[TiApp app] setForceSplashAsSnapshot:flag];
}

- (NSNumber *)forceSplashAsSnapshot
{
return @([[TiApp app] forceSplashAsSnapshot]);
}

#if defined(USE_TI_APPIOS)
- (id)iOS
{
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run on
@interface TiApp : TiHost <UIApplicationDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate> {
UIWindow *window;
UIImageView *loadView;
UIImageView *splashScreenImage;
UIView *splashScreenView;
BOOL loaded;

TiContextGroupRef contextGroup;
Expand Down
49 changes: 22 additions & 27 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,19 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
[self boot];
}

- (UIImageView *)splashScreenImage
- (UIView *)splashScreenView
{
if (splashScreenImage == nil) {
splashScreenImage = [[UIImageView alloc] init];
[splashScreenImage setBackgroundColor:[UIColor yellowColor]];
[splashScreenImage setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[splashScreenImage setContentMode:UIViewContentModeScaleToFill];
if (splashScreenView == nil) {
#ifdef LAUNCHSCREEN_STORYBOARD
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
UIViewController *launchScreen = [sb instantiateInitialViewController];

splashScreenView = [[launchScreen view] retain];
#else
splashScreenView = [[UIImageView alloc] init];
[splashScreenView setBackgroundColor:[UIColor yellowColor]];
[splashScreenView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[splashScreenView setContentMode:UIViewContentModeScaleToFill];

UIDeviceOrientation imageOrientation;
UIUserInterfaceIdiom imageIdiom;
Expand All @@ -381,10 +387,12 @@ - (UIImageView *)splashScreenImage
(UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]
resultingOrientation:&imageOrientation
idiom:&imageIdiom];
[splashScreenImage setImage:defaultImage];
[splashScreenImage setFrame:[[UIScreen mainScreen] bounds]];
[(UIImageView *)splashScreenView setImage:defaultImage];
[splashScreenView setFrame:[[UIScreen mainScreen] bounds]];
#endif
}
return splashScreenImage;

return splashScreenView;
}

- (void)generateNotification:(NSDictionary *)dict
Expand Down Expand Up @@ -1037,13 +1045,7 @@ - (void)applicationWillResignActive:(UIApplication *)application
withArguments:[NSOrderedSet orderedSetWithObject:application]];

if ([self forceSplashAsSnapshot]) {
#ifdef LAUNCHSCREEN_STORYBOARD
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
[[[self controller] topPresentedController] presentViewController:vc animated:NO completion:nil];
#else
[window addSubview:[self splashScreenImage]];
#endif
[window addSubview:[self splashScreenView]];
}
[[NSNotificationCenter defaultCenter] postNotificationName:kTiSuspendNotification object:self];

Expand All @@ -1066,16 +1068,9 @@ - (void)applicationDidBecomeActive:(UIApplication *)application

// We should think about placing this inside "applicationWillBecomeActive" instead to make
// the UI re-useable again more quickly
if ([self forceSplashAsSnapshot]) {
#ifdef LAUNCHSCREEN_STORYBOARD
[[[self controller] topPresentedController] dismissViewControllerAnimated:NO
completion:nil];
#else
if (splashScreenImage != nil) {
[[self splashScreenImage] removeFromSuperview];
RELEASE_TO_NIL(splashScreenImage);
}
#endif
if ([self forceSplashAsSnapshot] && splashScreenView != nil) {
[[self splashScreenView] removeFromSuperview];
RELEASE_TO_NIL(splashScreenView);
}

// NOTE: Have to fire a separate but non-'resume' event here because there is SOME information
Expand Down Expand Up @@ -1280,7 +1275,7 @@ - (void)dealloc
RELEASE_TO_NIL(userAgent);
RELEASE_TO_NIL(remoteDeviceUUID);
RELEASE_TO_NIL(remoteNotification);
RELEASE_TO_NIL(splashScreenImage);
RELEASE_TO_NIL(splashScreenView);
#ifndef USE_JSCORE_FRAMEWORK
if ([self debugMode]) {
TiDebuggerStop();
Expand Down