Skip to content

Commit 8bc568b

Browse files
authored
iOS: Cosmetic Changes
- Show Domain instead of URL - use appearance to keep navigationbar from being half black half custom colour - remove navigation buttons
1 parent cac3c4a commit 8bc568b

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/ios/CDVWKInAppBrowser.m

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ - (void)createViews
845845
self.spinner.userInteractionEnabled = NO;
846846
[self.spinner stopAnimating];
847847

848-
self.closeButton = [[UIBarButtonItem alloc] initWithTitle:@"닫기" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
848+
self.closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
849849
self.closeButton.enabled = YES;
850850
if (_browserOptions.navigationbuttoncolor != nil) { // Set button color if user sets it in options
851851
self.closeButton.tintColor = [self colorFromHexString:_browserOptions.navigationbuttoncolor];
@@ -962,7 +962,15 @@ - (id)createNavigationViewContoller {
962962
[nav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
963963

964964
if (_browserOptions.toolbarcolor != nil) {
965-
nav.navigationBar.barTintColor = [self colorFromHexString:_browserOptions.toolbarcolor];
965+
if (@available(iOS 13.0, *)) {
966+
UINavigationBarAppearance* navBarAppearance = [self.navigationController.navigationBar standardAppearance];
967+
[navBarAppearance configureWithOpaqueBackground];
968+
navBarAppearance.backgroundColor = [self colorFromHexString:_browserOptions.toolbarcolor];
969+
nav.navigationBar.standardAppearance = navBarAppearance;
970+
nav.navigationBar.scrollEdgeAppearance = navBarAppearance;
971+
} else {
972+
nav.navigationBar.barTintColor = [self colorFromHexString:_browserOptions.toolbarcolor];
973+
}
966974
}
967975
nav.modalPresentationStyle = self.modalPresentationStyle;
968976
nav.presentationController.delegate = self;
@@ -1234,7 +1242,16 @@ - (void) rePositionViews {
12341242
self.navigationController.navigationBar.shadowImage = image;
12351243
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
12361244
if (_browserOptions.toolbarcolor != nil) {
1237-
self.navigationController.navigationBar.barTintColor = [self colorFromHexString:_browserOptions.toolbarcolor];
1245+
if (@available(iOS 13.0, *)) {
1246+
UINavigationBarAppearance* navBarAppearance = [self.navigationController.navigationBar standardAppearance];
1247+
[navBarAppearance configureWithOpaqueBackground];
1248+
navBarAppearance.backgroundColor = [self colorFromHexString:_browserOptions.toolbarcolor];
1249+
self.navigationController.navigationBar.standardAppearance = navBarAppearance;
1250+
self.navigationController.navigationBar.scrollEdgeAppearance = navBarAppearance;
1251+
} else {
1252+
self.navigationController.navigationBar.barTintColor = [self colorFromHexString:_browserOptions.toolbarcolor];
1253+
}
1254+
12381255
}
12391256

12401257
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
@@ -1243,7 +1260,7 @@ - (void) rePositionViews {
12431260

12441261
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14], NSForegroundColorAttributeName: [UIColor colorWithWhite:1.0 alpha:0.45]};
12451262
self.navigationItem.leftBarButtonItems = @[self.closeButton];
1246-
self.navigationItem.rightBarButtonItems = @[self.shareButton, self.forwardButton, fixedSpaceButton, self.backButton];
1263+
self.navigationItem.rightBarButtonItems = @[self.shareButton];
12471264

12481265
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
12491266
label.textColor = [UIColor colorWithWhite:1.0 alpha:0.45];
@@ -1312,7 +1329,17 @@ - (void)webView:(WKWebView *)theWebView didFinishNavigation:(WKNavigation *)navi
13121329
[self.spinner stopAnimating];
13131330
//custom
13141331
UILabel *label = (UILabel *)self.navigationItem.titleView;
1315-
label.text = [self.currentURL absoluteString];
1332+
1333+
// Extract the domain from the URL
1334+
NSString *urlString = [self.currentURL absoluteString];
1335+
NSURL *url = [NSURL URLWithString:urlString];
1336+
NSString *domain = url.host;
1337+
1338+
// Remove "www." if it exists in the domain
1339+
domain = [domain stringByReplacingOccurrencesOfString:@"www." withString:@""];
1340+
1341+
// Set the domain as the text for the label
1342+
label.text = domain;
13161343
[label sizeToFit];
13171344

13181345
[self.navigationDelegate didFinishNavigation:theWebView];

0 commit comments

Comments
 (0)