Skip to content

Commit bf69393

Browse files
committed
Improving nav button UI on iOS and using status bar height for sizing logic when nav bar is on top
1 parent de86501 commit bf69393

File tree

1 file changed

+61
-17
lines changed

1 file changed

+61
-17
lines changed

src/ios/CDVInAppBrowser.m

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -642,21 +642,8 @@ - (void)createViews
642642
self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000];
643643
self.addressLabel.userInteractionEnabled = NO;
644644

645-
NSString* frontArrowString = NSLocalizedString(@"", nil); // create arrow from Unicode char
646-
self.forwardButton = [[UIBarButtonItem alloc] initWithTitle:frontArrowString style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)];
647-
self.forwardButton.enabled = YES;
648-
self.forwardButton.imageInsets = UIEdgeInsetsZero;
649-
if (_browserOptions.navigationbuttoncolor != nil) { // Set button color if user sets it in options
650-
self.forwardButton.tintColor = [self colorFromHexString:_browserOptions.navigationbuttoncolor];
651-
}
652-
653-
NSString* backArrowString = NSLocalizedString(@"", nil); // create arrow from Unicode char
654-
self.backButton = [[UIBarButtonItem alloc] initWithTitle:backArrowString style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];
655-
self.backButton.enabled = YES;
656-
self.backButton.imageInsets = UIEdgeInsetsZero;
657-
if (_browserOptions.navigationbuttoncolor != nil) { // Set button color if user sets it in options
658-
self.backButton.tintColor = [self colorFromHexString:_browserOptions.navigationbuttoncolor];
659-
}
645+
self.forwardButton = [self buildForwardButton];
646+
self.backButton = [self buildBackButton];
660647

661648
// Filter out Navigation Buttons if user requests so
662649
if (_browserOptions.hidenavigationbuttons) {
@@ -676,6 +663,63 @@ - (void) setWebViewFrame : (CGRect) frame {
676663
[self.webView setFrame:frame];
677664
}
678665

666+
- (UIBarButtonItem*)buildForwardButton
667+
{
668+
UIImage *forwardArrow = [self drawForwardArrow];
669+
UIBarButtonItem *forwardButton = [[UIBarButtonItem alloc] initWithImage:forwardArrow style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)];
670+
forwardButton.enabled = YES;
671+
forwardButton.imageInsets = UIEdgeInsetsZero;
672+
673+
if (_browserOptions.navigationbuttoncolor != nil) { // Set button color if user sets it in options
674+
forwardButton.tintColor = [self colorFromHexString:_browserOptions.navigationbuttoncolor];
675+
}
676+
677+
return forwardButton;
678+
}
679+
680+
- (UIBarButtonItem*)buildBackButton
681+
{
682+
UIImage *backArrow = [self drawBackArrow];
683+
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:backArrow style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];
684+
backButton.enabled = YES;
685+
backButton.imageInsets = UIEdgeInsetsZero;
686+
687+
if (_browserOptions.navigationbuttoncolor != nil) { // Set button color if user sets it in options
688+
backButton.tintColor = [self colorFromHexString:_browserOptions.navigationbuttoncolor];
689+
}
690+
691+
return backButton;
692+
}
693+
694+
- (UIImage*)drawForwardArrow
695+
{
696+
CGSize canvasSize = CGSizeMake(20,20);
697+
CGFloat scale = [UIScreen mainScreen].scale;
698+
699+
canvasSize.width *= scale;
700+
canvasSize.height *= scale;
701+
702+
UIGraphicsBeginImageContextWithOptions(canvasSize, false, 0);
703+
CGContextRef context = UIGraphicsGetCurrentContext();
704+
705+
CGContextBeginPath(context);
706+
CGContextMoveToPoint( context, canvasSize.width * 3.0/10.0, canvasSize.height * 2.8/10.0);
707+
CGContextAddLineToPoint(context, canvasSize.width * 5.0/10.0, canvasSize.height * 5.0/10.0);
708+
CGContextAddLineToPoint(context, canvasSize.width * 3.0/10.0, canvasSize.height * 7.2/10.0);
709+
710+
CGContextSetLineWidth(context, (scale > 1.0 ? 0.75 * scale : 1.0));
711+
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
712+
CGContextStrokePath(context);
713+
714+
return UIGraphicsGetImageFromCurrentImageContext();
715+
}
716+
717+
-(UIImage*)drawBackArrow
718+
{
719+
UIImage *forwardArrow = [self drawForwardArrow];
720+
return [UIImage imageWithCGImage:forwardArrow.CGImage scale:forwardArrow.scale orientation:UIImageOrientationUpMirrored];
721+
}
722+
679723
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString
680724
{
681725
// the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically
@@ -898,8 +942,8 @@ - (float) getStatusBarOffset {
898942
}
899943

900944
- (void) rePositionViews {
901-
if ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]) {
902-
[self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT, self.webView.frame.size.width, self.webView.frame.size.height)];
945+
if ((_browserOptions.toolbar) && ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop])) {
946+
[self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT + [self getStatusBarOffset], self.webView.frame.size.width, self.webView.frame.size.height - [self getStatusBarOffset])];
903947
[self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
904948
}
905949
}

0 commit comments

Comments
 (0)