react-native-bottom-sheet
react-native-bottom-sheet copied to clipboard
How to handle Android Hardware Back Button
Feature Request
1. I have tried this way and couple other options. but still not perfectly working. Sometimes it blocks to navigate back.
Why it is needed
- To Close the Open Bottom Sheet with button
Possible implementation
- Please check Code down Below
Code sample
const handleAndroidBackButton = useCallback(() => {
if (Platform.OS === 'android' && updateIndex >= 0) {
console.log(`updateIndex:`, updateIndex);
bottomSheetModalLayoutRef.current?.close();
setUpdateIndex(-1);
return true; // Consume the back press event
}
return false; // Allow default back press behavior if bottom sheet is closed
}, [updateIndex, bottomSheetModalLayoutRef]);
useEffect(() => {
const backHandlerSubscription = BackHandler.addEventListener(
'hardwareBackPress',
handleAndroidBackButton,
);
return () => {
backHandlerSubscription.remove();
};
}, [handleAndroidBackButton]);
@salahbm: hello! :wave:
This issue is being automatically closed because it does not follow the issue template.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.