CB-8467
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:
parent
ab696f6ebd
commit
df8bcaf751
24
README.md
24
README.md
@ -216,6 +216,7 @@ The object returned from a call to `cordova.InAppBrowser.open` when the target i
|
|||||||
- removeEventListener
|
- removeEventListener
|
||||||
- close
|
- close
|
||||||
- show
|
- show
|
||||||
|
- hide
|
||||||
- executeScript
|
- executeScript
|
||||||
- insertCSS
|
- insertCSS
|
||||||
|
|
||||||
@ -414,6 +415,27 @@ The function is passed an `InAppBrowserEvent` object.
|
|||||||
// some time later...
|
// some time later...
|
||||||
ref.show();
|
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
|
## InAppBrowser.executeScript
|
||||||
|
|
||||||
> Injects JavaScript code into the `InAppBrowser` window
|
> Injects JavaScript code into the `InAppBrowser` window
|
||||||
@ -683,4 +705,4 @@ iab.open('http://url-that-fails-whitelist.com', '_blank'); // loads in th
|
|||||||
iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
|
iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
|
||||||
iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
|
iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -212,6 +212,17 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
pluginResult.setKeepCallback(true);
|
pluginResult.setKeepCallback(true);
|
||||||
this.callbackContext.sendPluginResult(pluginResult);
|
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 {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,17 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
pluginResult.setKeepCallback(true);
|
pluginResult.setKeepCallback(true);
|
||||||
this.callbackContext.sendPluginResult(pluginResult);
|
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 {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,10 @@ var IABExecs = {
|
|||||||
console.error('[FirefoxOS] show not implemented');
|
console.error('[FirefoxOS] show not implemented');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
hide: function (win, lose) {
|
||||||
|
console.error('[FirefoxOS] hide not implemented');
|
||||||
|
},
|
||||||
|
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0],
|
||||||
target = args[1],
|
target = args[1],
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
- (void)close:(CDVInvokedUrlCommand*)command;
|
- (void)close:(CDVInvokedUrlCommand*)command;
|
||||||
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
|
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
|
||||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||||
|
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -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
|
- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
|
||||||
{
|
{
|
||||||
NSURLRequest* request = [NSURLRequest requestWithURL:url];
|
NSURLRequest* request = [NSURLRequest requestWithURL:url];
|
||||||
|
@ -65,6 +65,10 @@ void Inappbrowser::show(int, int) {
|
|||||||
m_cordova->execQML("CordovaWrapper.global.inappbrowser.visible = true");
|
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) {
|
void Inappbrowser::close(int, int) {
|
||||||
m_cordova->execQML("CordovaWrapper.global.inappbrowser.destroy()");
|
m_cordova->execQML("CordovaWrapper.global.inappbrowser.destroy()");
|
||||||
this->callbackWithoutRemove(_eventCb, EXIT_EVENT);
|
this->callbackWithoutRemove(_eventCb, EXIT_EVENT);
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures);
|
void open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures);
|
||||||
void show(int, int);
|
void show(int, int);
|
||||||
|
void hide(int, int);
|
||||||
void close(int, int);
|
void close(int, int);
|
||||||
void injectStyleFile(int cb, int, const QString&, bool);
|
void injectStyleFile(int cb, int, const QString&, bool);
|
||||||
void injectStyleCode(int cb, int, const QString&, bool);
|
void injectStyleCode(int cb, int, const QString&, bool);
|
||||||
|
@ -118,6 +118,11 @@ var IAB = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
hide: function (win, lose) {
|
||||||
|
if (browserWrap) {
|
||||||
|
browserWrap.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
|
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
|
@ -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)
|
public void injectScriptCode(string options)
|
||||||
{
|
{
|
||||||
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||||
|
@ -50,7 +50,10 @@
|
|||||||
exec(null, null, "InAppBrowser", "close", []);
|
exec(null, null, "InAppBrowser", "close", []);
|
||||||
},
|
},
|
||||||
show: function (eventname) {
|
show: function (eventname) {
|
||||||
exec(null, null, "InAppBrowser", "show", []);
|
exec(null, null, "InAppBrowser", "show", []);
|
||||||
|
},
|
||||||
|
hide: function (eventname) {
|
||||||
|
exec(null, null, "InAppBrowser", "hide", []);
|
||||||
},
|
},
|
||||||
addEventListener: function (eventname,f) {
|
addEventListener: function (eventname,f) {
|
||||||
if (eventname in this.channels) {
|
if (eventname in this.channels) {
|
||||||
|
@ -38,6 +38,12 @@ var IAB = {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
},
|
},
|
||||||
|
hide: function (win, lose) {
|
||||||
|
/* empty block, ran out of bacon?
|
||||||
|
if (browserWrap) {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
},
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0],
|
||||||
target = args[1],
|
target = args[1],
|
||||||
|
Loading…
Reference in New Issue
Block a user