From b822dfe91572b958c1363f2ff1853d069bfe3089 Mon Sep 17 00:00:00 2001 From: Ali Kazemkhanloo Date: Fri, 6 Jan 2023 12:02:58 +0000 Subject: [PATCH 1/2] make Clipboard external to support expo as well as bare react-native --- README.md | 21 +++++++++++++++++++-- package.json | 1 - src/index.tsx | 8 +++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b058b40..507f5d7 100644 --- a/README.md +++ b/README.md @@ -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~~ +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 @@ -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 ( console.log(code)} numberOfInputs={6} /> diff --git a/package.json b/package.json index 69b973a..331929d 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "typescript": "4.7.4" }, "peerDependencies": { - "@react-native-clipboard/clipboard": "*", "react": "*", "react-native": "*" }, diff --git a/src/index.tsx b/src/index.tsx index 7fd9e45..3fc33cd 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,3 @@ -import Clipboard from '@react-native-clipboard/clipboard'; import React, { forwardRef, RefObject, @@ -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): Promise; + getString(): Promise; +} + type Props = TextInputProps & { autofillFromClipboard: boolean; autofillListenerIntervalMS?: number; @@ -43,6 +47,7 @@ type Props = TextInputProps & { isRTL?: boolean; numberOfInputs: number; testIDPrefix?: string; + Clipboard: ClipboardType; }; const styles = StyleSheet.create({ @@ -75,6 +80,7 @@ const OtpInputs = forwardRef( selectTextOnFocus = true, style, testIDPrefix = 'otpInput', + Clipboard, ...restProps }, ref, From 15343764761b92d2b16d59abbc36795e6120a035 Mon Sep 17 00:00:00 2001 From: Ali Kazemkhanloo Date: Fri, 6 Jan 2023 13:16:57 +0000 Subject: [PATCH 2/2] fix types and add change readme for expo --- README.md | 4 ++-- src/index.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 507f5d7..adad82e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Supported version: `react-native >= 0.59.0` ~~### Expo is currently not supported as `Clipboard` is not included in Expo SDK~~ -react native: +bare react native: ```bash $ yarn add react-native-otp-inputs @react-native-clipboard/clipboard ``` @@ -70,7 +70,7 @@ import { View } from 'react-native'; import OtpInputs from 'react-native-otp-inputs'; // expo -import {* as ExpoClipboard} from 'expo-clipboard'; +import * as ExpoClipboard from 'expo-clipboard'; const Clipboard = { setString: ExpoClipboard.setStringAsync, getString: ExpoClipboard.getStringAsync diff --git a/src/index.tsx b/src/index.tsx index 3fc33cd..7f4bf52 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -30,7 +30,7 @@ const supportAutofillFromClipboard = Platform.OS === 'android' || parseInt(Platform.Version as string, 10) < 14; type ClipboardType = { - setString(string: string): Promise; + setString(string: string): void; getString(): Promise; }