diff --git a/lib/ios/RNNComponentPresenter.m b/lib/ios/RNNComponentPresenter.m index f267ab17115..c43095cc8bc 100644 --- a/lib/ios/RNNComponentPresenter.m +++ b/lib/ios/RNNComponentPresenter.m @@ -83,7 +83,9 @@ - (void)applyOptions:(RNNNavigationOptions *)options { backgroundColor:[options.topBar.searchBar.backgroundColor withDefault:nil] tintColor:[options.topBar.searchBar.tintColor - withDefault:nil]]; + withDefault:nil] + cancelText:[withDefault.topBar.searchBar.cancelText + withDefault:nil]]; } [_topBarTitlePresenter applyOptions:withDefault.topBar]; @@ -145,7 +147,9 @@ - (void)mergeOptions:(RNNNavigationOptions *)mergeOptions backgroundColor:[mergeOptions.topBar.searchBar.backgroundColor withDefault:nil] tintColor:[mergeOptions.topBar.searchBar.tintColor - withDefault:nil]]; + withDefault:nil] + cancelText:[withDefault.topBar.searchBar.cancelText + withDefault:nil]]; } else { [viewController setSearchBarVisible:NO]; } diff --git a/lib/ios/RNNSearchBarOptions.h b/lib/ios/RNNSearchBarOptions.h index bee30e91482..c571ced0570 100644 --- a/lib/ios/RNNSearchBarOptions.h +++ b/lib/ios/RNNSearchBarOptions.h @@ -10,5 +10,6 @@ @property(nonatomic, strong) Color *backgroundColor; @property(nonatomic, strong) Color *tintColor; @property(nonatomic, strong) Text *placeholder; +@property(nonatomic, strong) Text *cancelText; @end diff --git a/lib/ios/RNNSearchBarOptions.m b/lib/ios/RNNSearchBarOptions.m index 549db10fb0b..7eb32295bb7 100644 --- a/lib/ios/RNNSearchBarOptions.m +++ b/lib/ios/RNNSearchBarOptions.m @@ -13,6 +13,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.backgroundColor = [ColorParser parse:dict key:@"backgroundColor"]; self.tintColor = [ColorParser parse:dict key:@"tintColor"]; self.placeholder = [TextParser parse:dict key:@"placeholder"]; + self.cancelText = [TextParser parse:dict key:@"cancelText"]; return self; } @@ -33,6 +34,8 @@ - (void)mergeOptions:(RNNSearchBarOptions *)options { self.tintColor = options.tintColor; if (options.placeholder.hasValue) self.placeholder = options.placeholder; + if (options.cancelText.hasValue) + self.cancelText = options.cancelText; } @end diff --git a/lib/ios/UIViewController+RNNOptions.h b/lib/ios/UIViewController+RNNOptions.h index 0d8720d3ed0..490a3fda89e 100644 --- a/lib/ios/UIViewController+RNNOptions.h +++ b/lib/ios/UIViewController+RNNOptions.h @@ -14,7 +14,8 @@ hideOnScroll:(BOOL)searchBarHiddenWhenScrolling obscuresBackgroundDuringPresentation:(BOOL)obscuresBackgroundDuringPresentation backgroundColor:(nullable UIColor *)backgroundColor - tintColor:(nullable UIColor *)tintColor; + tintColor:(nullable UIColor *)tintColor + cancelText:(NSString *_Nullable)cancelText; - (void)setSearchBarHiddenWhenScrolling:(BOOL)searchBarHidden; diff --git a/lib/ios/UIViewController+RNNOptions.m b/lib/ios/UIViewController+RNNOptions.m index ee09cb5a56c..fc670ad4339 100644 --- a/lib/ios/UIViewController+RNNOptions.m +++ b/lib/ios/UIViewController+RNNOptions.m @@ -29,7 +29,8 @@ - (void)setSearchBarWithOptions:(NSString *)placeholder hideOnScroll:(BOOL)hideOnScroll obscuresBackgroundDuringPresentation:(BOOL)obscuresBackgroundDuringPresentation backgroundColor:(nullable UIColor *)backgroundColor - tintColor:(nullable UIColor *)tintColor { + tintColor:(nullable UIColor *)tintColor + cancelText:(NSString *)cancelText { if (!self.navigationItem.searchController) { UISearchController *search = [[UISearchController alloc] initWithSearchResultsController:nil]; @@ -41,6 +42,9 @@ - (void)setSearchBarWithOptions:(NSString *)placeholder if (placeholder) { search.searchBar.placeholder = placeholder; } + if (cancelText) { + [search.searchBar setValue:cancelText forKey:@"cancelButtonText"]; + } search.hidesNavigationBarDuringPresentation = hideTopBarOnFocus; search.searchBar.searchBarStyle = UISearchBarStyleProminent; search.searchBar.tintColor = tintColor; diff --git a/lib/src/interfaces/Options.ts b/lib/src/interfaces/Options.ts index 7f8cccfc64d..19695c29ff1 100644 --- a/lib/src/interfaces/Options.ts +++ b/lib/src/interfaces/Options.ts @@ -583,6 +583,7 @@ export interface OptionsSearchBar { backgroundColor?: Color; tintColor?: Color; placeholder?: string; + cancelText?: string; } export interface OptionsTopBar { diff --git a/playground/ios/NavigationTests/RNNSearchBarOptionsTest.m b/playground/ios/NavigationTests/RNNSearchBarOptionsTest.m index bb50d79c3f9..c46f439d2c1 100644 --- a/playground/ios/NavigationTests/RNNSearchBarOptionsTest.m +++ b/playground/ios/NavigationTests/RNNSearchBarOptionsTest.m @@ -15,7 +15,8 @@ - (void)testInitWithDict { @"obscuresBackgroundDuringPresentation" : @(1), @"backgroundColor" : @(0xff0000ff), @"tintColor" : @(0xff0000ff), - @"placeholder" : @"placeholder" + @"placeholder" : @"placeholder", + @"cancelText" : @"cancelText", }]; XCTAssertTrue(options.visible.get); @@ -25,6 +26,7 @@ - (void)testInitWithDict { XCTAssertTrue([options.backgroundColor.get isEqual:UIColor.blueColor]); XCTAssertTrue([options.tintColor.get isEqual:UIColor.blueColor]); XCTAssertTrue([options.placeholder.get isEqualToString:@"placeholder"]); + XCTAssertTrue([options.cancelText.get isEqualToString:@"cancelText"]); } - (void)testMergeOptions { @@ -35,7 +37,8 @@ - (void)testMergeOptions { @"obscuresBackgroundDuringPresentation" : @(1), @"backgroundColor" : @(0xff0000ff), @"tintColor" : @(0xff0000ff), - @"placeholder" : @"placeholder" + @"placeholder" : @"placeholder", + @"cancelText" : @"cancelText", }]; RNNSearchBarOptions *mergeOptions = [[RNNSearchBarOptions alloc] initWithDict:@{ @"visible" : @(0), @@ -44,7 +47,8 @@ - (void)testMergeOptions { @"obscuresBackgroundDuringPresentation" : @(0), @"backgroundColor" : @(0xff00ff00), @"tintColor" : @(0xff00ff00), - @"placeholder" : @"mergedPlaceholder" + @"placeholder" : @"mergedPlaceholder", + @"cancelText" : @"mergedCancelText", }]; [options mergeOptions:mergeOptions]; @@ -56,6 +60,7 @@ - (void)testMergeOptions { XCTAssertTrue([options.backgroundColor.get isEqual:UIColor.greenColor]); XCTAssertTrue([options.tintColor.get isEqual:UIColor.greenColor]); XCTAssertTrue([options.placeholder.get isEqualToString:@"mergedPlaceholder"]); + XCTAssertTrue([options.cancelText.get isEqualToString:@"mergedCancelText"]); } @end diff --git a/website/docs/api/topBar-searchBar.mdx b/website/docs/api/topBar-searchBar.mdx index ead162857cc..bb48b29089b 100644 --- a/website/docs/api/topBar-searchBar.mdx +++ b/website/docs/api/topBar-searchBar.mdx @@ -52,3 +52,9 @@ sidebar_label: Layout | Type | Required | Platform | Description | | ----------------------- | -------- | -------- | ------------------------------ | | string | No | iOS | The placeholder value in the UISearchBar. | + +## `cancelText` + +| Type | Required | Platform | Description | +| ----------------------- | -------- | -------- | ----------------------------------------------------- | +| string | No | iOS | The text value of "Cancel" button in the UISearchBar. |