Skip to content

Commit 5cf7c2d

Browse files
GitToTheHubCopilot
andauthored
feat(ios): use UIBarButtonSystemItemClose since iOS 26 (#1138)
- Since iOS 13 it's possible to use `UIBarButtonSystemItemClose` instead of `UIBarButtonSystemItemDone` which correspond perfectly to a close button. Since `UIBarButtonSystemItemClose` looks akward on iOS 18 and older, because an X inside a round button is shown, instead of a text, the close button is only applied since iOS 26. Co-authored-by: Copilot <copilot@github.com>
1 parent 42e12dd commit 5cf7c2d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/ios/CDVWKInAppBrowser.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Licensed to the Apache Software Foundation (ASF) under one
3838

3939
#define IAB_BRIDGE_NAME @"cordova_iab"
4040

41+
#define kCloseButtonSystemItem (@available(iOS 26.0, *) ? UIBarButtonSystemItemClose : UIBarButtonSystemItemDone)
42+
4143
#pragma mark CDVWKInAppBrowser
4244

4345
@implementation CDVWKInAppBrowser
@@ -811,7 +813,9 @@ - (void)createViews
811813

812814
// NOTE: On iOS 26 using `UIBarButtonItem initWithBarButtonSystemItem:` gives constraint warnings,
813815
// which is a known UIKit bug.
814-
self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
816+
self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:kCloseButtonSystemItem
817+
target:self
818+
action:@selector(close)];
815819
self.closeButton.enabled = YES;
816820

817821
UIBarButtonItem *flexibleSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
@@ -1014,11 +1018,11 @@ - (void)setWebViewFrame:(CGRect)frame
10141018

10151019
- (void)setCloseButtonTitle:(NSString *)title withColor:(NSString *)colorString atIndex:(int)buttonIndex
10161020
{
1017-
// The advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically
1018-
// 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.)
1021+
// The system Close/Done button title is localized automatically.
1022+
// If a custom caption is provided, create a title-based button instead.
10191023
self.closeButton = nil;
1020-
// Initialize with title if title is set, otherwise the title will be 'Done' localized.
1021-
self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
1024+
// Initialize with title if set, otherwise use the system-localized Close/Done item.
1025+
self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:kCloseButtonSystemItem target:self action:@selector(close)];
10221026
self.closeButton.enabled = YES;
10231027
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default.
10241028
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];

0 commit comments

Comments
 (0)