Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

Supported version: `react-native >= 0.59.0`

### Expo is currently not supported as `Clipboard` is not included in Expo SDK

~~### Expo is currently not supported as `Clipboard` is not included in Expo SDK~~
bare react native:
```bash
$ yarn add react-native-otp-inputs @react-native-clipboard/clipboard
```

expo:
```bash
$ yarn add react-native-otp-inputs expo-clipboard
```

### After installation run:

```bash
Expand Down Expand Up @@ -64,11 +69,23 @@ import React, { Component } from 'react';
import { View } from 'react-native';
import OtpInputs from 'react-native-otp-inputs';

// expo
import * as ExpoClipboard from 'expo-clipboard';
const Clipboard = {
setString: ExpoClipboard.setStringAsync,
getString: ExpoClipboard.getStringAsync
}

// react-native
import Clipboard from '@react-native-clipboard/clipboard'


export default class App extends Component {
render() {
return (
<View style={styles.container}>
<OtpInputs
Clipboard={Clipboard}
handleChange={(code) => console.log(code)}
numberOfInputs={6}
/>
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"typescript": "4.7.4"
},
"peerDependencies": {
"@react-native-clipboard/clipboard": "*",
"react": "*",
"react-native": "*"
},
Expand Down
8 changes: 7 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Clipboard from '@react-native-clipboard/clipboard';
import React, {
forwardRef,
RefObject,
Expand Down Expand Up @@ -30,6 +29,11 @@ import { OtpInputsRef, SupportedKeyboardType } from './types';
const supportAutofillFromClipboard =
Platform.OS === 'android' || parseInt(Platform.Version as string, 10) < 14;

type ClipboardType = {
setString(string: string): void;
getString(): Promise<string>;
}

type Props = TextInputProps & {
autofillFromClipboard: boolean;
autofillListenerIntervalMS?: number;
Expand All @@ -43,6 +47,7 @@ type Props = TextInputProps & {
isRTL?: boolean;
numberOfInputs: number;
testIDPrefix?: string;
Clipboard: ClipboardType;
};

const styles = StyleSheet.create({
Expand Down Expand Up @@ -75,6 +80,7 @@ const OtpInputs = forwardRef<OtpInputsRef, Props>(
selectTextOnFocus = true,
style,
testIDPrefix = 'otpInput',
Clipboard,
...restProps
},
ref,
Expand Down