Skip to content

Commit

Permalink
fix: modal closing with escape
Browse files Browse the repository at this point in the history
  • Loading branch information
parasharrajat committed Oct 18, 2021
1 parent b679d5b commit 694bdda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/Modal/BaseModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BaseModal extends PureComponent {
*/
hideModal(callHideCallback = true) {
if (this.props.shouldSetModalVisibility) {
setModalVisibility(false);
setModalVisibility(false, true);
}
if (callHideCallback) {
this.props.onModalHide();
Expand Down Expand Up @@ -79,7 +79,7 @@ class BaseModal extends PureComponent {
onBackButtonPress={this.props.onClose}
onModalShow={() => {
if (this.props.shouldSetModalVisibility) {
setModalVisibility(true);
setModalVisibility(true, true);
}
this.props.onModalShow();
}}
Expand Down
7 changes: 4 additions & 3 deletions src/components/ScreenWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const propTypes = {

/** Details about any modals being used */
modal: PropTypes.shape({
/** Indicates if there is a modal currently visible or not */
isVisible: PropTypes.bool,
/** Indicates if there is a Alert modal currently visible or not */
isAlertModalVisible: PropTypes.bool,
}),

};
Expand All @@ -67,7 +67,7 @@ class ScreenWrapper extends React.Component {

componentDidMount() {
this.unsubscribeEscapeKey = KeyboardShortcut.subscribe('Escape', () => {
if (!this.props.modal.isVisible) {
if (!this.props.modal.isAlertModalVisible) {
Navigation.dismissModal();
}
}, [], true);
Expand All @@ -88,6 +88,7 @@ class ScreenWrapper extends React.Component {
}

render() {
console.debug('modal visibility', this.props.modal.isAlertModalVisible);
return (
<SafeAreaInsetsContext.Consumer>
{(insets) => {
Expand Down
7 changes: 4 additions & 3 deletions src/libs/actions/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import ONYXKEYS from '../../ONYXKEYS';
/**
* Allows other parts of the app to know when a modal has been opened or closed
*
* @param {bool} isVisible
* @param {Boolean} isVisible
* @param {Boolean} isAlert
*/
function setModalVisibility(isVisible) {
Onyx.merge(ONYXKEYS.MODAL, {isVisible});
function setModalVisibility(isVisible, isAlert) {
Onyx.merge(ONYXKEYS.MODAL, {isVisible, isAlertModalVisible: isAlert ? isVisible : false});
}

export {
Expand Down

0 comments on commit 694bdda

Please sign in to comment.