From c7972b6cffcedae7a9bbbeb66875a5d2fb37ce29 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Tue, 15 Oct 2013 15:00:09 -0700 Subject: [PATCH] CB-4930 - iOS - InAppBrowser should take into account the status bar --- src/ios/CDVInAppBrowser.m | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index 4170dd2..5711e76 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -32,6 +32,11 @@ #pragma mark CDVInAppBrowser +@interface CDVInAppBrowser () { + UIStatusBarStyle _previousStatusBarStyle; +} +@end + @implementation CDVInAppBrowser - (CDVInAppBrowser*)initWithWebView:(UIWebView*)theWebView @@ -115,6 +120,7 @@ } } + _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options]; [self.inAppBrowserViewController showLocationBar:browserOptions.location]; @@ -155,8 +161,13 @@ } if (! browserOptions.hidden) { + + UINavigationController* nav = [[UINavigationController alloc] + initWithRootViewController:self.inAppBrowserViewController]; + nav.navigationBarHidden = YES; + if (self.viewController.modalViewController != self.inAppBrowserViewController) { - [self.viewController presentModalViewController:self.inAppBrowserViewController animated:YES]; + [self.viewController presentModalViewController:nav animated:YES]; } } [self.inAppBrowserViewController navigateTo:url]; @@ -166,7 +177,13 @@ { if ([self.inAppBrowserViewController isViewLoaded] && self.inAppBrowserViewController.view.window) return; - [self.viewController presentModalViewController:self.inAppBrowserViewController animated:YES]; + + _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; + + UINavigationController* nav = [[UINavigationController alloc] + initWithRootViewController:self.inAppBrowserViewController]; + nav.navigationBarHidden = YES; + [self.viewController presentModalViewController:nav animated:YES]; } - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options @@ -362,6 +379,10 @@ // Don't recycle the ViewController since it may be consuming a lot of memory. // Also - this is required for the PDF/User-Agent bug work-around. self.inAppBrowserViewController = nil; + + if (IsAtLeastiOSVersion(@"7.0")) { + [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; + } } @end @@ -632,6 +653,11 @@ [CDVUserAgentUtil releaseLock:&_userAgentLockToken]; [super viewDidUnload]; } + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} - (void)close { @@ -674,6 +700,15 @@ { [self.webView goForward]; } + +- (void)viewWillAppear:(BOOL)animated +{ + if (IsAtLeastiOSVersion(@"7.0")) { + [[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]]; + } + + [super viewWillAppear:animated]; +} #pragma mark UIWebViewDelegate