Skip to content

Commit 37ca592

Browse files
committed
Revert "UI Tweaks for toolbars and icons (#8)"
This reverts commit e81d69f.
1 parent 8748761 commit 37ca592

File tree

5 files changed

+35
-83
lines changed

5 files changed

+35
-83
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ instance, or the system browser.
106106
- **bannertextcolor**: Set to a valid hext color string.
107107
- **bannertextsize**: Set to an integer.
108108
- **pagetitleheader**: Set to `yes` or `no` to diplay the current page title. If `yes`, a header with the current page title and close button is added. A reload button replaces the close button in the toolbar.
109-
- **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 and effects all toolbars.
110-
- **toolbartextcolor**: set to a valid hex color string and it will change the color of text on the toolbar from default.
111109

112110
Android supports these additional options:
113111

@@ -126,6 +124,7 @@ instance, or the system browser.
126124
- **hidenavigationbuttons**: set to `yes` to hide the navigation buttons on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
127125
- **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`.
128126
- **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`.
127+
- **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`.
129128
- **lefttoright**: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is `no`.
130129
- **zoom**: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
131130
- **mediaPlaybackRequiresUserAction**: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
@@ -146,6 +145,7 @@ instance, or the system browser.
146145
- **hidenavigationbuttons**: set to `yes` or `no` to turn the toolbar navigation buttons on or off (defaults to `no`). Only applicable if toolbar is not disabled.
147146
- **navigationbuttoncolor**: set as a valid hex color string, for example: `#00ff00`, to change from the default color. Only applicable if navigation buttons are visible.
148147
- **toolbar**: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
148+
- **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.
149149
- **toolbartranslucent**: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled.
150150
- **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.
151151
- **enableViewportScale**: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).

