Skip to content

Conversation

kmichalikk
Copy link
Collaborator

Description

Resolves #2744

We have hardcoded MenuItem.showAsAction to SHOW_AS_ACTION_ALWAYS to have search icon always visible on toolbar. This setting also indirectly controls the behavior of Up button; OR-ing it with SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW makes the Up button collapse the searchbar first, then pop the screen on the second click.

Changes

Added headerSearchBarActions.showAsAction option for Screen with possible values: default, always, collapse, where default === always

Currently, no other SHOW_AS_ACTION_ enum is supported

show-as-action.mov

Test code and steps to reproduce

See Test2744

}

private fun updateToolbarMenu(menu: Menu) {
menu.clear()
if (shouldShowSearchBar()) {
locateSearchBarSubviewInConfig()?.let {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

shouldShowSearchBar() was effectively true when config for type==SEARCH_BAR existed, so this refactor should not change the behaviour

Copy link
Member

Choose a reason for hiding this comment

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

This is ok, thanks for the note.

@kmichalikk kmichalikk requested a review from kkafar July 17, 2025 10:14
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

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

I have few questions regarding the structure & changes. The code itself looks really nice!

type StackNavigationProp = NavigationProp<StackRouteParamList>;

const SearchAlways = ({navigation}: StackNavigationProp) => {
return <ScrollView contentInsetAdjustmentBehavior='automatic'>
Copy link
Member

Choose a reason for hiding this comment

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

Let's use braces () - this will make code more maintainable, if some additional logic will be needed, also it'll stick to the pattern we use everywhere else.

Another thing - in general I prefer (and try to enforce) usage of regular functions over arrow functions, due to symbol hoisting. Therefore let's rewrite this a bit.

@@ -733,6 +734,16 @@ export interface SearchBarProps {
* @platform ios
*/
tintColor?: ColorValue;
/**
* @platform android
Copy link
Member

Choose a reason for hiding this comment

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

This annotation should be placed in the end of the comment block. No technical reason, just to keep the convention.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this additional resource?

actionView = searchView
setIcon(R.drawable.ic_action_search)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to set this icon manually?

val currentContext = context
if (searchView == null && currentContext != null) {
val newSearchView = CustomSearchView(currentContext, this)
searchView = newSearchView
onSearchViewCreate?.invoke(newSearchView)
}
menu.add("").apply {
setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
menu.add("Search").apply {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to change that?

Copy link
Member

Choose a reason for hiding this comment

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

Where is this title used?

}

private fun updateToolbarMenu(menu: Menu) {
menu.clear()
if (shouldShowSearchBar()) {
locateSearchBarSubviewInConfig()?.let {
Copy link
Member

Choose a reason for hiding this comment

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

This is ok, thanks for the note.

@@ -23,6 +23,8 @@ type SearchBarPlacement = 'automatic' | 'inline' | 'stacked';

type AutoCapitalizeType = 'none' | 'words' | 'sentences' | 'characters';

type SearchShowAsAction = 'default' | 'always' | 'collapse';
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need default case? Couldn't we just use always if the user does not set the value? Does it give us any advantage over direct approach?

@kkafar
Copy link
Member

kkafar commented Jul 21, 2025

Note

Note for future us.

On hold due to low prio + issues with existing code.

There already exists code responsible for that interaction (preventing immediate pop when search bar is focused), however it stopped to work at some time. We need to figure out why it has stopped to work & fix it.

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.

Android: Up/back on search should cancel search, not navigate
2 participants