Skip to content

Commit

Permalink
Merge pull request #16381 from situchan/fix/15276-search-focus-shortcut
Browse files Browse the repository at this point in the history
navigate to Search page after fully closing modal on keyboard shortcut
  • Loading branch information
Hayata Suenaga authored Mar 27, 2023
2 parents 1d3f069 + ecbe591 commit 2f922c4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/components/EmojiPicker/EmojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ class EmojiPicker extends React.Component {
}
}

hideEmojiPicker() {
/**
* Hide the emoji picker menu.
*
* @param {Boolean} isNavigating
*/
hideEmojiPicker(isNavigating) {
if (isNavigating) { this.onModalHide = () => {}; }
this.emojiPopoverAnchor = null;
this.setState({isEmojiPickerVisible: false});
}

/**
* Show the ReportActionContextMenu modal popover.
* Show the emoji picker menu.
*
* @param {Function} [onModalHide=() => {}] - Run a callback when Modal hides.
* @param {Function} [onEmojiSelected=() => {}] - Run a callback when Emoji selected.
Expand Down
1 change: 1 addition & 0 deletions src/components/Modal/BaseModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BaseModal extends PureComponent {
if (callHideCallback) {
this.props.onModalHide();
}
Modal.onModalDidClose();
}

render() {
Expand Down
6 changes: 2 additions & 4 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ class AuthScreens extends React.Component {
// the chat switcher, or new group chat
// based on the key modifiers pressed and the operating system
this.unsubscribeSearchShortcut = KeyboardShortcut.subscribe(searchShortcutConfig.shortcutKey, () => {
Modal.close();
Navigation.navigate(ROUTES.SEARCH);
Modal.close(() => Navigation.navigate(ROUTES.SEARCH));
}, searchShortcutConfig.descriptionKey, searchShortcutConfig.modifiers, true);
this.unsubscribeGroupShortcut = KeyboardShortcut.subscribe(groupShortcutConfig.shortcutKey, () => {
Modal.close();
Navigation.navigate(ROUTES.NEW_GROUP);
Modal.close(() => Navigation.navigate(ROUTES.NEW_GROUP));
}, groupShortcutConfig.descriptionKey, groupShortcutConfig.modifiers, true);
}

Expand Down
26 changes: 23 additions & 3 deletions src/libs/actions/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';

let closeModal;
let onModalClose;

/**
* Allows other parts of the app to call modal close function
Expand All @@ -12,9 +13,27 @@ function setCloseModal(onClose) {
closeModal = onClose;
}

function close() {
if (!closeModal) { return; }
closeModal();
/**
* Close modal in other parts of the app
*
* @param {Function} [onModalCloseCallback]
* @param {Boolean} isNavigating
*/
function close(onModalCloseCallback, isNavigating = true) {
if (!closeModal) {
// If modal is already closed, no need to wait for modal close. So immediately call callback.
if (onModalCloseCallback) { onModalCloseCallback(); }
onModalClose = null;
return;
}
onModalClose = onModalCloseCallback;
closeModal(isNavigating);
}

function onModalDidClose() {
if (!onModalClose) { return; }
onModalClose();
onModalClose = null;
}

/**
Expand All @@ -39,6 +58,7 @@ function willAlertModalBecomeVisible(isVisible) {
export {
setCloseModal,
close,
onModalDidClose,
setModalVisibility,
willAlertModalBecomeVisible,
};

0 comments on commit 2f922c4

Please sign in to comment.