'Close bottom sheet on pressing back button on android
I am using @gorhom/bottom-sheet library in react native expo and I would like to close the sheet when I press the back button on android, how can I achieve this?
Solution 1:[1]
Create a backHandler event in your useEffect and call the bottomSheetRef.current.close() method inside it:-
useEffect(() => {
const backAction = () => {
bottomSheetRef.current.close()
return true;
};
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction
);
return () => backHandler.remove();
}, []);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | this.arjun |
