Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Change name of focus and blur events to searchFocus and searchBl…
…ur (#2154) ## Description Right now, while trying to use search bar on new architecture, iOS throws an error, that `topFocus` event cannot both direct and bubbling. That's mainly because `RNSSearchBar` component extends from `View`, which already has `topFocus` event registered. This PR changes the naming of this event (along with `topBlur`, to keep compliance of both behaviours) to `topSearchFocus` and `topSearchBlur`. Fixes react-navigation/react-navigation#11928. ## Changes - Changed topFocus and topBlur event to topSearchFocus and topSearchBlur, - Added type that renames onFocus and onBlur props inside SearchBar native component (to don't introduce breaking change). ## Screenshots / GIFs ### Before https://github.com/software-mansion/react-native-screens/assets/23281839/492a5e96-feaa-4107-ab3f-e0a3e1237fc3 ### After https://github.com/software-mansion/react-native-screens/assets/23281839/2cbce030-3844-43e4-bf3b-582ca82c5603 ## Test code and steps to reproduce You can test `Test758.tsx` test, along with Example -> Search bar to test behaviour of the events on search bar. Eventually, you can use snippet below, that has been enhanced by adding console.logs on every search bar event. <details> <summary>Enhanced test</summary> ```tsx /* eslint-disable react-hooks/exhaustive-deps */ import * as React from 'react'; import { Button, NativeSyntheticEvent, ScrollView } from 'react-native'; import { NavigationContainer, NavigationProp, ParamListBase, } from '@react-navigation/native'; import { createNativeStackNavigator, NativeStackScreenProps, } from '@react-navigation/native-stack'; import { SearchBarProps } from 'react-native-screens'; const AppStack = createNativeStackNavigator(); export default function App(): JSX.Element { return ( <NavigationContainer> <AppStack.Navigator screenOptions={{ headerLargeTitle: true, headerTransparent: false, }}> <AppStack.Screen name="First" component={First} /> <AppStack.Screen name="Second" component={Second} /> </AppStack.Navigator> </NavigationContainer> ); } function First({ navigation }: NativeStackScreenProps<ParamListBase>) { React.useLayoutEffect(() => { navigation.setOptions({ headerSearchBarOptions: searchBarOptions, }); }, [navigation]); const [search, setSearch] = React.useState(''); const searchBarOptions: SearchBarProps = { barTintColor: 'powderblue', tintColor: 'red', textColor: 'red', hideWhenScrolling: true, obscureBackground: false, hideNavigationBar: false, autoCapitalize: 'sentences', placeholder: 'Some text', cancelButtonText: 'Some text', onChangeText: (e: NativeSyntheticEvent<{ text: string }>) => { setSearch(e.nativeEvent.text); console.warn('Search text:', e.nativeEvent.text); }, onCancelButtonPress: () => console.warn('Cancel button pressed'), onSearchButtonPress: () => console.warn('Search button pressed'), onFocus: () => console.warn('onFocus event'), onBlur: () => console.warn('onBlur event'), onOpen: () => console.warn('onOpen event'), onClose: () => console.warn('onClose event'), }; const items = [ 'Apples', 'Pie', 'Juice', 'Cake', 'Nuggets', 'Some', 'Other', 'Stuff', 'To', 'Fill', 'The', 'Scrolling', 'Space', ]; return ( <ScrollView contentInsetAdjustmentBehavior="automatic" keyboardDismissMode="on-drag"> <Button title="Tap me for second screen" onPress={() => navigation.navigate('Second')} /> {items .filter(item => item.toLowerCase().indexOf(search.toLowerCase()) !== -1) .map(item => ( <Button title={item} key={item} onPress={() => { console.warn(`${item} clicked`); }} /> ))} </ScrollView> ); } function Second({ navigation }: { navigation: NavigationProp<ParamListBase> }) { return ( <ScrollView contentInsetAdjustmentBehavior="automatic"> <Button title="Tap me for first screen" onPress={() => navigation.navigate('First')} /> </ScrollView> ); } ``` </details> ## Checklist - [X] Included code example that can be used to test this change - [X] Updated TS types - [X] Updated documentation: <!-- For adding new props to native-stack --> - [X] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx - [X] Ensured that CI passes --------- Co-authored-by: Kacper Kafara <kacper.kafara@swmansion.com>
- Loading branch information