Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Onboarding - Modal can be dismissed by ESC key #39927

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/hooks/useDisableModalDismissOnEscape.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {useEffect} from 'react';
import * as Modal from '@userActions/Modal';

export default function useDisableModalDismissOnEscape() {
useEffect(() => {
Modal.setDisableDismissOnEscape(true);
return () => Modal.setDisableDismissOnEscape(false);
}, []);
}
9 changes: 8 additions & 1 deletion src/libs/actions/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ function setModalVisibility(isVisible: boolean) {
Onyx.merge(ONYXKEYS.MODAL, {isVisible});
}

/**
* Allows other parts of the app to set whether modals should be dismissable using the Escape key
*/
function setDisableDismissOnEscape(disableDismissOnEscape: boolean) {
Onyx.merge(ONYXKEYS.MODAL, {disableDismissOnEscape});
}

/**
* Allows other parts of app to know that an alert modal is about to open.
* This will trigger as soon as a modal is opened but not yet visible while animation is running.
Expand All @@ -78,4 +85,4 @@ function willAlertModalBecomeVisible(isVisible: boolean, isPopover = false) {
Onyx.merge(ONYXKEYS.MODAL, {willAlertModalBecomeVisible: isVisible, isPopover});
}

export {setCloseModal, close, onModalDidClose, setModalVisibility, willAlertModalBecomeVisible, closeTop};
export {setCloseModal, close, onModalDidClose, setModalVisibility, willAlertModalBecomeVisible, setDisableDismissOnEscape, closeTop};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Text from '@components/Text';
import TextInput from '@components/TextInput';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
import useDisableModalDismissOnEscape from '@hooks/useDisableModalDismissOnEscape';
import useLocalize from '@hooks/useLocalize';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useTheme from '@hooks/useTheme';
Expand All @@ -36,6 +37,8 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useOnboardingLayout();

useDisableModalDismissOnEscape();

const saveAndNavigate = useCallback((values: FormOnyxValues<'onboardingPersonalDetailsForm'>) => {
PersonalDetails.updateDisplayName(values.firstName.trim(), values.lastName.trim());

Expand Down
3 changes: 3 additions & 0 deletions src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MenuItemList from '@components/MenuItemList';
import OfflineIndicator from '@components/OfflineIndicator';
import SafeAreaConsumer from '@components/SafeAreaConsumer';
import Text from '@components/Text';
import useDisableModalDismissOnEscape from '@hooks/useDisableModalDismissOnEscape';
import useLocalize from '@hooks/useLocalize';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -47,6 +48,8 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, on
const [error, setError] = useState(false);
const theme = useTheme();

useDisableModalDismissOnEscape();

const PurposeFooterInstance = <OfflineIndicator />;

useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/home/sidebar/SidebarLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priority
return;
}

if (modal.current.disableDismissOnEscape) {
return;
}

Navigation.dismissModal();
},
shortcutConfig.descriptionKey,
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ type Modal = {
/** Indicates when an Alert modal is about to be visible */
willAlertModalBecomeVisible?: boolean;

/** Indicates whether the modal should be dismissable using the ESCAPE key */
disableDismissOnEscape?: boolean;

/** Indicates if there is a modal currently visible or not */
isVisible?: boolean;

Expand Down
Loading