-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9585 from Expensify/update-staging-from-main
Update version to 1.1.79-0 on staging
- Loading branch information
Showing
39 changed files
with
908 additions
and
540 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,76 @@ | ||
import {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import CONST from '../CONST'; | ||
import KeyboardShortcut from '../libs/KeyboardShortcut'; | ||
|
||
const propTypes = { | ||
/** Children to render. */ | ||
children: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.node, | ||
]).isRequired, | ||
|
||
/** The current focused index. */ | ||
focusedIndex: PropTypes.number.isRequired, | ||
|
||
/** The maximum index – provided so that the focus can be sent back to the beginning of the list when the end is reached. */ | ||
maxIndex: PropTypes.number.isRequired, | ||
|
||
/** A callback executed when the focused input changes. */ | ||
onFocusedIndexChanged: PropTypes.func.isRequired, | ||
}; | ||
|
||
class ArrowKeyFocusManager extends Component { | ||
componentDidMount() { | ||
const arrowUpConfig = CONST.KEYBOARD_SHORTCUTS.ARROW_UP; | ||
const arrowDownConfig = CONST.KEYBOARD_SHORTCUTS.ARROW_DOWN; | ||
|
||
this.unsubscribeArrowUpKey = KeyboardShortcut.subscribe(arrowUpConfig.shortcutKey, () => { | ||
if (this.props.maxIndex <= 1) { | ||
return; | ||
} | ||
|
||
let newFocusedIndex = this.props.focusedIndex - 1; | ||
|
||
// Wrap around to the bottom of the list | ||
if (newFocusedIndex < 0) { | ||
newFocusedIndex = this.props.maxIndex; | ||
} | ||
|
||
this.props.onFocusedIndexChanged(newFocusedIndex); | ||
}, arrowUpConfig.descriptionKey, arrowUpConfig.modifiers, true); | ||
|
||
this.unsubscribeArrowDownKey = KeyboardShortcut.subscribe(arrowDownConfig.shortcutKey, () => { | ||
if (this.props.maxIndex <= 1) { | ||
return; | ||
} | ||
|
||
let newFocusedIndex = this.props.focusedIndex + 1; | ||
|
||
// Wrap around to the top of the list | ||
if (newFocusedIndex > this.props.maxIndex) { | ||
newFocusedIndex = 0; | ||
} | ||
|
||
this.props.onFocusedIndexChanged(newFocusedIndex); | ||
}, arrowDownConfig.descriptionKey, arrowDownConfig.modifiers, true); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.unsubscribeArrowUpKey) { | ||
this.unsubscribeArrowUpKey(); | ||
} | ||
|
||
if (this.unsubscribeArrowDownKey) { | ||
this.unsubscribeArrowDownKey(); | ||
} | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
ArrowKeyFocusManager.propTypes = propTypes; | ||
|
||
export default ArrowKeyFocusManager; |
This file contains 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.