Skip to content

Commit

Permalink
clear useLockModal for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrebam committed Feb 8, 2024
1 parent 313e267 commit eb1674a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/example/src/hooks/useLockModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ interface UseLockProps {

// This hook is used to lock the spatial navigation of parent navigator when a modal is open
// and to prevent the user from closing the modal by pressing the back button

export const useLockModal = ({ isModalVisible, setIsModalVisible }: UseLockProps) => {
// Locks the parent navigator when the modal is open and unlocks it when it's closed
useLockParentSpatialNavigator(isModalVisible);
usePreventNavigationGoBack(isModalVisible, setIsModalVisible);
};

const useLockParentSpatialNavigator = (isModalVisible: boolean) => {
const { lock, unlock } = useLockSpatialNavigation();
useEffect(() => {
if (isModalVisible) {
Expand All @@ -21,8 +24,12 @@ export const useLockModal = ({ isModalVisible, setIsModalVisible }: UseLockProps
};
}
}, [isModalVisible, lock, unlock]);
};

// Prevents the user from closing the modal by pressing the back button
const usePreventNavigationGoBack = (
isModalVisible: boolean,
setIsModalVisible: (isVisible: boolean) => void,
) => {
const navigation = useNavigation();
useEffect(() => {
if (isModalVisible) {
Expand Down

0 comments on commit eb1674a

Please sign in to comment.