feat: support hintTextColor on iOS search bar#4089
Conversation
There was a problem hiding this comment.
Pull request overview
Adds iOS support for the hintTextColor SearchBar option by applying it to the iOS search bar placeholder and keeping the placeholder string stable across hint color updates. This also updates the public types/spec so hintTextColor is no longer presented as Android-only.
Changes:
- Apply
hintTextColorto the iOSUISearchTextFieldplaceholder viaattributedPlaceholder. - Persist placeholder text in native (
_placeholder) so changing hint color doesn’t unintentionally change placeholder content. - Update TypeScript types/codegen spec to treat
hintTextColoras non-Android-only.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/types.tsx | Removes Android-only annotation from hintTextColor in SearchBarProps docs. |
| src/fabric/SearchBarNativeComponent.ts | Moves hintTextColor into the shared prop set (not under “Android only”). |
| ios/RNSSearchBar.mm | Implements setHintTextColor, stores placeholder, and updates Fabric + legacy prop export. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -60,6 +60,7 @@ export interface NativeProps extends ViewProps { | |||
| barTintColor?: ColorValue | undefined; | |||
| tintColor?: ColorValue | undefined; | |||
| textColor?: ColorValue | undefined; | |||
| hintTextColor?: ColorValue | undefined; | |||
There was a problem hiding this comment.
I'd move it above the comment.
| if (_hintTextColor != nil && _placeholder != nil) { | ||
| _controller.searchBar.searchTextField.attributedPlaceholder = | ||
| [[NSAttributedString alloc] initWithString:_placeholder attributes:@{NSForegroundColorAttributeName : _hintTextColor}]; | ||
| } else { | ||
| [_controller.searchBar setPlaceholder:_placeholder]; | ||
| } |
There was a problem hiding this comment.
Hi, @skrtdev. Thank you for the PR. I left some questions and suggestions.
I also think it would be nice to create a dedicated test for the new prop. For current stack we're using apps/src/tests/issue-tests directory. We can create Test4089.tsx there. We should check different search bar placements and placeholder x hintTextColor configurations, including empty values and restoring default values in runtime.
Also, the title of the PR start with feat: as we're adding new functionality to iOS implementation rather than fixing something.
| @@ -60,6 +60,7 @@ export interface NativeProps extends ViewProps { | |||
| barTintColor?: ColorValue | undefined; | |||
| tintColor?: ColorValue | undefined; | |||
| textColor?: ColorValue | undefined; | |||
| hintTextColor?: ColorValue | undefined; | |||
There was a problem hiding this comment.
I'd move it above the comment.
| if (_hintTextColor != nil && _placeholder != nil) { | ||
| _controller.searchBar.searchTextField.attributedPlaceholder = | ||
| [[NSAttributedString alloc] initWithString:_placeholder attributes:@{NSForegroundColorAttributeName : _hintTextColor}]; | ||
| } else { | ||
| [_controller.searchBar setPlaceholder:_placeholder]; | ||
| } |
|
|
||
| - (void)setHintTextColor:(UIColor *)hintTextColor | ||
| { | ||
| #if !TARGET_OS_TV |
There was a problem hiding this comment.
Why do we need tvOS guard here?
| { | ||
| #if !TARGET_OS_TV | ||
| _hintTextColor = hintTextColor; | ||
| [self setPlaceholder:_placeholder]; |
There was a problem hiding this comment.
I wouldn't call the setter here. I suggest that we keep the setters simple (just set the _placeholder/_hintTextColor properties, if any of them we're changed (oldScreenProps.XXX != newScreenProps.XXX), set new local flag in updateProps to YES) and at the end of updateProps if props were invalidated, let's call new method like updatePlaceholder that will check both props and apply the placeholder/attributedPlaceholder accordingly.
| /** | ||
| * The search hint text color | ||
| * | ||
| * @plaform android |
There was a problem hiding this comment.
We should also remove (Android only) from GUIDE_FOR_LIBRARY_AUTHORS.md
| _controller.searchBar.searchTextField.attributedPlaceholder = | ||
| [[NSAttributedString alloc] initWithString:_placeholder attributes:@{NSForegroundColorAttributeName : _hintTextColor}]; | ||
| } else { | ||
| [_controller.searchBar setPlaceholder:_placeholder]; |
There was a problem hiding this comment.
If the user provides only _hintTextColor and _placeholder remains nil, we get empty search bar instead of the default text. We need to fix this.
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-05-25.at.11.25.00.mov
| _placeholder = placeholder; | ||
|
|
||
| if (_hintTextColor != nil && _placeholder != nil) { | ||
| _controller.searchBar.searchTextField.attributedPlaceholder = |
There was a problem hiding this comment.
It seems like it doesn't work on iOS 26 for new search bar at the bottom. We should investigate why & if we can't fix it, describe the limitations in the prop docs.
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-05-25.at.11.24.44.mov
|
You're right: it doesn't work on iOS 26 for new search bar at the bottom. I also noticed that even on non-bottom search bar, styling is ignored when the search bar is focused. It seems like we can't fix it. I also think there's a bug after the first focus. 2nd and subsequent focuses dont fully focus the search bar. The user can type but it's not the native focused state. I'll investigate more on that and eventually open a separate PR / issue. |
There was a problem hiding this comment.
The search bar doesn't really support runtime changes for e.g. placement so we should probably have configuration on root screen and then apply the config on new pushed screen with the config.
| } | ||
| } | ||
| #endif /* Check for iOS 26.0 */ | ||
| [searchBar updatePlaceholder]; |
There was a problem hiding this comment.
I'm not sure if we need this. We will be informed about any changes in updateProps right?
| } | ||
|
|
||
| RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString) | ||
| RCT_CUSTOM_VIEW_PROPERTY(placeholder, NSString, RNSSearchBar) |
There was a problem hiding this comment.
We've dropped support for Paper so these are not necessary. I think recently PR removing those landed on main. We should merge/rebase onto current main.
Summary
hintTextColorto the iOS search bar placeholderhintTextColoris no longer marked Android-onlyTest plan
git diff --checkclang-formatand full package checks were not run locally because this environment does not have the repo toolchain installed.