https://github.com/envoy/react-native-key-commands
iOS UIKeyCommand native component for React Native
https://github.com/envoy/react-native-key-commands
ios react-native
Last synced: about 1 year ago
JSON representation
iOS UIKeyCommand native component for React Native
- Host: GitHub
- URL: https://github.com/envoy/react-native-key-commands
- Owner: envoy
- License: mit
- Created: 2018-03-13T21:58:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T13:33:51.000Z (almost 3 years ago)
- Last Synced: 2023-08-16T21:11:13.460Z (almost 3 years ago)
- Topics: ios, react-native
- Language: Objective-C
- Size: 33.2 KB
- Stars: 13
- Watchers: 6
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-key-commands
iOS [UIKeyCommand](https://developer.apple.com/documentation/uikit/uikeycommand) native component for React Native
## Install
```
npm install @envoy/react-native-key-commands
```
or
```
yarn add @envoy/react-native-key-commands
```
then
```
react-native link
```
## Usage
```JSX
import React from 'react'
import { NativeSyntheticEvent } from 'react-native'
import KeyCommands, {
KeyCommand,
constants,
} from '@envoy/react-native-key-commands'
export default class MyComponent: React.Component {
render () {
return (
{/* .. other views.. */}
)
}
private onKeyCommand = (event: NativeSyntheticEvent) => {
if (event.nativeEvent.input === '1' && event.keyModifiers === constants.keyModifierCommand) {
// do something here
}
}
}
```
To combine key modifiers, you can use `|` (bit-wise OR) operator, for example, you can define a shortcut `CMD + ALT + C` like this
```js
{
input: "c",
keyModifier: constants.keyModifierCommand | constants.,keyModifierAlternate
discoverabilityTitle: "Do something cool"
}
```
## Constants
Constants are exposed as `constatns` under the package. You can import it via
```
import { constants } from '@envoy/react-native-key-commands'
```
Here's the value mapping from `constants` to iOS constant values
- keyModifierShift: UIKeyModifierShift
- keyModifierControl: UIKeyModifierControl
- keyModifierAlternate: UIKeyModifierAlternate
- keyModifierCommand: UIKeyModifierCommand
- keyModifierNumericPad: UIKeyModifierNumericPad
- keyInputUpArrow: UIKeyInputUpArrow
- keyInputDownArrow: UIKeyInputDownArrow
- keyInputLeftArrow: UIKeyInputLeftArrow
- keyInputRightArrow: UIKeyInputRightArrow
- keyInputEscape: UIKeyInputEscape