-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix attachment modal doesn't close when pressing search shortcut #27639
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, {forwardRef, useCallback, useEffect, useMemo} from 'react'; | ||
import React, {forwardRef, useCallback, useEffect, useMemo, useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import ReactNativeModal from 'react-native-modal'; | ||
|
@@ -14,6 +14,7 @@ import variables from '../../styles/variables'; | |
import CONST from '../../CONST'; | ||
import ComposerFocusManager from '../../libs/ComposerFocusManager'; | ||
import useNativeDriver from '../../libs/useNativeDriver'; | ||
import usePrevious from '../../hooks/usePrevious'; | ||
|
||
const propTypes = { | ||
...modalPropTypes, | ||
|
@@ -55,6 +56,9 @@ function BaseModal({ | |
|
||
const safeAreaInsets = useSafeAreaInsets(); | ||
|
||
const isVisibleRef = useRef(isVisible); | ||
const wasVisible = usePrevious(isVisible); | ||
|
||
/** | ||
* Hides modal | ||
* @param {Boolean} [callHideCallback=true] Should we call the onModalHide callback | ||
|
@@ -76,20 +80,25 @@ function BaseModal({ | |
); | ||
|
||
useEffect(() => { | ||
Modal.willAlertModalBecomeVisible(isVisible); | ||
|
||
// To handle closing any modal already visible when this modal is mounted, i.e. PopoverReportActionContextMenu | ||
Modal.setCloseModal(isVisible ? onClose : null); | ||
}, [isVisible, onClose]); | ||
isVisibleRef.current = isVisible; | ||
if (isVisible) { | ||
Modal.willAlertModalBecomeVisible(true); | ||
// To handle closing any modal already visible when this modal is mounted, i.e. PopoverReportActionContextMenu | ||
Modal.setCloseModal(onClose); | ||
} else if (wasVisible && !isVisible) { | ||
Modal.willAlertModalBecomeVisible(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @bernhardoj, we are thinking of moving this line, and the same line from the next There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is any reason but just replicating the previous code. |
||
Modal.setCloseModal(null); | ||
} | ||
}, [isVisible, wasVisible, onClose]); | ||
|
||
useEffect( | ||
() => () => { | ||
// Only trigger onClose and setModalVisibility if the modal is unmounting while visible. | ||
if (isVisible) { | ||
hideModal(true); | ||
Modal.willAlertModalBecomeVisible(false); | ||
if (!isVisibleRef.current) { | ||
return; | ||
} | ||
|
||
hideModal(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should create a ref for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ref is only needed for variables that are passed by value (not confirmed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, haven't tested it too |
||
Modal.willAlertModalBecomeVisible(false); | ||
// To prevent closing any modal already unmounted when this modal still remains as visible state | ||
Modal.setCloseModal(null); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB. Is there a significant gain merging the two useEffects together? I think it's more readable to have the isVisibleRef useEffect separated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just to reduce loc :). I think it's fine to put it here, we can even put it outside of
useEffect
, but it will feels like out of place.