diff --git a/providers/GlobalModalProvider.tsx b/providers/GlobalModalProvider.tsx index 76ced95a..c2268899 100644 --- a/providers/GlobalModalProvider.tsx +++ b/providers/GlobalModalProvider.tsx @@ -5,10 +5,13 @@ import { type ReactNode, useCallback, useContext, + useEffect, useRef, useState, } from "react"; +import { BackHandler, Platform } from "react-native"; + interface ModalOptions { enableDynamicSizing?: boolean; snapPoints?: (string | number)[]; @@ -73,6 +76,25 @@ export const GlobalModalProvider: React.FC = ({ }); }, []); + useEffect(() => { + if (Platform.OS !== "android") return; + + const onBackPress = () => { + if (isVisible) { + hideModal(); + return true; + } + return false; + }; + + const subscription = BackHandler.addEventListener( + "hardwareBackPress", + onBackPress, + ); + + return () => subscription.remove(); + }, [isVisible, hideModal]); + const value = { showModal, hideModal,