src/android/InAppBrowser.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public class InAppBrowser extends CordovaPlugin {
112112
private static final Boolean DEFAULT_HARDWARE_BACK = true;
113113
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
114114
private static final String TOOLBAR_COLOR = "toolbarcolor";
115-
private static final String TOOLBAR_TEXT_COLOR = "toolbartextcolor";
116115
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption";
117116
private static final String CLOSE_BUTTON_COLOR = "closebuttoncolor";
118117
private static final String LEFT_TO_RIGHT = "lefttoright";
@@ -137,7 +136,6 @@ public class InAppBrowser extends CordovaPlugin {
137136
private static final List customizableOptions = Arrays.asList(
138137
CLOSE_BUTTON_CAPTION,
139138
TOOLBAR_COLOR,
140-
TOOLBAR_TEXT_COLOR,
141139
NAVIGATION_COLOR,
142140
CLOSE_BUTTON_COLOR,
143141
FOOTER_COLOR,
@@ -166,7 +164,6 @@ public class InAppBrowser extends CordovaPlugin {
166164
private String closeButtonColor = "";
167165
private boolean leftToRight = false;
168166
private int toolbarColor = android.graphics.Color.LTGRAY;
169-
private int toolbarTextColor = android.graphics.Color.LTGRAY;
170167
private boolean hideNavigationButtons = false;
171168
private String navigationButtonColor = "";
172169
private boolean hideUrlBar = false;
@@ -757,10 +754,6 @@ public String showWebPage(final String url, HashMap<String, String> features) {
757754
if (toolbarColorSet != null) {
758755
toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
759756
}
760-
String toolbarTextColorSet = features.get(TOOLBAR_TEXT_COLOR);
761-
if (toolbarTextColorSet != null) {
762-
toolbarTextColor = android.graphics.Color.parseColor(toolbarTextColorSet);
763-
}
764757
String navigationButtonColorSet = features.get(NAVIGATION_COLOR);
765758
if (navigationButtonColorSet != null) {
766759
navigationButtonColor = navigationButtonColorSet;
@@ -1012,7 +1005,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
10121005
// Page title header layout
10131006
GradientDrawable pageTitleHeaderBorderBackground = new GradientDrawable();
10141007
pageTitleHeaderBorderBackground.setColor(toolbarColor);
1015-
pageTitleHeaderBorderBackground.setStroke(1, darkerColorForColor(toolbarColor));
1008+
pageTitleHeaderBorderBackground.setStroke(1, android.graphics.Color.parseColor("#E9E6E1"));
10161009
RelativeLayout pageTitleHeader = new RelativeLayout(cordova.getActivity());
10171010
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
10181011
pageTitleHeader.setBackgroundDrawable(pageTitleHeaderBorderBackground);
@@ -1030,11 +1023,10 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
10301023
pageTitleTextView.setLayoutParams(pageTitleTextViewLayoutParams);
10311024
pageTitleTextView.setText("Loading...");
10321025
pageTitleTextView.setTextSize(bannerTextSize);
1033-
pageTitleTextView.setTextColor(toolbarTextColor);
1026+
if (navigationButtonColor != "") pageTitleTextView.setTextColor(android.graphics.Color.parseColor(navigationButtonColor));
10341027
pageTitleTextView.setTypeface(null, Typeface.BOLD);
10351028
int lockResId = activityRes.getIdentifier("lock", "drawable", cordova.getActivity().getPackageName());
10361029
Drawable lockIcon = activityRes.getDrawable(lockResId);
1037-
lockIcon.setTint(toolbarTextColor);
10381030
pageTitleTextView.setCompoundDrawablesWithIntrinsicBounds(lockIcon, null, null, null);
10391031
pageTitleTextView.setCompoundDrawablePadding(this.dpToPixels(8));
10401032
pageTitleTextView.setGravity(Gravity.CENTER_VERTICAL);
@@ -1052,9 +1044,8 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
10521044
_footerColor = android.graphics.Color.LTGRAY;
10531045
}
10541046
GradientDrawable footerBorderBackground = new GradientDrawable();
1055-
int footerBorderBackgroundColor = getShowPageTitleHeader() ? toolbarColor : _footerColor;
1056-
footerBorderBackground.setColor(footerBorderBackgroundColor);
1057-
footerBorderBackground.setStroke(1, darkerColorForColor(footerBorderBackgroundColor));
1047+
footerBorderBackground.setColor(getShowPageTitleHeader() ? toolbarColor : _footerColor);
1048+
footerBorderBackground.setStroke(1, android.graphics.Color.parseColor("#E9E6E1"));
10581049
RelativeLayout footer = new RelativeLayout(cordova.getActivity());
10591050
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
10601051
footer.setBackgroundDrawable(footerBorderBackground);
@@ -1303,14 +1294,6 @@ private boolean sendBannerTappedEvent() {
13031294
return false;
13041295
}
13051296

1306-
private static int darkerColorForColor(int color) {
1307-
int a = Color.alpha(color);
1308-
return Color.argb(a,
1309-
Math.max(Color.red(color) - 51, 0),
1310-
Math.max(Color.green(color) - 51, 0),
1311-
Math.max(Color.blue(color) - 51, 0));
1312-
}
1313-
13141297
/**
13151298
* Receive File Data from File Chooser
13161299
*

src/ios/CDVInAppBrowserOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
@property (nonatomic, assign) BOOL lefttoright;
2929
@property (nonatomic, copy) NSString* toolbarposition;
3030
@property (nonatomic, copy) NSString* toolbarcolor;
31-
@property (nonatomic, copy) NSString* toolbartextcolor;
3231
@property (nonatomic, assign) BOOL toolbartranslucent;
3332
@property (nonatomic, assign) BOOL hidenavigationbuttons;
3433
@property (nonatomic, copy) NSString* navigationbuttoncolor;

src/ios/CDVInAppBrowserOptions.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ - (id)init
4343
self.closebuttoncolor = nil;
4444
self.lefttoright = false;
4545
self.toolbarcolor = nil;
46-
self.toolbartextcolor = nil;
4746
self.toolbartranslucent = YES;
4847
self.beforeload = @"";
4948

src/ios/CDVWKInAppBrowser.m

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ - (void)createViews
814814
self.bannerTextView.opaque = YES;
815815
self.bannerTextView.scrollEnabled = NO;
816816
self.bannerTextView.textAlignment = NSTextAlignmentLeft;
817-
self.bannerTextView.textColor = _browserOptions.bannertextcolor != nil ? [self colorFromHexString:_browserOptions.bannertextcolor] : [UIColor labelColor];
817+
self.bannerTextView.textColor = _browserOptions.bannertextcolor != nil ? [self colorFromHexString:_browserOptions.bannertextcolor] : [self colorFromHexString:@"#000000"];
818818
// NOTE: Edge format is top, left, bottom, right.
819819
self.bannerTextView.textContainerInset = UIEdgeInsetsMake(8, 5, 8, 5);
820820
self.bannerTextView.userInteractionEnabled = YES;
@@ -887,14 +887,17 @@ - (void)createViews
887887

888888
self.pageTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.navigationItem.titleView.frame.origin.x, self.navigationItem.titleView.frame.origin.y, self.navigationItem.titleView.frame.size.width, self.navigationItem.titleView.frame.size.height)];
889889

890-
UIButton *backUIButton = [self createNavButton:@"chevron.backward" fallbackImageName:@"back" titleFallback:@"" action:@selector(goBack:) withDescription:@"back button"];
891-
self.backButton = [[UIBarButtonItem alloc] initWithCustomView:backUIButton];
892-
893-
UIButton *forwardUIButton = [self createNavButton:@"chevron.forward" fallbackImageName:@"forward" titleFallback:@"" action:@selector(goForward:) withDescription:@"forward button"];
890+
UIButton *forwardUIButton = [self createButton:@"forward" titleFallback:@"" action:@selector(goForward:) withDescription:@"forward button"];
894891
self.forwardButton = [[UIBarButtonItem alloc] initWithCustomView:forwardUIButton];
892+
self.forwardButton.imageInsets = UIEdgeInsetsZero;
893+
894+
UIButton *backUIButton = [self createButton:@"back" titleFallback:@"" action:@selector(goBack:) withDescription:@"back button"];
895+
self.backButton = [[UIBarButtonItem alloc] initWithCustomView:backUIButton];
896+
self.backButton.imageInsets = UIEdgeInsetsZero;
895897

896-
UIButton *reloadUIButton = [self createNavButton:@"arrow.clockwise" fallbackImageName:@"reload" titleFallback:@"" action:@selector(doReload:) withDescription:@"reload button"];
898+
UIButton *reloadUIButton = [self createButton:@"reload" titleFallback:@"" action:@selector(doReload:) withDescription:@"reload button"];
897899
self.reloadButton = [[UIBarButtonItem alloc] initWithCustomView:reloadUIButton];
900+
self.reloadButton.imageInsets = UIEdgeInsetsZero;
898901

899902
if (_browserOptions.pagetitleheader) {
900903
if (_browserOptions.hidenavigationbuttons) {
@@ -903,7 +906,7 @@ - (void)createViews
903906
[self.toolbar setItems:@[self.backButton, fixedSpaceButton, self.forwardButton, flexibleSpaceButton, self.reloadButton]];
904907
}
905908
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, [_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop] ? self.toolbar.frame.size.height - 1 : 0, self.view.bounds.size.width, 1)];
906-
lineView.backgroundColor = [self darkerColorForColor:self.toolbar.barTintColor];
909+
lineView.backgroundColor = [self colorFromHexString:@"#E9E6E1"];
907910
[self.toolbar addSubview:lineView];
908911
} else {
909912
// Filter out Navigation Buttons if user requests so
@@ -990,11 +993,7 @@ - (void)showPageTitleHeader:(BOOL)show
990993

991994
// Style the navigation bar
992995
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
993-
if (_browserOptions.toolbarcolor != nil) { // Set toolbar color if user sets it in options
994-
appearance.backgroundColor = [self colorFromHexString:_browserOptions.toolbarcolor];
995-
} else {
996-
[appearance configureWithOpaqueBackground];
997-
}
996+
[appearance configureWithOpaqueBackground];
998997
navBar.standardAppearance = appearance;
999998
navBar.scrollEdgeAppearance = appearance;
1000999

@@ -1003,13 +1002,12 @@ - (void)showPageTitleHeader:(BOOL)show
10031002
customTitleView.axis = UILayoutConstraintAxisHorizontal;
10041003
customTitleView.distribution = UIStackViewDistributionEqualSpacing;
10051004
customTitleView.alignment = UIStackViewAlignmentCenter;
1006-
UIColor *toolbarTextColorOrDefault = _browserOptions.toolbartextcolor != nil ? [self colorFromHexString:_browserOptions.toolbartextcolor] : [UIColor labelColor];
1007-
UIImageView *lockIconView = [[UIImageView alloc] initWithImage:[self createSystemSymbolImage:@"lock.fill" fallbackImageName:@"lock" pointSize:12 withTintColor:toolbarTextColorOrDefault]];
1005+
customTitleView.spacing = 8;
1006+
UIImageView *lockIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lock"]];
10081007
self.pageTitleLabel.text = NSLocalizedString(@"Loading...", nil);
10091008
[self.pageTitleLabel setFont:[UIFont boldSystemFontOfSize:16]];
10101009
[self.pageTitleLabel sizeToFit];
10111010
self.pageTitleLabel.textAlignment = NSTextAlignmentLeft;
1012-
self.pageTitleLabel.textColor = toolbarTextColorOrDefault;
10131011
[customTitleView addArrangedSubview:lockIconView];
10141012
[customTitleView addArrangedSubview:self.pageTitleLabel];
10151013
self.navigationItem.titleView = customTitleView;
@@ -1242,18 +1240,6 @@ - (UIColor *)colorFromHexString:(NSString *)hexString {
12421240
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
12431241
}
12441242

1245-
// Helper function to return a slightly darker version of UIColor
1246-
- (UIColor *)darkerColorForColor:(UIColor *)c
1247-
{
1248-
CGFloat r, g, b, a;
1249-
if ([c getRed:&r green:&g blue:&b alpha:&a])
1250-
return [UIColor colorWithRed:MAX(r - 0.2, 0.0)
1251-
green:MAX(g - 0.2, 0.0)
1252-
blue:MAX(b - 0.2, 0.0)
1253-
alpha:a];
1254-
return nil;
1255-
}
1256-
12571243
#pragma mark WKNavigationDelegate
12581244

12591245
- (void)webView:(WKWebView *)theWebView didStartProvisionalNavigation:(WKNavigation *)navigation{
@@ -1372,49 +1358,34 @@ - (void)presentationControllerWillDismiss:(UIPresentationController *)presentati
13721358
isExiting = TRUE;
13731359
}
13741360

1375-
- (UIImage*) createSystemSymbolImage:(NSString*)systemSymbolName fallbackImageName:(NSString*)fallbackImageName pointSize:(CGFloat)pointSize
1376-
{
1377-
return [self createSystemSymbolImage:systemSymbolName fallbackImageName:fallbackImageName pointSize:pointSize withTintColor:[UIColor labelColor]];
1378-
}
1379-
1380-
// See https://developer.apple.com/design/human-interface-guidelines/sf-symbols#app-top
1381-
- (UIImage*) createSystemSymbolImage:(NSString*)systemSymbolName fallbackImageName:(NSString*)fallbackImageName pointSize:(CGFloat)pointSize withTintColor:(UIColor*)color
1382-
{
1383-
if (@available(iOS 13.0, *)) {
1384-
// At least iOS 13.0 which means we can use system symbol
1385-
UIImageSymbolConfiguration * configuration = [UIImageSymbolConfiguration configurationWithPointSize:pointSize];
1386-
return [[UIImage systemImageNamed:systemSymbolName withConfiguration:configuration] imageWithTintColor:color renderingMode:UIImageRenderingModeAlwaysOriginal];
1387-
} else {
1388-
// Use the fallback image for older versions of iOS
1389-
UIImage* buttonImage = [UIImage imageNamed:fallbackImageName];
1390-
if (!buttonImage) {
1391-
NSLog([@"createSystemSymbolImage - failed to load image" stringByAppendingString:fallbackImageName]);
1392-
}
1393-
return buttonImage;
1394-
}
1395-
}
1396-
1397-
- (UIButton*) createNavButton:(NSString*)systemSymbolName fallbackImageName:(NSString*)fallbackImageName titleFallback:(NSString*)titleFallback action:(SEL)action withDescription:(NSString*)description
1361+
- (UIButton*) createButton:(NSString*)name titleFallback:(NSString*)titleFallback action:(SEL)action withDescription:(NSString*)description
13981362
{
13991363
UIButton* result = [UIButton buttonWithType:UIButtonTypeCustom];
14001364
result.bounds = CGRectMake(0, 0, 30, 30);
14011365

1402-
// At least iOS 13.0 which means we can use system symbol
1403-
UIColor *color = _browserOptions.navigationbuttoncolor != nil ? [self colorFromHexString:_browserOptions.navigationbuttoncolor] : [UIColor labelColor];
1404-
UIImage *buttonImage = [self createSystemSymbolImage:systemSymbolName fallbackImageName:fallbackImageName pointSize:24 withTintColor:color];
1366+
UIImage *buttonImage = [UIImage imageNamed:name];
1367+
if (!buttonImage) {
1368+
NSLog([@"createButton - failed to load iamge" stringByAppendingString:name]);
1369+
}
14051370

1406-
NSString *fallbackImageNamePressed = [fallbackImageName stringByAppendingString:@"_light"];
1407-
UIImage *buttonImagePressed = [self createSystemSymbolImage:systemSymbolName fallbackImageName:fallbackImageNamePressed pointSize:24 withTintColor:[color colorWithAlphaComponent:0.9]];
1371+
NSString *pressedName = [name stringByAppendingString:@"_light"];
1372+
UIImage *buttonImagePressed = [UIImage imageNamed:pressedName];
1373+
if (!buttonImagePressed) {
1374+
NSLog([@"createButton - failed to load image" stringByAppendingString:pressedName]);
1375+
}
14081376

14091377
if ((buttonImage) && (buttonImagePressed)) {
1410-
[result setImage:buttonImage forState:UIControlStateNormal];
14111378
[result setImage:buttonImagePressed forState:UIControlStateHighlighted];
14121379
result.adjustsImageWhenHighlighted = NO;
1380+
1381+
[result setImage:buttonImage forState:UIControlStateNormal];
14131382
} else {
14141383
[result setTitle:titleFallback forState:UIControlStateNormal];
14151384
[result setTitle:titleFallback forState:UIControlStateHighlighted];
1416-
[result setTitleColor:color forState:UIControlStateNormal];
1417-
[result setTitleColor:color forState:UIControlStateHighlighted];
1385+
if (_browserOptions.navigationbuttoncolor != nil) {
1386+
[result setTitleColor:[self colorFromHexString:_browserOptions.navigationbuttoncolor] forState:UIControlStateNormal];
1387+
[result setTitleColor:[self colorFromHexString:_browserOptions.navigationbuttoncolor] forState:UIControlStateHighlighted];
1388+
}
14181389
}
14191390
[result addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
14201391

0 commit comments

Comments
 (0)