3

Apple requires, that no text scrolls through their transparent status bar.

I am using the inAppBrowser Plugin in my Phonegap Build app, which runs into exactly this problem. For some reason, the inAppbrowser ignores the background I set for my App, and just shows the website behind the status bar objects.

I am using the StatusBarPlugin to control my Status Bar Javascript:

document.addEventListener("deviceready", onDeviceReady, false);

    // Global InAppBrowser reference
    var iabRef = null;
    function iabLoadStart(event) {
        StatusBar.hide();
    }
    function iabLoadStop(event) {
    }
    function iabClose(event) {
         StatusBar.show();
         iabRef.removeEventListener('loadstart', iabLoadStart);
         iabRef.removeEventListener('loadstop', iabLoadStop);
         iabRef.removeEventListener('exit', iabClose);
    }    
    function openPage(url) {
    window.open(url, '_blank', 'location=yes,enableViewportScale=yes,');
    }
    // STATUS Bar
    function setStatusBar() {
    StatusBar.show();
    StatusBar.overlaysWebView(false);
    StatusBar.backgroundColorByHexString("#C8DB2F");
    }
    // Cordova is ready
    //
    function onDeviceReady() {
         checkConnection();
         setStatusBar();
         iabRef.addEventListener('loadstart', iabLoadStart);
         iabRef.addEventListener('loadstop', iabLoadStop);
         iabRef.addEventListener('exit', iabClose);
    }

I have seen similar questions coming up here, but the answers didn't solve my problem.

Community
  • 1
  • 1
5mark
  • 293
  • 1
  • 5
  • 12

6 Answers6

2

Yes, that's correct. On iPhone the inAppbrowser ignores the definitions made for the app itself (Cordova 3.4 / IOS 7).

Furthermore, it erases it when it returns to the app (in my definitions I defined the status bar to be transparent and stay on top of the application body).

  • Are there anyway to not erase it when it returns to the app? – hllau Mar 12 '14 at 07:18
  • Answer found. Setting "View controller-based status bar appearance" to "Yes" would make the status text reappear when it returns to the app. – hllau Mar 12 '14 at 07:25
  • 2
    Your answer works, thanks. But still remains the problem of inAppbrowser not respecting the app statusbar definitions. I'll try a turnaround and if it works, I'll post here. – Miguel Lopes Mar 13 '14 at 10:44
2

I found a way to solve this problem: you edit the CDVInAppBrowser.m file and in this block:

if (self = [super init]) {
    // default values
    self.location = YES;
    self.toolbar = YES;
    self.closebuttoncaption = nil;
    self.toolbarposition = kInAppBrowserToolbarBarPositionBottom;

change the Bottom to Top :-) There are other things that can be done but this kills the problem in a simple way.

1

When you open the InAppBrowser, your app and all of it's JS are paused, so no matter how much scripting you try to put in your app to control the IAB none of it will matter once it's actually open.

However, if you set the tool bar position option to top, it will move the browser controls from the bottom of the screen to the top. The browser chrome will account for the status bar and when you scroll content up, it will be sufficiently hidden underneath the controls.

It's kind of a hacky solution, but it works without intense coding or re-writing the plugin.

How to do it:

In your config.xml file, make sure you're specifying the InAppBrowser plugin:

<gap:plugin name="org.apache.cordova.core.inappbrowser" />

Then wherever you are opening the browser:

window.open('YOUR-URL-HERE', '_blank', 'toolbarposition=top');

You can find more customizable options in the InAppBrowser GitHub readme.

0

I'm using cordova-plugin-inappbrowser and had these exact same issues with the statusbar in iOS. I tried a few of the suggestions here, as well as trying to insertCSS() to adjust the margin at the top and none seemed to work. In the end, installing the org.apache.cordova.statusbar plugin and simply calling StatusBar.overlaysWebView(false); corrected the issue.

You can read more about the statusbar plugin here. Solution courtesy of neilsteventon.

alexkb
  • 3,216
  • 2
  • 30
  • 30
0

To further expand on @alexkb, the solution is to hook into the exit event of the InAppBrowser so that after you return to the page the statusBar will show correctly.

myinapp = window.open('YOUR-URL-HERE', '_blank', 'toolbarposition=top');
myinapp.addEventListener('exit', function (event) {
    StatusBar.overlaysWebView(true);
    StatusBar.overlaysWebView(false);
});
Nico Westerdale
  • 2,147
  • 1
  • 24
  • 31
0

This fixed the issue for me hide and show the statusbar when the in app browser is closed

var ref = window.open('http://google.com', '_blank');
ref.addEventListener('exit', function(event) {
    StatusBar.hide();
    StatusBar.show();
});
Scott w
  • 495
  • 7
  • 15