diff --git a/README.md b/README.md index 3ca029f..a08fad9 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ instance, or the system browser. - __hideurlbar__: set to `yes` to hide the url bar on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`. - __navigationbuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of both navigation buttons from default. Only has effect if user has location set to `yes` and not hidenavigationbuttons set to `yes`. - __toolbarcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color the toolbar from default. Only has effect if user has location set to `yes`. + - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the left and close button to the right. - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. - __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)). @@ -144,6 +145,7 @@ instance, or the system browser. - __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`) - __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled. - __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled. + - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left. - __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`) on iOS 10+. - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`). - __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`). diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 895b543..048b02a 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -110,6 +110,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String TOOLBAR_COLOR = "toolbarcolor"; private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption"; private static final String CLOSE_BUTTON_COLOR = "closebuttoncolor"; + private static final String LEFT_TO_RIGHT = "lefttoright"; private static final String HIDE_NAVIGATION = "hidenavigationbuttons"; private static final String NAVIGATION_COLOR = "navigationbuttoncolor"; private static final String HIDE_URL = "hideurlbar"; @@ -138,6 +139,7 @@ public class InAppBrowser extends CordovaPlugin { private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2; private String closeButtonCaption = ""; private String closeButtonColor = ""; + private boolean leftToRight = false; private int toolbarColor = android.graphics.Color.LTGRAY; private boolean hideNavigationButtons = false; private String navigationButtonColor = ""; @@ -679,6 +681,10 @@ public class InAppBrowser extends CordovaPlugin { if (closeButtonColorSet != null) { closeButtonColor = closeButtonColorSet; } + String leftToRightSet = features.get(LEFT_TO_RIGHT); + if (leftToRightSet != null) { + leftToRight = leftToRightSet.equals("yes") ? true : false; + } String toolbarColorSet = features.get(TOOLBAR_COLOR); if (toolbarColorSet != null) { toolbarColor = android.graphics.Color.parseColor(toolbarColorSet); @@ -746,7 +752,8 @@ public class InAppBrowser extends CordovaPlugin { } RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); - closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + if (leftToRight) closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + else closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); _close.setLayoutParams(closeLayoutParams); if (Build.VERSION.SDK_INT >= 16) @@ -777,6 +784,7 @@ public class InAppBrowser extends CordovaPlugin { dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); @@ -790,15 +798,22 @@ public class InAppBrowser extends CordovaPlugin { toolbar.setBackgroundColor(toolbarColor); toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); - toolbar.setHorizontalGravity(Gravity.LEFT); + if (leftToRight) { + toolbar.setHorizontalGravity(Gravity.LEFT); + } else { + toolbar.setHorizontalGravity(Gravity.RIGHT); + } toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); - actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + RelativeLayout.LayoutParams actionButtonLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + if (leftToRight) actionButtonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + else actionButtonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + actionButtonContainer.setLayoutParams(actionButtonLayoutParams); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); - actionButtonContainer.setId(Integer.valueOf(1)); + actionButtonContainer.setId(leftToRight ? Integer.valueOf(5) : Integer.valueOf(1)); // Back button ImageButton back = new ImageButton(cordova.getActivity()); @@ -878,7 +893,8 @@ public class InAppBrowser extends CordovaPlugin { // Header Close/Done button - View close = createCloseButton(5); + int closeButtonId = leftToRight ? 1 : 5; + View close = createCloseButton(closeButtonId); toolbar.addView(close); // Footer diff --git a/src/ios/CDVInAppBrowserOptions.h b/src/ios/CDVInAppBrowserOptions.h index 29fd6e1..d9f46bf 100644 --- a/src/ios/CDVInAppBrowserOptions.h +++ b/src/ios/CDVInAppBrowserOptions.h @@ -25,6 +25,7 @@ @property (nonatomic, assign) BOOL toolbar; @property (nonatomic, copy) NSString* closebuttoncaption; @property (nonatomic, copy) NSString* closebuttoncolor; +@property (nonatomic, assign) BOOL lefttoright; @property (nonatomic, copy) NSString* toolbarposition; @property (nonatomic, copy) NSString* toolbarcolor; @property (nonatomic, assign) BOOL toolbartranslucent; diff --git a/src/ios/CDVInAppBrowserOptions.m b/src/ios/CDVInAppBrowserOptions.m index 60e45fc..4e62539 100644 --- a/src/ios/CDVInAppBrowserOptions.m +++ b/src/ios/CDVInAppBrowserOptions.m @@ -44,6 +44,7 @@ self.disallowoverscroll = NO; self.hidenavigationbuttons = NO; self.closebuttoncolor = nil; + self.lefttoright = false; self.toolbarcolor = nil; self.toolbartranslucent = YES; self.beforeload = @""; diff --git a/src/ios/CDVUIInAppBrowser.h b/src/ios/CDVUIInAppBrowser.h index a545833..0a58d2b 100644 --- a/src/ios/CDVUIInAppBrowser.h +++ b/src/ios/CDVUIInAppBrowser.h @@ -84,7 +84,7 @@ - (void)navigateTo:(NSURL*)url; - (void)showLocationBar:(BOOL)show; - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; -- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString; +- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex; - (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions; diff --git a/src/ios/CDVUIInAppBrowser.m b/src/ios/CDVUIInAppBrowser.m index 5e3e900..a294a2b 100644 --- a/src/ios/CDVUIInAppBrowser.m +++ b/src/ios/CDVUIInAppBrowser.m @@ -172,7 +172,8 @@ static CDVUIInAppBrowser* instance = nil; [self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) { - [self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor]; + int closeButtonIndex = browserOptions.lefttoright ? (browserOptions.hidenavigationbuttons ? 1 : 4) : 0; + [self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor :closeButtonIndex]; } // Set Presentation Style UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default @@ -763,9 +764,15 @@ static CDVUIInAppBrowser* instance = nil; // Filter out Navigation Buttons if user requests so if (_browserOptions.hidenavigationbuttons) { - [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]]; + if (_browserOptions.lefttoright) { + [self.toolbar setItems:@[flexibleSpaceButton, self.closeButton]]; + } else { + [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]]; + } + } else if (_browserOptions.lefttoright) { + [self.toolbar setItems:@[self.backButton, fixedSpaceButton, self.forwardButton, flexibleSpaceButton, self.closeButton]]; } else { - [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; + [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; } self.view.backgroundColor = [UIColor grayColor]; @@ -779,7 +786,7 @@ static CDVUIInAppBrowser* instance = nil; [self.webView setFrame:frame]; } -- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString +- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex { // the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically // but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one) @@ -791,7 +798,7 @@ static CDVUIInAppBrowser* instance = nil; self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1]; NSMutableArray* items = [self.toolbar.items mutableCopy]; - [items replaceObjectAtIndex:0 withObject:self.closeButton]; + [items replaceObjectAtIndex:buttonIndex withObject:self.closeButton]; [self.toolbar setItems:items]; } diff --git a/src/ios/CDVWKInAppBrowser.h b/src/ios/CDVWKInAppBrowser.h index 0015cea..1f359b1 100644 --- a/src/ios/CDVWKInAppBrowser.h +++ b/src/ios/CDVWKInAppBrowser.h @@ -73,7 +73,7 @@ - (void)navigateTo:(NSURL*)url; - (void)showLocationBar:(BOOL)show; - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; -- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString; +- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex; - (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions; diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 6364f4f..3b039f5 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -228,7 +228,8 @@ static CDVWKInAppBrowser* instance = nil; [self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) { - [self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor]; + int closeButtonIndex = browserOptions.lefttoright ? (browserOptions.hidenavigationbuttons ? 1 : 4) : 0; + [self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor :closeButtonIndex]; } // Set Presentation Style UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default @@ -884,9 +885,15 @@ BOOL isExiting = FALSE; // Filter out Navigation Buttons if user requests so if (_browserOptions.hidenavigationbuttons) { - [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]]; + if (_browserOptions.lefttoright) { + [self.toolbar setItems:@[flexibleSpaceButton, self.closeButton]]; + } else { + [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]]; + } + } else if (_browserOptions.lefttoright) { + [self.toolbar setItems:@[self.backButton, fixedSpaceButton, self.forwardButton, flexibleSpaceButton, self.closeButton]]; } else { - [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; + [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; } self.view.backgroundColor = [UIColor grayColor]; @@ -900,7 +907,7 @@ BOOL isExiting = FALSE; [self.webView setFrame:frame]; } -- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString +- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex { // the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically // but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one) @@ -912,7 +919,7 @@ BOOL isExiting = FALSE; self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1]; NSMutableArray* items = [self.toolbar.items mutableCopy]; - [items replaceObjectAtIndex:0 withObject:self.closeButton]; + [items replaceObjectAtIndex:buttonIndex withObject:self.closeButton]; [self.toolbar setItems:items]; }