我提出这个问题是因为我最近在寻找 Mac 地址的字符串掩码。所以我决定创建自己的函数。以前的代码:
import React from 'react'
import {TextInput} from 'react-native-paper'
import {TextInputMask} from 'react-native-masked-text'
.
.
.
<TextInput
mode="outlined"
label="MAC"
render={props =>
<TextInputMask
type={'custom'}
options={{
/**
* mask: (String | required | default '')
* the mask pattern
* 9 - accept digit.
* A - accept alpha.
* S - accept alphanumeric.
* * - accept all, EXCEPT white space.
*/
mask: 'AA:AA:AA:AA:AA:AA'
}}
{...props}
/>
问题是当我慢慢输入 Mac 地址时,掩码会擦除文本,这种行为非常烦人。当我更快地键入 Mac 地址时它工作得很好,而这在常规使用流程中不会发生。Ps:我使用的是'react-native-masked-text'