Skip to content
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

[No QA] Simplify and upgrade KeyboardShortcut library #8059

Merged
merged 14 commits into from
Mar 10, 2022
Merged
Changes from 13 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
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -106,6 +106,7 @@
"react-web-config": "^1.0.0",
"rn-fetch-blob": "^0.12.0",
"save": "^2.4.0",
"shim-keyboard-event-key": "^1.0.3",
"smoothscroll-polyfill": "^0.4.4",
"underscore": "^1.13.1",
"urbanairship-react-native": "^11.0.2"
7 changes: 4 additions & 3 deletions src/CONST.js
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ const CONST = {
WEB: 'web',
DESKTOP: 'desktop',
},
KEYBOARD_SHORTCUT_MODIFIERS: {
PLATFORM_SPECIFIC_KEYS: {
CTRL: {
DEFAULT: 'control',
[PLATFORM_OS_MACOS]: 'meta',
@@ -176,8 +176,9 @@ const CONST = {
},
},
KEYBOARD_SHORTCUT_KEY_DISPLAY_NAME: {
CONTROL: 'Ctrl',
META: 'Cmd',
CONTROL: 'CTRL',
ESCAPE: 'ESC',
META: 'CMD',
Copy link
Contributor

Choose a reason for hiding this comment

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

Small question: How come this is called the META key instead of COMMAND?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IDK

SHIFT: 'Shift',
},
CURRENCY: {
7 changes: 6 additions & 1 deletion src/components/Button.js
Original file line number Diff line number Diff line change
@@ -48,6 +48,10 @@ const propTypes = {
/** Call the onPress function when Enter key is pressed */
pressOnEnter: PropTypes.bool,

/** The priority to assign the enter key event listener. 0 is the highest priority. */
enterKeyEventListenerPriority: PropTypes.number,


Copy link
Member

@rushatgabhane rushatgabhane Mar 9, 2022

Choose a reason for hiding this comment

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

@roryabraham extra line breaker. (We really need a eslint rule for this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there somewhere where we've explicitly added this to the review guidelines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Is there somewhere where we've explicitly added this to the review guidelines

Nope.

Yeah, let's add that rule.

Copy link
Member

Choose a reason for hiding this comment

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

@roryabraham I'm gonna create a quick PR for eslint-config-expensify to turn it on.

/** Additional styles to add after local styles. Applied to Pressable portion of button */
style: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.object),
@@ -92,6 +96,7 @@ const defaultProps = {
onPressIn: () => {},
onPressOut: () => {},
pressOnEnter: false,
enterKeyEventListenerPriority: 0,
style: [],
innerStyles: [],
textStyles: [],
@@ -124,7 +129,7 @@ class Button extends Component {
return;
}
this.props.onPress();
}, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true);
}, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true, false, this.props.enterKeyEventListenerPriority);
}

componentWillUnmount() {
5 changes: 2 additions & 3 deletions src/components/KeyboardShortcutsModal.js
Original file line number Diff line number Diff line change
@@ -33,10 +33,9 @@ const defaultProps = {
class KeyboardShortcutsModal extends React.Component {
componentDidMount() {
const shortcutConfig = CONST.KEYBOARD_SHORTCUTS.SHORTCUT_MODAL;
const shortcutModifiers = KeyboardShortcut.getShortcutModifiers(shortcutConfig.modifiers);
this.unsubscribeShortcutModal = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, () => {
KeyboardShortcutsActions.showKeyboardShortcutModal();
}, shortcutConfig.descriptionKey, shortcutModifiers, true);
}, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true);
}

componentWillUnmount() {
@@ -73,7 +72,7 @@ class KeyboardShortcutsModal extends React.Component {
}

render() {
const shortcuts = KeyboardShortcut.getKeyboardShortcuts();
const shortcuts = KeyboardShortcut.getDocumentedShortcuts();
const modalType = this.props.isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE;

return (
Loading