Skip to content

Commit

Permalink
Merge pull request #43041 from ntdiary/fix-modal-keyboard
Browse files Browse the repository at this point in the history
enable new focus management for waypoint and report field page
  • Loading branch information
Julesssss authored Jun 7, 2024
2 parents 02bd068 + 55e84c0 commit 0460aec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/components/ConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CONST from '@src/CONST';
import type IconAsset from '@src/types/utils/IconAsset';
import ConfirmContent from './ConfirmContent';
import Modal from './Modal';
import type BaseModalProps from './Modal/types';

type ConfirmModalProps = {
/** Title of the modal */
Expand Down Expand Up @@ -74,6 +75,9 @@ type ConfirmModalProps = {
* We are attempting to migrate to a new refocus manager, adding this property for gradual migration.
* */
shouldEnableNewFocusManagement?: boolean;

/** How to re-focus after the modal is dismissed */
restoreFocusType?: BaseModalProps['restoreFocusType'];
};

function ConfirmModal({
Expand All @@ -98,6 +102,7 @@ function ConfirmModal({
onConfirm,
image,
shouldEnableNewFocusManagement,
restoreFocusType,
}: ConfirmModalProps) {
const {isSmallScreenWidth} = useResponsiveLayout();
const styles = useThemeStyles();
Expand All @@ -112,6 +117,7 @@ function ConfirmModal({
type={isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CONFIRM}
innerContainerStyle={image ? styles.pt0 : {}}
shouldEnableNewFocusManagement={shouldEnableNewFocusManagement}
restoreFocusType={restoreFocusType}
>
<ConfirmContent
title={title}
Expand Down
1 change: 1 addition & 0 deletions src/pages/EditReportFieldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function EditReportFieldPage({route, policy, report}: EditReportFieldPageProps)
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
danger
shouldEnableNewFocusManagement
/>

{(reportField.type === 'text' || isReportFieldTitle) && (
Expand Down
10 changes: 9 additions & 1 deletion src/pages/iou/request/step/IOURequestStepWaypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import InputWrapperWithRef from '@components/Form/InputWrapper';
import type {FormOnyxValues} from '@components/Form/types';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import type BaseModalProps from '@components/Modal/types';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useLocationBias from '@hooks/useLocationBias';
Expand Down Expand Up @@ -58,6 +59,7 @@ function IOURequestStepWaypoint({
const styles = useThemeStyles();
const {windowWidth} = useWindowDimensions();
const [isDeleteStopModalOpen, setIsDeleteStopModalOpen] = useState(false);
const [restoreFocusType, setRestoreFocusType] = useState<BaseModalProps['restoreFocusType']>();
const navigation = useNavigation();
const isFocused = navigation.isFocused();
const {translate} = useLocalize();
Expand Down Expand Up @@ -130,6 +132,7 @@ function IOURequestStepWaypoint({

const deleteStopAndHideModal = () => {
Transaction.removeWaypoint(transaction, pageIndex, action === CONST.IOU.ACTION.CREATE);
setRestoreFocusType(CONST.MODAL.RESTORE_FOCUS_TYPE.DELETE);
setIsDeleteStopModalOpen(false);
Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(action, iouType, transactionID, reportID));
};
Expand Down Expand Up @@ -172,7 +175,10 @@ function IOURequestStepWaypoint({
{
icon: Expensicons.Trashcan,
text: translate('distance.deleteWaypoint'),
onSelected: () => setIsDeleteStopModalOpen(true),
onSelected: () => {
setRestoreFocusType(undefined);
setIsDeleteStopModalOpen(true);
},
},
]}
/>
Expand All @@ -187,6 +193,8 @@ function IOURequestStepWaypoint({
cancelText={translate('common.cancel')}
shouldEnableNewFocusManagement
danger
shouldEnableNewFocusManagement

Check failure on line 196 in src/pages/iou/request/step/IOURequestStepWaypoint.tsx

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

JSX elements cannot have multiple attributes with the same name.

Check failure on line 196 in src/pages/iou/request/step/IOURequestStepWaypoint.tsx

View workflow job for this annotation

GitHub Actions / lint / Run ESLint

No duplicate props allowed
restoreFocusType={restoreFocusType}
/>
<FormProvider
style={[styles.flexGrow1, styles.mh5]}
Expand Down

0 comments on commit 0460aec

Please sign in to comment.