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

Hide splash sceen without SplashScreenDelay on .hide() #1006

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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