diff --git a/README.md b/README.md index 1d0ce9c7..cb49121b 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,8 @@ Hide the statusbar. StatusBar.hide(); +On iOS, you can pass 2 optional parameters, animated and duration, in order to animate hiding the statusbar. By default, the animated parameter is set to false. + Supported Platforms ------------------- @@ -284,6 +286,13 @@ Supported Platforms - Android - Windows +Quick Example +------------- + + StatusBar.hide(); + StatusBar.hide(true); // => default duration value is 0.1s + StatusBar.hide(true, 0.3); + StatusBar.show ================= @@ -291,6 +300,8 @@ Shows the statusbar. StatusBar.show(); +On iOS, you can pass 2 optional parameters, animated and duration in seconds, in order to animate showing the statusbar. By default, the animated parameter is set to false. + Supported Platforms ------------------- @@ -299,6 +310,13 @@ Supported Platforms - Android - Windows +Quick Example +------------- + + StatusBar.show(); + StatusBar.show(true); // => default duration value is 0.1s + StatusBar.show(true, 0.3); + StatusBar.isVisible ================= diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m index 058bbefb..9b36586a 100644 --- a/src/ios/CDVStatusBar.m +++ b/src/ios/CDVStatusBar.m @@ -150,7 +150,7 @@ - (void)pluginInitialize } else { self.webView.scrollView.scrollsToTop = NO; } - + // blank scroll view to intercept status bar taps UIScrollView *fakeScrollView = [[UIScrollView alloc] initWithFrame:UIScreen.mainScreen.bounds]; fakeScrollView.delegate = self; @@ -257,17 +257,33 @@ - (void) overlaysWebView:(CDVInvokedUrlCommand*)command self.statusBarOverlaysWebView = [value boolValue]; } -- (void) refreshStatusBarAppearance +- (void) refreshStatusBarAppearanceWithAnimation:(BOOL)refreshAnimated duration:(NSTimeInterval)duration { SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate"); if ([self.viewController respondsToSelector:sel]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" - [self.viewController performSelector:sel withObject:nil]; + if (refreshAnimated) { + [UIView animateWithDuration:duration animations:^() { + [self.viewController performSelector:sel withObject:nil]; + }completion:^(BOOL finished){}]; + } else { + [self.viewController performSelector:sel withObject:nil]; + } #pragma clang diagnostic pop } } +- (void) refreshStatusBarAppearanceWithAnimation:(BOOL)refreshAnimated +{ + [self refreshStatusBarAppearanceWithAnimation:refreshAnimated duration:0.1]; +} + +- (void) refreshStatusBarAppearance +{ + [self refreshStatusBarAppearanceWithAnimation:NO]; +} + - (void) setStyleForStatusBar:(UIStatusBarStyle)style { if (_uiviewControllerBasedStatusBarAppearance) { @@ -359,16 +375,16 @@ - (void) backgroundColorByHexString:(CDVInvokedUrlCommand*)command [self _backgroundColorByHexString:value]; } -- (void) hideStatusBar +- (void) hideStatusBarWithAnimation:(BOOL)animated duration:(NSTimeInterval)duration { if (_uiviewControllerBasedStatusBarAppearance) { CDVViewController* vc = (CDVViewController*)self.viewController; vc.sb_hideStatusBar = [NSNumber numberWithBool:YES]; - [self refreshStatusBarAppearance]; + [self refreshStatusBarAppearanceWithAnimation:animated duration:duration]; } else { UIApplication* app = [UIApplication sharedApplication]; - [app setStatusBarHidden:YES]; + [app setStatusBarHidden:YES withAnimation:animated]; } } @@ -380,7 +396,17 @@ - (void) hide:(CDVInvokedUrlCommand*)command if (!app.isStatusBarHidden) { - [self hideStatusBar]; + id animated = [command argumentAtIndex:0]; + if (!([animated isKindOfClass:[NSNumber class]])) { + animated = [NSNumber numberWithBool:NO]; + } + + id duration = [command argumentAtIndex:1]; + if (!([duration isKindOfClass:[NSNumber class]])) { + duration = [NSNumber numberWithDouble:0.1]; + } + + [self hideStatusBarWithAnimation:[animated boolValue] duration:[duration doubleValue]]; [_statusBarBackgroundView removeFromSuperview]; @@ -390,16 +416,16 @@ - (void) hide:(CDVInvokedUrlCommand*)command } } -- (void) showStatusBar +- (void) showStatusBarWithAnimation:(BOOL)animated duration:(NSTimeInterval)duration { if (_uiviewControllerBasedStatusBarAppearance) { CDVViewController* vc = (CDVViewController*)self.viewController; vc.sb_hideStatusBar = [NSNumber numberWithBool:NO]; - [self refreshStatusBarAppearance]; + [self refreshStatusBarAppearanceWithAnimation:animated duration:duration]; } else { UIApplication* app = [UIApplication sharedApplication]; - [app setStatusBarHidden:NO]; + [app setStatusBarHidden:NO withAnimation:animated]; } } @@ -410,7 +436,17 @@ - (void) show:(CDVInvokedUrlCommand*)command if (app.isStatusBarHidden) { - [self showStatusBar]; + id animated = [command argumentAtIndex:0]; + if (!([animated isKindOfClass:[NSNumber class]])) { + animated = [NSNumber numberWithBool:NO]; + } + + id duration = [command argumentAtIndex:1]; + if (!([duration isKindOfClass:[NSNumber class]])) { + duration = [NSNumber numberWithDouble:0.1]; + } + + [self showStatusBarWithAnimation:[animated boolValue] duration:[duration doubleValue]]; [self resizeWebView]; if (!self.statusBarOverlaysWebView) { @@ -471,7 +507,7 @@ -(void)resizeWebView } frame.size.height -= frame.origin.y; self.webView.frame = frame; - + } - (void) dealloc diff --git a/www/statusbar.js b/www/statusbar.js index d6ab16b2..8d74bc6f 100644 --- a/www/statusbar.js +++ b/www/statusbar.js @@ -85,13 +85,13 @@ var StatusBar = { exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]); }, - hide: function () { - exec(null, null, "StatusBar", "hide", []); + hide: function (animated, duration) { + exec(null, null, "StatusBar", "hide", [animated, duration]); StatusBar.isVisible = false; }, - show: function () { - exec(null, null, "StatusBar", "show", []); + show: function (animated, duration) { + exec(null, null, "StatusBar", "show", [animated, duration]); StatusBar.isVisible = true; }