Added support for hiding the web view container.  This maintains the browser
session without closing it.  The browser window can be repeatedly hidden and
shown.

** This has only been tested on android and ios **

amazon/android:
An additional `hide` action was added to `InAppBrowser#execute`.  It is
identical to `show`, except that it calls `dialog.hide()` instead.

blackberry10:
no changes

firefoxos:
Added a `hide` method that is identical to `show`, indicating it is not
supported.

ios:
Added a `hide` method that is identical to `show`, except that it uses
`dismissViewControllerAnimated`.  It checks the value of
`_previousStatusBarStyle`.  If it is `-1`, the method returns with no
action performed.  If it is not, it is set to `-1.`

ubuntu:
Added a `hide` method that sets `CordovaWrapper.global.inappbrowser.visible` to
`false`.

windows:
Added a `hide` method that sets `browserWrap.style.display` to `none`.

wp:
Added a `hide` method that is identical to `show`, except that it sets
`browser.Visibility` to `Visibility.Collapsed` and sets `AppBar.IsVisible` to
`false`.
This commit is contained in:
ekidder3 2015-02-05 07:20:57 -05:00 committed by Eric Kidder
parent ab696f6ebd
commit df8bcaf751
12 changed files with 133 additions and 2 deletions

View File

@ -216,6 +216,7 @@ The object returned from a call to `cordova.InAppBrowser.open` when the target i
- removeEventListener
- close
- show
- hide
- executeScript
- insertCSS
@ -414,6 +415,27 @@ The function is passed an `InAppBrowserEvent` object.
// some time later...
ref.show();
## InAppBrowser.hide
> Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden.
ref.hide();
- __ref__: reference to the InAppBrowser window (`InAppBrowser`)
### Supported Platforms
- Amazon Fire OS
- Android
- iOS
- Windows 8 and 8.1
### Quick Example
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank');
// some time later...
ref.hide();
## InAppBrowser.executeScript
> Injects JavaScript code into the `InAppBrowser` window

View File

@ -212,6 +212,17 @@ public class InAppBrowser extends CordovaPlugin {
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else if (action.equals("hide")) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.hide();
}
});
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else {
return false;
}

View File

@ -253,6 +253,17 @@ public class InAppBrowser extends CordovaPlugin {
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else if (action.equals("hide")) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.hide();
}
});
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else {
return false;
}

View File

@ -43,6 +43,10 @@ var IABExecs = {
console.error('[FirefoxOS] show not implemented');
},
hide: function (win, lose) {
console.error('[FirefoxOS] hide not implemented');
},
open: function (win, lose, args) {
var strUrl = args[0],
target = args[1],

View File

@ -40,6 +40,7 @@
- (void)close:(CDVInvokedUrlCommand*)command;
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)hide:(CDVInvokedUrlCommand*)command;
@end

View File

@ -243,6 +243,54 @@
});
}
- (void)hide:(CDVInvokedUrlCommand*)command
{
if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to hide IAB after it was closed.");
return;
}
if (_previousStatusBarStyle == -1) {
NSLog(@"Tried to hide IAB while already hidden");
return;
}
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
// Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{
if (self.inAppBrowserViewController != nil) {
_previousStatusBarStyle = -1;
[self.viewController dismissViewControllerAnimated:YES completion:nil];
}
});
}
- (void)hide:(CDVInvokedUrlCommand*)command
{
if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to hide IAB after it was closed.");
return;
}
if (_previousStatusBarStyle == -1) {
NSLog(@"Tried to hide IAB while already hidden");
return;
}
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
// Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{
if (self.inAppBrowserViewController != nil) {
_previousStatusBarStyle = -1;
[self.viewController dismissViewControllerAnimated:YES completion:nil];
}
});
}
- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
{
NSURLRequest* request = [NSURLRequest requestWithURL:url];

View File

@ -65,6 +65,10 @@ void Inappbrowser::show(int, int) {
m_cordova->execQML("CordovaWrapper.global.inappbrowser.visible = true");
}
void Inappbrowser::hide(int, int) {
m_cordova->execQML("CordovaWrapper.global.inappbrowser.visible = false");
}
void Inappbrowser::close(int, int) {
m_cordova->execQML("CordovaWrapper.global.inappbrowser.destroy()");
this->callbackWithoutRemove(_eventCb, EXIT_EVENT);

View File

@ -46,6 +46,7 @@ public:
public slots:
void open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures);
void show(int, int);
void hide(int, int);
void close(int, int);
void injectStyleFile(int cb, int, const QString&, bool);
void injectStyleCode(int cb, int, const QString&, bool);

View File

@ -118,6 +118,11 @@ var IAB = {
}
});
},
hide: function (win, lose) {
if (browserWrap) {
browserWrap.style.display = "none";
}
},
open: function (win, lose, args) {
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
setImmediate(function () {

View File

@ -131,6 +131,21 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
public void hide(string options)
{
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
if (browser != null)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
browser.Visibility = Visibility.Collapsed;
AppBar.IsVisible = false;
});
}
}
public void injectScriptCode(string options)
{
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);

View File

@ -52,6 +52,9 @@
show: function (eventname) {
exec(null, null, "InAppBrowser", "show", []);
},
hide: function (eventname) {
exec(null, null, "InAppBrowser", "hide", []);
},
addEventListener: function (eventname,f) {
if (eventname in this.channels) {
this.channels[eventname].subscribe(f);

View File

@ -38,6 +38,12 @@ var IAB = {
}*/
},
hide: function (win, lose) {
/* empty block, ran out of bacon?
if (browserWrap) {
}*/
},
open: function (win, lose, args) {
var strUrl = args[0],
target = args[1],