Skip to content

Commit

Permalink
CB-13969 functionality extended to WKWebView
Browse files Browse the repository at this point in the history
  • Loading branch information
steinaragustli committed Feb 28, 2019
1 parent 3c0a42e commit 9c7c2f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ios/CDVWKInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 12 additions & 5 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
[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
Expand Down Expand Up @@ -884,9 +885,15 @@ - (void)createViews

// 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];
Expand All @@ -900,7 +907,7 @@ - (void) setWebViewFrame : (CGRect) frame {
[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)
Expand All @@ -912,7 +919,7 @@ - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString
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];
}

Expand Down

0 comments on commit 9c7c2f3

Please sign in to comment.