# ty-react-native-smooth-pincode-input
**Repository Path**: kunyuan-hongke/ty-react-native-smooth-pincode-input
## Basic Information
- **Project Name**: ty-react-native-smooth-pincode-input
- **Description**: ty-react-native-smooth-pincode-input库
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-04-01
- **Last Updated**: 2025-10-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
@react-native-smooth-pincode-input
> [!TIP] [Github 地址](https://e.gitee.com/kunyuan-hongke/projects/737600/repos/kunyuan-hongke/ty-react-native-smooth-pincode-input/sources)
## 安装与使用
进入到工程目录并输入以下命令:
#### **npm**
```bash
npm install @tuya-oh/react-native-smooth-pincode-input
```
#### **yarn**
```bash
yarn add @tuya-oh/react-native-smooth-pincode-input
```
下面的代码展示了这个库的基本使用场景:
> [!WARNING] 使用时 import 的库名不变。
```js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import SmoothPinCodeInput from 'react-native-smooth-pincode-input';
export default class App extends React.Component {
state = {
code: '',
password: '',
};
pinInput = React.createRef();
_checkCode = (code) => {
if (code != '1234') {
this.pinInput.current.shake()
.then(() => this.setState({ code: '' }));
}
}
render() {
const { code, password } = this.state;
return (
{/* default */}
Default
this.setState({ code })}
onFulfill={this._checkCode}
onBackspace={() => console.log('No more back.')}
/>
{/* password */}
Password
this.setState({ password })}/>
{/* underline */}
Underline
this.setState({ code })}
/>
{/* customized */}
Customized
this.setState({ code })}
/>
{/* Custom placeholder & mask */}
Custom Placeholder
}
mask={}
maskDelay={1000}
password={true}
cellStyle={null}
cellStyleFocused={null}
value={code}
onTextChange={code => this.setState({ code })}
/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
section: {
alignItems: 'center',
margin: 16,
},
title: {
fontSize: 16,
fontWeight: 'bold',
marginBottom: 8,
},
});
```
## 约束与限制
## 属性
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
| Name | Description | Type | Required | Platform | HarmonyOS Support | 默认值 |
| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | ----------- | ----------------- | ---------------------------------------- |
| value | 输入框显示的值 | String | no | IOS/Android | yes | '' |
| codeLength | 输入字符的个数 | Number | no | IOS/Android | yes | 4 |
| cellSize | 每个单元格的大小 | Number | no | IOS/Android | yes | 48 |
| cellSpacing | 单元格之间的间距 | Number | no | IOS/Android | yes | 4 |
| placeholder | '' | String | no | IOS/Android | yes | Element |
| mask | '*' | String | no | IOS/Android | yes | Element |
| maskDelay | 字符被遮罩前的延迟,单位为毫秒 | Number | no | IOS/Android | yes | 200 |
| password | 是否遮罩输入值。每个单元格使用 mask 属性进行遮罩 | Boolean | no | IOS/Android | yes | FALSE |
| autoFocus | 如果为 true,则在组件挂载时聚焦输入框 | Boolean | no | IOS/Android | yes | FALSE |
| editable | 如果为 false,则每个单元格不可编辑 | Boolean | no | IOS/Android | yes | TRUE |
| animated | 是否启用动画 | Boolean | no | IOS/Android | yes | TRUE |
| animationFocused | 聚焦单元格的动画。可以是预设动画的字符串形式,也可以是自定义动画对象 | String, Object | no | IOS/Android | yes | 'pulse' |
| restrictToNumbers | 是否仅限制输入数字 | Boolean | no | IOS/Android | yes | FALSE |
| containerStyle | 整个单元格容器的视图样式 | React View StyleSheet | no | IOS/Android | yes | {} |
| cellStyle | 每个单元格的视图样式 | React View StyleSheet | no | IOS/Android | yes | { borderColor: 'gray', borderWidth: 1} |
| cellStyleFocused | 聚焦单元格的视图样式 | React View StyleSheet | no | IOS/Android | yes | { borderColor: 'black', borderWidth: 2 } |
| textStyle | 单元格值的文本样式 | React Text StyleSheet | no | IOS/Android | yes | { color: 'gray', fontSize: 24 } |
| textStyleFocused | 聚焦单元格值的文本样式 | React Text StyleSheet | no | IOS/Android | yes | { color: 'black' } |
| onFulfill | 当输入完全填满时调用的回调函数 | Function | no | IOS/Android | yes | null |
| onTextChange | 当文本更改时调用的回调函数 | Function | no | IOS/Android | yes | null |
| onBackspace | 当输入为空且按下退格键时调用的回调函数 | Function | no | IOS/Android | yes | null |
| keyboardType | 确定打开的键盘类型 | Enum('default', 'number-pad', 'decimal-pad', 'numeric', 'email-address', 'phone-pad') | no | IOS/Android | yes | 'numeric' |
## 开源协议
本项目基于 [MIT License (MIT)](https://github.com/xamous/react-native-smooth-pincode-input/blob/master/LICENSE) ,请自由地享受和参与开源。