Skip to content

feat: support hintTextColor on iOS search bar#4089

Open
skrtdev wants to merge 6 commits into
software-mansion:mainfrom
skrtdev:ios-searchbar-hint-text-color
Open

feat: support hintTextColor on iOS search bar#4089
skrtdev wants to merge 6 commits into
software-mansion:mainfrom
skrtdev:ios-searchbar-hint-text-color

Conversation

@skrtdev
Copy link
Copy Markdown

@skrtdev skrtdev commented May 23, 2026

Summary

  • apply hintTextColor to the iOS search bar placeholder
  • keep the placeholder string stable when the hint color changes
  • update search bar types/docs so hintTextColor is no longer marked Android-only

Test plan

  • git diff --check

clang-format and full package checks were not run locally because this environment does not have the repo toolchain installed.

Copilot AI review requested due to automatic review settings May 23, 2026 20:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hintTextColor to the iOS UISearchTextField placeholder via attributedPlaceholder.
  • Persist placeholder text in native (_placeholder) so changing hint color doesn’t unintentionally change placeholder content.
  • Update TypeScript types/codegen spec to treat hintTextColor as 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.

Comment thread src/fabric/SearchBarNativeComponent.ts Outdated
Comment on lines +59 to +63
@@ -60,6 +60,7 @@ export interface NativeProps extends ViewProps {
barTintColor?: ColorValue | undefined;
tintColor?: ColorValue | undefined;
textColor?: ColorValue | undefined;
hintTextColor?: ColorValue | undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move it above the comment.

Comment thread ios/RNSSearchBar.mm Outdated
Comment on lines +211 to +216
if (_hintTextColor != nil && _placeholder != nil) {
_controller.searchBar.searchTextField.attributedPlaceholder =
[[NSAttributedString alloc] initWithString:_placeholder attributes:@{NSForegroundColorAttributeName : _hintTextColor}];
} else {
[_controller.searchBar setPlaceholder:_placeholder];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Copy link
Copy Markdown
Contributor

@kligarski kligarski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/fabric/SearchBarNativeComponent.ts Outdated
Comment on lines +59 to +63
@@ -60,6 +60,7 @@ export interface NativeProps extends ViewProps {
barTintColor?: ColorValue | undefined;
tintColor?: ColorValue | undefined;
textColor?: ColorValue | undefined;
hintTextColor?: ColorValue | undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move it above the comment.

Comment thread ios/RNSSearchBar.mm Outdated
Comment on lines +211 to +216
if (_hintTextColor != nil && _placeholder != nil) {
_controller.searchBar.searchTextField.attributedPlaceholder =
[[NSAttributedString alloc] initWithString:_placeholder attributes:@{NSForegroundColorAttributeName : _hintTextColor}];
} else {
[_controller.searchBar setPlaceholder:_placeholder];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Comment thread ios/RNSSearchBar.mm Outdated

- (void)setHintTextColor:(UIColor *)hintTextColor
{
#if !TARGET_OS_TV
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need tvOS guard here?

Comment thread ios/RNSSearchBar.mm Outdated
{
#if !TARGET_OS_TV
_hintTextColor = hintTextColor;
[self setPlaceholder:_placeholder];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/types.tsx
/**
* The search hint text color
*
* @plaform android
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also remove (Android only) from GUIDE_FOR_LIBRARY_AUTHORS.md

Comment thread ios/RNSSearchBar.mm Outdated
_controller.searchBar.searchTextField.attributedPlaceholder =
[[NSAttributedString alloc] initWithString:_placeholder attributes:@{NSForegroundColorAttributeName : _hintTextColor}];
} else {
[_controller.searchBar setPlaceholder:_placeholder];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread ios/RNSSearchBar.mm
_placeholder = placeholder;

if (_hintTextColor != nil && _placeholder != nil) {
_controller.searchBar.searchTextField.attributedPlaceholder =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@skrtdev skrtdev changed the title fix: support hintTextColor on iOS search bar feat: support hintTextColor on iOS search bar May 25, 2026
@skrtdev
Copy link
Copy Markdown
Author

skrtdev commented May 25, 2026

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need this. We will be informed about any changes in updateProps right?

Comment thread ios/RNSSearchBar.mm
}

RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
RCT_CUSTOM_VIEW_PROPERTY(placeholder, NSString, RNSSearchBar)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants