-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56203 from layacat/fix-back-press-search-screen
Fix: Handle Back press event for search header on multiple screens
- Loading branch information
Showing
13 changed files
with
243 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
import {useFocusEffect} from '@react-navigation/native'; | ||
import {useCallback} from 'react'; | ||
import {BackHandler} from 'react-native'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type UseSearchBackPress from './types'; | ||
|
||
const useSearchBackPress: UseSearchBackPress = ({onClearSelection, onNavigationCallBack}) => { | ||
const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE); | ||
useFocusEffect( | ||
useCallback(() => { | ||
const onBackPress = () => { | ||
if (selectionMode?.isEnabled) { | ||
onClearSelection(); | ||
turnOffMobileSelectionMode(); | ||
return true; | ||
} | ||
onNavigationCallBack(); | ||
return false; | ||
}; | ||
const backHandler = BackHandler.addEventListener('hardwareBackPress', onBackPress); | ||
return () => backHandler.remove(); | ||
}, [selectionMode?.isEnabled, onClearSelection, onNavigationCallBack]), | ||
); | ||
}; | ||
|
||
export default useSearchBackPress; |
This file contains 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,6 @@ | ||
import type UseSearchBackPress from './types'; | ||
|
||
// the back press event is only supported on Android native | ||
const useSearchBackPress: UseSearchBackPress = () => {}; | ||
|
||
export default useSearchBackPress; |
This file contains 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,8 @@ | ||
type UseSearchBackPressParams = { | ||
onClearSelection: () => void; | ||
onNavigationCallBack: () => void; | ||
}; | ||
|
||
type UseSearchBackPress = (params: UseSearchBackPressParams) => void; | ||
|
||
export default UseSearchBackPress; |
This file contains 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.