Skip to content
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
15 changes: 10 additions & 5 deletions src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ function BaseModal({
[shouldSetModalVisibility, onModalHide, restoreFocusType, uniqueModalId],
);

const handleDismissModal = useCallback(() => {
ComposerFocusManager.setReadyToFocus(uniqueModalId);
}, [uniqueModalId]);

useEffect(() => {
let removeOnCloseListener: () => void;
if (isVisible) {
Expand All @@ -134,13 +138,18 @@ function BaseModal({
}
}

// When the modal becomes not visible, run dismiss logic to setReadyToFocus after it fully closes.
if (!isVisible && wasVisible) {
handleDismissModal();
}
Comment on lines +141 to +144

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In your proposal, ComposerFocusManager.setReadyToFocus(uniqueModalId) is called on unmount
() => () => {}

Didn't it work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@situchan Yes, when I created the PR and hideModal was called, the cleanup function (() => () => {}) did not run in the case described in #70912


return () => {
if (!removeOnCloseListener) {
return;
}
removeOnCloseListener();
};
}, [isVisible, wasVisible, onClose, type]);
}, [isVisible, wasVisible, onClose, type, handleDismissModal]);

useEffect(() => {
hideModalCallbackRef.current = hideModal;
Expand Down Expand Up @@ -178,10 +187,6 @@ function BaseModal({
}
};

const handleDismissModal = () => {
ComposerFocusManager.setReadyToFocus(uniqueModalId);
};

// Checks if modal overlaps with topSafeArea. Used to offset tall bottom docked modals with keyboard.
useEffect(() => {
if (type !== CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED || !canUseTouchScreen || !isSmallScreenWidth) {
Expand Down
17 changes: 7 additions & 10 deletions src/components/Modal/ReanimatedModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,13 @@ function ReanimatedModal({
InteractionManager.clearInteractionHandle(handleRef.current);
}

// On the web platform, the Modal's onDismiss callback may not be triggered if the dismiss process is interrupted by other actions such as navigation.
// Specifically on Android, the Modal's onDismiss callback does not work reliably. There's a reported issue at:
// Because on Android, the Modal's onDismiss callback does not work reliably. There's a reported issue at:
// https://stackoverflow.com/questions/58937956/react-native-modal-ondismiss-not-invoked
// Therefore, we manually call onDismiss and onModalHide here.
if (getPlatform() !== CONST.PLATFORM.IOS) {
onDismiss?.();
// Therefore, we manually call onModalHide() here for Android.
if (getPlatform() === CONST.PLATFORM.ANDROID) {
onModalHide();
}
}, [onDismiss, onModalHide]);
}, [onModalHide]);

const containerView = (
<Container
Expand Down Expand Up @@ -218,11 +216,10 @@ function ReanimatedModal({
statusBarTranslucent={statusBarTranslucent}
testID={testID}
onDismiss={() => {
if (getPlatform() !== CONST.PLATFORM.IOS) {
return;
}
onDismiss?.();
onModalHide();
if (getPlatform() !== CONST.PLATFORM.ANDROID) {
onModalHide();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed changes in this file is straight revert of #71637

}}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
Expand Down
Loading