-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Added Keyboard shortcuts modal #6112
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
Merged
roryabraham
merged 41 commits into
Expensify:main
from
akshayasalvi:keyboard-shortcuts-modal
Nov 24, 2021
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
baf320a
Basic component with props added
akshayasalvi fdf81af
Converted component to class component
akshayasalvi e00816c
Added mapper function to the keyboardshortcut lib
akshayasalvi 28855fb
Translation files
akshayasalvi cb54938
Removed modal props from ScreenWrapper
akshayasalvi a6c28bd
Modified the shortcut trigger logic to modal
akshayasalvi 6bad775
Added keys for existing shortcuts
akshayasalvi 290acb8
Styling updates for container
akshayasalvi f31f5ed
Key handling for cmd
akshayasalvi 2b6e319
Moved styling to style.js
akshayasalvi 32622ab
Changed border styling
akshayasalvi 2e0d4c7
Added spanish translations
akshayasalvi 2096196
Added styling options for modal
akshayasalvi 18fbadf
Added borderRadius to the table
akshayasalvi 640687d
Fixed border styling for the table
akshayasalvi c18e2a4
Removed height hardcoding
akshayasalvi ea2a41f
Allow modal to open in input focus as well
akshayasalvi e1a8e96
Merge branch 'main' of github-personal:akshayasalvi/App into keyboard…
akshayasalvi e39b198
Updated copy for the modal subtitle
akshayasalvi 77c9381
Code cleanup
akshayasalvi 111edbc
Moved object to map to Keyboardshortcut lib
akshayasalvi 06e42c4
Reordered params for KeyboardShortcut.subscribe
akshayasalvi 1018fb5
Styling fixes
akshayasalvi dbfa47e
Changes for code cleanup
akshayasalvi 048c729
Merge branch 'main' of github-personal:akshayasalvi/App into keyboard…
akshayasalvi 666e499
Added check for descriptionKey
akshayasalvi eeb16d1
Fixed escape key for dialog
akshayasalvi fa76933
Lint fixes
akshayasalvi 99e7a4f
Made modal bottom docked for small screens and changed function name
akshayasalvi 1f57f37
Moved shortcut modifiers (control/meta) logic to utils
akshayasalvi 6943aa1
Merge branch 'main' of github-personal:akshayasalvi/App into keyboard…
akshayasalvi 4c29fc0
Changed logic for modifiers
akshayasalvi 7de6c54
Fixed typo for KeyboardShortcut
akshayasalvi e5b034d
Split toggle func to hide and show
akshayasalvi 3cbd1bf
Removed hardcoding of the shortcuts to CONST
akshayasalvi fc03898
Pick all shortcut configs from CONST
akshayasalvi eb6ef1c
Added enter configuration for keyboard shortcuts
akshayasalvi e2e456c
Fixed typo for Button
akshayasalvi f09b027
Added jsdocs and changed function calls
akshayasalvi 2eeed69
Unified representation of shortcut object
akshayasalvi 06c77ce
Fixed typos in shortcuts
akshayasalvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import _ from 'underscore'; | ||
| import HeaderWithCloseButton from './HeaderWithCloseButton'; | ||
| import Text from './Text'; | ||
| import Modal from './Modal'; | ||
| import CONST from '../CONST'; | ||
| import styles from '../styles/styles'; | ||
| import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; | ||
| import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||
| import compose from '../libs/compose'; | ||
| import KeyboardShortcut from '../libs/KeyboardShortcut'; | ||
|
|
||
| const propTypes = { | ||
| /** prop to fetch screen width */ | ||
| ...windowDimensionsPropTypes, | ||
|
|
||
| /** props to fetch translation functions */ | ||
| ...withLocalizePropTypes, | ||
| }; | ||
|
|
||
| class KeyboardShortcutsModal extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
| isOpen: false, | ||
| }; | ||
|
|
||
| this.showKeyboardShortcutModal = this.showKeyboardShortcutModal.bind(this); | ||
| this.hideKeyboardShortcutModal = this.hideKeyboardShortcutModal.bind(this); | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| const shortcutConfig = CONST.KEYBOARD_SHORTCUTS.SHORTCUT_MODAL; | ||
| const shortcutModifiers = KeyboardShortcut.getShortcutModifiers(shortcutConfig.modifiers); | ||
| this.unsubscribeShortcutModal = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, () => { | ||
| this.showKeyboardShortcutModal(); | ||
| }, shortcutConfig.descriptionKey, shortcutModifiers, true); | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| if (!this.unsubscribeShortcutModal) { | ||
| return; | ||
| } | ||
| this.unsubscribeShortcutModal(); | ||
| } | ||
|
|
||
| showKeyboardShortcutModal() { | ||
| this.setState({isOpen: true}); | ||
| } | ||
|
|
||
| hideKeyboardShortcutModal() { | ||
| this.setState({isOpen: false}); | ||
| } | ||
|
|
||
| /** | ||
| * Render single row for the Keyboard shortcuts with description | ||
| * @param {Object} shortcut | ||
| * @param {Boolean} isFirstRow | ||
| * @returns {*} | ||
| */ | ||
| renderRow(shortcut, isFirstRow) { | ||
| return ( | ||
| <View | ||
| style={[ | ||
| styles.keyboardShortcutTableRow, | ||
| styles.flex1, | ||
| isFirstRow && styles.keyboardShortcutTableFirstRow, | ||
| ]} | ||
| key={shortcut.displayName} | ||
| > | ||
| <View style={[styles.dFlex, styles.p2, styles.keyboardShortcutTablePrefix]}> | ||
| <Text>{shortcut.displayName}</Text> | ||
| </View> | ||
| <View style={[styles.flex1, styles.p2, styles.alignSelfStretch]}> | ||
| <Text>{this.props.translate(`keyboardShortcutModal.shortcuts.${shortcut.descriptionKey}`)}</Text> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| const shortcuts = KeyboardShortcut.getKeyboardShortcuts(); | ||
| const modalType = this.props.isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CENTERED; | ||
|
|
||
| return ( | ||
| <Modal | ||
| isVisible={this.state.isOpen} | ||
| type={modalType} | ||
| containerStyle={styles.keyboardShortcutModalContainer} | ||
| onClose={this.hideKeyboardShortcutModal} | ||
| > | ||
| <HeaderWithCloseButton title={this.props.translate('keyboardShortcutModal.title')} onCloseButtonPress={this.hideKeyboardShortcutModal} /> | ||
| <View style={[styles.p5, styles.pt0]}> | ||
| <Text style={styles.mb5}>{this.props.translate('keyboardShortcutModal.subtitle')}</Text> | ||
| <View style={[styles.keyboardShortcutTableWrapper]}> | ||
| <View style={[styles.alignItemsCenter, styles.keyboardShortcutTableContainer]}> | ||
| {_.map(shortcuts, (shortcut, index) => { | ||
| const isFirstRow = index === 0; | ||
| return this.renderRow(shortcut, isFirstRow); | ||
| })} | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </Modal> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| KeyboardShortcutsModal.propTypes = propTypes; | ||
|
|
||
| export default compose( | ||
| withWindowDimensions, | ||
| withLocalize, | ||
| )(KeyboardShortcutsModal); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.