cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] infil00p closed pull request #197: CB-12132: (android & ios) implement hidenotclose feature
Date Thu, 01 Jan 1970 00:00:00 GMT
infil00p closed pull request #197: CB-12132: (android & ios) implement hidenotclose feature
URL: https://github.com/apache/cordova-plugin-inappbrowser/pull/197
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 1e0645c4..ffbd9c62
--- a/README.md
+++ b/README.md
@@ -114,6 +114,7 @@ instance, or the system browser.
     - __hardwareback__: set to `yes` to use the hardware back button to navigate backwards
through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will
close.  The default value is `yes`, so you must set it to `no` if you want the back button
to simply close the InAppBrowser.
     - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from
autoplaying (defaults to `no`).
     - __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume
with the app to stop background audio (this may be required to avoid Google Play issues like
described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)).
+    - __hidenotclose__: set to 'yes' to make the done/close button hide the browser window
rather than closing the browser (defaults to 'no')
 
     iOS only:
 
@@ -131,6 +132,7 @@ instance, or the system browser.
     - __presentationstyle__:  Set to `pagesheet`, `formsheet` or `fullscreen` to set the
[presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle)
(defaults to `fullscreen`).
     - __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to
set the [transition style](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle)
(defaults to `coververtical`).
     - __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar
to be at the top or bottom of the window.
+    - __hidenotclose__: set to 'yes' to make the done/close button hide the browser window
rather than closing the browser (defaults to 'no')
 
     Windows only:
 
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index b54c2241..f8ccb9ee 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -77,6 +77,7 @@ Licensed to the Apache Software Foundation (ASF) under one
     private static final String SYSTEM = "_system";
     private static final String EXIT_EVENT = "exit";
     private static final String LOCATION = "location";
+    private static final String HIDEWINDOW = "hidenotclose";
     private static final String ZOOM = "zoom";
     private static final String HIDDEN = "hidden";
     private static final String LOAD_START_EVENT = "loadstart";
@@ -94,6 +95,7 @@ Licensed to the Apache Software Foundation (ASF) under one
     private EditText edittext;
     private CallbackContext callbackContext;
     private boolean showLocationBar = true;
+    private boolean hideNotClose = false;
     private boolean showZoomControls = true;
     private boolean openWindowHidden = false;
     private boolean clearAllCache = false;
@@ -501,6 +503,15 @@ private boolean getShowLocationBar() {
         return this.showLocationBar;
     }
 
+    /**
+     * Should we hide instead of closing
+     *
+     * @return boolean
+     */
+    private boolean getHideNotClose() {
+        return this.hideNotClose;
+    }
+
     private InAppBrowser getInAppBrowser(){
         return this;
     }
@@ -517,12 +528,17 @@ public String showWebPage(final String url, HashMap<String, Boolean>
features) {
         showZoomControls = true;
         openWindowHidden = false;
         mediaPlaybackRequiresUserGesture = false;
+        hideNotClose = false;
 
         if (features != null) {
             Boolean show = features.get(LOCATION);
             if (show != null) {
                 showLocationBar = show.booleanValue();
             }
+            Boolean hideWin = features.get(HIDEWINDOW);
+            if (hideWin != null) {
+                hideNotClose = hideWin.booleanValue();
+            }
             Boolean zoom = features.get(ZOOM);
             if (zoom != null) {
                 showZoomControls = zoom.booleanValue();
@@ -704,7 +720,10 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
 
                 close.setOnClickListener(new View.OnClickListener() {
                     public void onClick(View v) {
-                        closeDialog();
+                        if(getHideNotClose())
+                            dialog.hide();
+                        else
+                            closeDialog();
                     }
                 });
 
diff --git a/src/ios/CDVInAppBrowser.h b/src/ios/CDVInAppBrowser.h
old mode 100644
new mode 100755
index d258eb09..d354cea6
--- a/src/ios/CDVInAppBrowser.h
+++ b/src/ios/CDVInAppBrowser.h
@@ -52,6 +52,7 @@
 @property (nonatomic, copy) NSString* toolbarposition;
 @property (nonatomic, assign) BOOL clearcache;
 @property (nonatomic, assign) BOOL clearsessioncache;
+@property (nonatomic, assign) BOOL hidenotclose;
 
 @property (nonatomic, copy) NSString* presentationstyle;
 @property (nonatomic, copy) NSString* transitionstyle;
@@ -96,6 +97,7 @@
 @property (nonatomic) NSURL* currentURL;
 
 - (void)close;
+- (void)hide;
 - (void)navigateTo:(NSURL*)url;
 - (void)showLocationBar:(BOOL)show;
 - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m
old mode 100644
new mode 100755
index 4646972a..5353d01a
--- a/src/ios/CDVInAppBrowser.m
+++ b/src/ios/CDVInAppBrowser.m
@@ -246,25 +246,11 @@ - (void)show:(CDVInvokedUrlCommand*)command
 - (void)hide:(CDVInvokedUrlCommand*)command
 {
     if (self.inAppBrowserViewController == nil) {
-        NSLog(@"Tried to hide IAB after it was closed.");
+        NSLog(@"IAB.hide() called but it was already 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];
-        }
-    });
+    // browserHide will take care of hiding.
+    [self.inAppBrowserViewController hide];
 }
 
 - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
@@ -496,6 +482,28 @@ - (void)browserExit
     _previousStatusBarStyle = -1; // this value was reset before reapplying it. caused statusbar
to stay black on ios7
 }
 
+- (void)browserHide
+{
+    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];
+        }
+    });
+}
+
 @end
 
 #pragma mark CDVInAppBrowserViewController
@@ -568,7 +576,11 @@ - (void)createViews
     self.spinner.userInteractionEnabled = NO;
     [self.spinner stopAnimating];
 
-    self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:@selector(close)];
+    if (_browserOptions.hidenotclose != nil) {
+        self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:@selector(hide)];
+    } else {
+        self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:@selector(close)];
+    }
     self.closeButton.enabled = YES;
 
     UIBarButtonItem* flexibleSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
@@ -815,6 +827,13 @@ - (void)close
     });
 }
 
+- (void)hide
+{
+    if ((self.navigationDelegate != nil) && [self.navigationDelegate respondsToSelector:@selector(browserHide)])
{
+        [self.navigationDelegate browserHide];
+    }
+}
+
 - (void)navigateTo:(NSURL*)url
 {
     NSURLRequest* request = [NSURLRequest requestWithURL:url];


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message