An open API service indexing awesome lists of open source software.

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

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