Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNNSearchBarOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions lib/ios/RNNSearchBarOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
3 changes: 2 additions & 1 deletion lib/ios/UIViewController+RNNOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion lib/ios/UIViewController+RNNOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export interface OptionsSearchBar {
backgroundColor?: Color;
tintColor?: Color;
placeholder?: string;
cancelText?: string;
}

export interface OptionsTopBar {
Expand Down
11 changes: 8 additions & 3 deletions playground/ios/NavigationTests/RNNSearchBarOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ - (void)testInitWithDict {
@"obscuresBackgroundDuringPresentation" : @(1),
@"backgroundColor" : @(0xff0000ff),
@"tintColor" : @(0xff0000ff),
@"placeholder" : @"placeholder"
@"placeholder" : @"placeholder",
@"cancelText" : @"cancelText",
}];

XCTAssertTrue(options.visible.get);
Expand All @@ -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 {
Expand All @@ -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),
Expand All @@ -44,7 +47,8 @@ - (void)testMergeOptions {
@"obscuresBackgroundDuringPresentation" : @(0),
@"backgroundColor" : @(0xff00ff00),
@"tintColor" : @(0xff00ff00),
@"placeholder" : @"mergedPlaceholder"
@"placeholder" : @"mergedPlaceholder",
@"cancelText" : @"mergedCancelText",
}];

[options mergeOptions:mergeOptions];
Expand All @@ -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
6 changes: 6 additions & 0 deletions website/docs/api/topBar-searchBar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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. |