Skip to content

Commit

Permalink
Hide splash sceen immediately on .hide() (#1006)
Browse files Browse the repository at this point in the history
Make hiding of splash screen a race between `SplashScreenDelay` setting
and navigator.splashscreen.hide().

Related issue: #991
  • Loading branch information
BendingBender authored Oct 10, 2020
1 parent 1d06c0a commit cb20c9b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions CordovaLib/Classes/Public/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,18 @@ - (void)onWebViewPageDidLoad:(NSNotification*)notification
self.webView.hidden = NO;

if ([self.settings cordovaBoolSettingForKey:@"AutoHideSplashScreen" defaultValue:YES]) {
[self showLaunchScreen:NO];
CGFloat splashScreenDelaySetting = [self.settings cordovaFloatSettingForKey:@"SplashScreenDelay" defaultValue:0];

if (splashScreenDelaySetting == 0) {
[self showLaunchScreen:NO];
} else {
// Divide by 1000 because config returns milliseconds and NSTimer takes seconds
CGFloat splashScreenDelay = splashScreenDelaySetting / 1000;

[NSTimer scheduledTimerWithTimeInterval:splashScreenDelay repeats:NO block:^(NSTimer * _Nonnull timer) {
[self showLaunchScreen:NO];
}];
}
}
}

Expand All @@ -776,22 +787,16 @@ - (void)onWebViewPageDidLoad:(NSNotification*)notification
*/
- (void)showLaunchScreen:(BOOL)visible
{
CGFloat splashScreenDelay = [self.settings cordovaFloatSettingForKey:@"SplashScreenDelay" defaultValue:0];

// AnimateWithDuration takes seconds but cordova documentation specifies milliseconds
CGFloat fadeSplashScreenDuration = [self.settings cordovaFloatSettingForKey:@"FadeSplashScreenDuration" defaultValue:250];

// Setting minimum value for fade to 0.25 seconds
fadeSplashScreenDuration = fadeSplashScreenDuration < 250 ? 250 : fadeSplashScreenDuration;

// Divide by 1000 because config returns milliseconds and NSTimer takes seconds
CGFloat delayToFade = (MAX(splashScreenDelay, fadeSplashScreenDuration) - fadeSplashScreenDuration)/1000;
// AnimateWithDuration takes seconds but cordova documentation specifies milliseconds
CGFloat fadeDuration = fadeSplashScreenDuration/1000;

[NSTimer scheduledTimerWithTimeInterval:delayToFade repeats:NO block:^(NSTimer * _Nonnull timer) {
[UIView animateWithDuration:fadeDuration animations:^{
[self.launchView setAlpha:(visible ? 1 : 0)];
}];
[UIView animateWithDuration:fadeDuration animations:^{
[self.launchView setAlpha:(visible ? 1 : 0)];
}];
}

Expand Down

0 comments on commit cb20c9b

Please sign in to comment.