项目中使用自提码,输入第一个的时候需要自动聚焦到第二个TextInput,然而找了外国人的一个组件:react-native-confirmation-code-input
但是, 这个输入框输入中文或者其他语言,键盘上面有候选字符串的时候,会出现崩溃的情况。
于是在,项目中使用try catch 205行,完美解决
其中正则是自己添加的
下面贴上人家组件封装的源码:
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { View, TextInput, StyleSheet, Dimensions, ViewPropTypes } from 'react-native';
import _ from 'lodash';
// if ViewPropTypes is not defined fall back to View.propType (to support RN < 0.44)
const viewPropTypes = ViewPropTypes || View.propTypes;
export default class ConfirmationCodeInput extends Component {
static propTypes = {
codeLength: PropTypes.number,
compareWithCode: PropTypes.string,
inputPosition: PropTypes.string,
size: PropTypes.number,
space: PropTypes.number,
className: PropTypes.string,
cellBorderWidth: PropTypes.number,
activeColor: PropTypes.string,
inactiveColor: PropTypes.string,
ignoreCase: PropTypes.bool,
autoFocus: PropTypes.bool,
codeInputStyle: TextInput.propTypes.style,
containerStyle: viewPropTypes.style,
onFulfill: PropTypes.func,
};
static defaultProps = {
codeLength: 5,
inputPosition: 'center',
autoFocus: true,
size: 40,
className: 'border-box',
cellBorderWidth: 1,
activeColor: 'rgba(255, 255, 255, 1)',
inactiveColor: 'rgba(255, 255, 255, 0.2)',
space: 8,
compareWithCode: '',
ignoreCase: false
};
constructor(props) {