Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fixed null SMS string #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
51 changes: 33 additions & 18 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best if you used @react-native-clipboard/clipboard instead.

import styles from './styles'
import { isAutoFillSupported } from './helpers/device'
import { codeToArray } from './helpers/codeToArray'
Expand Down Expand Up @@ -91,23 +91,38 @@ export default class OTPInputView extends Component<InputProps, OTPInputViewStat
}

checkPinCodeFromClipBoard = () => {
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
Expand Down