-
-
Notifications
You must be signed in to change notification settings - Fork 617
fix(iOS): prevent search bar from reopening keyboard on header button press #3676
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
Open
just1and0
wants to merge
1
commit into
software-mansion:main
Choose a base branch
from
just1and0:fix/ios-search-bar-keyboard-reopen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
apps/src/tests/issue-tests/TestSearchBarKeyboardReopen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import React from 'react'; | ||
| import { NavigationContainer, ParamListBase } from '@react-navigation/native'; | ||
| import { | ||
| NativeStackNavigationProp, | ||
| createNativeStackNavigator, | ||
| } from '@react-navigation/native-stack'; | ||
| import { Alert, Button, ScrollView, Text, View } from 'react-native'; | ||
| import { ListItem } from '../../shared'; | ||
|
|
||
| type StackRouteParamList = { | ||
| Home: undefined; | ||
| Second: undefined; | ||
| }; | ||
|
|
||
| type NavigationProp<ParamList extends ParamListBase> = { | ||
| navigation: NativeStackNavigationProp<ParamList>; | ||
| }; | ||
|
|
||
| type StackNavigationProp = NavigationProp<StackRouteParamList>; | ||
|
|
||
| const Stack = createNativeStackNavigator<StackRouteParamList>(); | ||
|
|
||
| const items = Array.from({ length: 20 }, (_, i) => `Item ${i + 1}`); | ||
|
|
||
| function Second({}: StackNavigationProp) { | ||
| return ( | ||
| <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
| <Text>Second screen</Text> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function Home({ navigation }: StackNavigationProp) { | ||
| const [searchQuery, setSearchQuery] = React.useState(''); | ||
|
|
||
| React.useLayoutEffect(() => { | ||
| navigation.setOptions({ | ||
| headerSearchBarOptions: { | ||
| placement: 'stacked', | ||
| hideWhenScrolling: false, | ||
| onChangeText: event => setSearchQuery(event.nativeEvent.text), | ||
| }, | ||
| headerRight: () => ( | ||
| <Button | ||
| title="Menu" | ||
| onPress={() => Alert.alert('Menu', 'Header button pressed')} | ||
| testID="home-header-right-button" | ||
| /> | ||
| ), | ||
| }); | ||
| }, [navigation]); | ||
|
|
||
| return ( | ||
| <View style={{ flex: 1 }}> | ||
| <ScrollView | ||
| contentInsetAdjustmentBehavior="automatic" | ||
| contentContainerStyle={{ marginTop: 15 }}> | ||
| <Text style={{ padding: 15, color: '#666', lineHeight: 22 }}> | ||
| Steps to reproduce:{'\n'} | ||
| 1. Tap the search bar to focus it{'\n'} | ||
| 2. Dismiss the keyboard (tap Cancel or tap away){'\n'} | ||
| 3. Tap the "Menu" button in the header{'\n'} | ||
| 4. Bug: The keyboard opens again instead of just triggering the button | ||
| </Text> | ||
| <Button | ||
| title="Open Second" | ||
| onPress={() => navigation.navigate('Second')} | ||
| testID="home-button-open-second" | ||
| /> | ||
| {items | ||
| .filter( | ||
| name => | ||
| searchQuery === '' || | ||
| name.toLowerCase().includes(searchQuery.toLowerCase()), | ||
| ) | ||
| .map(name => ( | ||
| <ListItem key={name} title={name} onPress={() => {}} /> | ||
| ))} | ||
| </ScrollView> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <NavigationContainer> | ||
| <Stack.Navigator> | ||
| <Stack.Screen name="Home" component={Home} /> | ||
| <Stack.Screen name="Second" component={Second} /> | ||
| </Stack.Navigator> | ||
| </NavigationContainer> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The description in the comment says "4. Bug: The keyboard opens again instead of just triggering the button" but this is describing the bug that was fixed, not the current expected behavior. Since this is a test file documenting the fix, the comment should clarify that this was the previous buggy behavior, or update it to describe the expected behavior after the fix (keyboard should NOT reopen).