Skip to content

Commit 9c7c2f3

Browse files
CB-13969 functionality extended to WKWebView
1 parent 3c0a42e commit 9c7c2f3

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/ios/CDVWKInAppBrowser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
- (void)navigateTo:(NSURL*)url;
7474
- (void)showLocationBar:(BOOL)show;
7575
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
76-
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString;
76+
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
7777

7878
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
7979

src/ios/CDVWKInAppBrowser.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
228228
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
229229
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
230230
if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) {
231-
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor];
231+
int closeButtonIndex = browserOptions.lefttoright ? (browserOptions.hidenavigationbuttons ? 1 : 4) : 0;
232+
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor :closeButtonIndex];
232233
}
233234
// Set Presentation Style
234235
UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default
@@ -884,9 +885,15 @@ - (void)createViews
884885

885886
// Filter out Navigation Buttons if user requests so
886887
if (_browserOptions.hidenavigationbuttons) {
887-
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
888+
if (_browserOptions.lefttoright) {
889+
[self.toolbar setItems:@[flexibleSpaceButton, self.closeButton]];
890+
} else {
891+
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
892+
}
893+
} else if (_browserOptions.lefttoright) {
894+
[self.toolbar setItems:@[self.backButton, fixedSpaceButton, self.forwardButton, flexibleSpaceButton, self.closeButton]];
888895
} else {
889-
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
896+
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
890897
}
891898

892899
self.view.backgroundColor = [UIColor grayColor];
@@ -900,7 +907,7 @@ - (void) setWebViewFrame : (CGRect) frame {
900907
[self.webView setFrame:frame];
901908
}
902909

903-
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString
910+
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex
904911
{
905912
// the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically
906913
// 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 @@ - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString
912919
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];
913920

914921
NSMutableArray* items = [self.toolbar.items mutableCopy];
915-
[items replaceObjectAtIndex:0 withObject:self.closeButton];
922+
[items replaceObjectAtIndex:buttonIndex withObject:self.closeButton];
916923
[self.toolbar setItems:items];
917924
}
918925

0 commit comments

Comments
 (0)