From 3c4be85c74331d63b20c69f096bb1a4dec8af9ca Mon Sep 17 00:00:00 2001 From: brandonzalcman Date: Wed, 29 May 2024 21:01:48 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fixed=20null=20SMS=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.tsx | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/index.tsx b/index.tsx index 6c56ef8..f24e718 100644 --- a/index.tsx +++ b/index.tsx @@ -2,7 +2,7 @@ import { InputProps, OTPInputViewState } from '@twotalltotems/react-native-otp-input'; import React, { Component } from 'react' import { View, TextInput, TouchableWithoutFeedback, Keyboard, Platform, I18nManager, EmitterSubscription, } from 'react-native' -import Clipboard from '@react-native-community/clipboard'; +import * as Clipboard from 'expo-clipboard'; import styles from './styles' import { isAutoFillSupported } from './helpers/device' import { codeToArray } from './helpers/codeToArray' @@ -91,23 +91,38 @@ export default class OTPInputView extends Component { - const { pinCount, onCodeFilled } = this.props - const regexp = new RegExp(`^\\d{${pinCount}}$`) - Clipboard.getString().then(code => { - if (this.hasCheckedClipBoard && regexp.test(code) && (this.clipBoardCode !== code)) { - this.setState({ - digits: code.split(""), - }, () => { - this.blurAllFields() - this.notifyCodeChanged() - onCodeFilled && onCodeFilled(code) - }) - } - this.clipBoardCode = code - this.hasCheckedClipBoard = true - }).catch(() => { - }) - } + const { pinCount, onCodeFilled } = this.props; + const regexp = new RegExp(`^\\d{${pinCount}}$`); + + Clipboard.getStringAsync() + .then(code => { + if (!code) { + console.log('Clipboard is empty or not accessible'); + return; + } + + if (this.hasCheckedClipBoard && regexp.test(code) && (this.clipBoardCode !== code)) { + this.setState( + { + digits: code.split(""), + }, + () => { + this.blurAllFields(); + this.notifyCodeChanged(); + if (onCodeFilled) { + onCodeFilled(code); + } + } + ); + } + + this.clipBoardCode = code; + this.hasCheckedClipBoard = true; + }) + .catch(error => { + console.error('Error accessing clipboard:', error); + }); + }; private handleChangeText = (index: number, text: string) => { const { onCodeFilled, pinCount } = this.props