-
-
Notifications
You must be signed in to change notification settings - Fork 575
feat(Android): Expose configuration for showAsAction with collapse #3009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
private fun updateToolbarMenu(menu: Menu) { | ||
menu.clear() | ||
if (shouldShowSearchBar()) { | ||
locateSearchBarSubviewInConfig()?.let { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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'> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
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. |
Description
Resolves #2744
We have hardcoded
MenuItem.showAsAction
toSHOW_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
, wheredefault === always
Currently, no other SHOW_AS_ACTION_ enum is supported
show-as-action.mov
Test code and steps to reproduce
See
Test2744