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 2 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: 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
@@ -1,4 +1,4 @@
import React, {useCallback} from 'react';
import React, {useCallback, useEffect} from 'react';
import {View} from 'react-native';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand All @@ -18,6 +18,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as Modal from '@userActions/Modal';
import * as PersonalDetails from '@userActions/PersonalDetails';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -36,6 +37,10 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useOnboardingLayout();

useEffect(() => {
Modal.setDisableDismissOnEscape(true);
}, []);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it works but I think it's not really good. We set on/off for this prop disableDismissOnEscape on 2 components, thus in order to keep it working:

  • We need to ensure their order
  • And if we replace OnboardingPurpose component with another component, we need to remember to copy that setter as well.

So I think they're not independent. What do you think if we set it on on mount, and off on unmount for each component? We can wrap it into a custom hook and use it on every modal that needs to disable dismiss on ESC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @hoangzinh this is a bit fragile logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I understand what you mean, I'll rework it accordingly so it applies more properly here.

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

Expand Down
2 changes: 2 additions & 0 deletions src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import * as Modal from '@userActions/Modal';
import * as Report from '@userActions/Report';
import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -80,6 +81,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, on
return;
}

Modal.setDisableDismissOnEscape(false);
Report.completeEngagementModal(CONST.ONBOARDING_CONCIERGE[selectedPurpose], selectedPurpose);

Navigation.dismissModal();
Expand Down
4 changes: 4 additions & 0 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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