Merged
docs: upgrade README and README_en to v0.4.2 template #24
gbwAdd on 5 days ago
docs: upgrade README and README_en to v0.4.2 template #24
Merged
Total: 2 files changed+581-136
| @@ -1,172 +1,308 @@ | |||
| 1 | -[npm-badge]: https://img.shields.io/npm/v/react-native-material-textfield.svg?colorB=ff6d00 | 1 | +> 模板版本:v0.4.2 |
| 2 | -[npm-url]: https://npmjs.com/package/react-native-material-textfield | ||
| 3 | -[license-badge]: https://img.shields.io/npm/l/react-native-material-textfield.svg?colorB=448aff | ||
| 4 | -[license-url]: https://raw.githubusercontent.com/n4kz/react-native-material-textfield/master/license.txt | ||
| 5 | -[travis-badge]: https://api.travis-ci.org/n4kz/react-native-material-textfield.svg?branch=master | ||
| 6 | -[travis-url]: https://travis-ci.org/n4kz/react-native-material-textfield?branch=master | ||
| 7 | -[codeclimate-badge]: https://img.shields.io/codeclimate/maintainability/n4kz/react-native-material-textfield.svg | ||
| 8 | -[codeclimate-url]: https://codeclimate.com/github/n4kz/react-native-material-textfield | ||
| 9 | -[example-url]: https://cloud.githubusercontent.com/assets/2055622/24325711/eaa4ff08-11af-11e7-8550-2504c1580979.gif | ||
| 10 | -[rn-textinput]: https://facebook.github.io/react-native/docs/textinput.html#props | ||
| 11 | -[md-textfield]: https://material.io/guidelines/components/text-fields.html | ||
| 12 | 2 | ||
| 13 | -# react-native-material-textfield | 3 | +<p align="center"> |
| 4 | + <h1 align="center"> <code>react-native-material-textfield</code> </h1> | ||
| 5 | +</p> | ||
| 14 | 6 | ||
| 15 | -[![npm][npm-badge]][npm-url] | 7 | +[English](./README_en.md) | **简体中文** |
| 16 | -[![license][license-badge]][license-url] | ||
| 17 | -[![travis][travis-badge]][travis-url] | ||
| 18 | -[![codeclimate][codeclimate-badge]][codeclimate-url] | ||
| 19 | 8 | ||
| 20 | -Material texfield with consistent behaviour on iOS and Android | 9 | +本项目基于 [react-native-material-textfield](https://github.com/n4kz/react-native-material-textfield) 开发。 |
| 21 | 10 | ||
| 22 | -![example][example-url] | 11 | +该第三方库的仓库已迁移至 AtomGit,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-material-textfield`,版本所属关系如下: |
| 23 | 12 | ||
| 24 | -## Features | 13 | +| 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 | |
| 14 | +| --- | --- | --- | --- | --- | --- | --- | --- | | ||
| 15 | +| @react-native-ohos/react-native-material-textfield | [~ 0.17.0](https://www.npmjs.com/package/@react-native-ohos/react-native-material-textfield) | [AtomGit Releases](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/releases) | 0.77.* /0.82.* | 否 | API12+ | 0.16.1 | [br_rnoh0.77](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/tree/br_rnoh0.77) | | ||
| 16 | +| @react-native-ohos/react-native-material-textfield | [~ 0.16.1](https://www.npmjs.com/package/@react-native-ohos/react-native-material-textfield) | [AtomGit Releases](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/releases) | 0.72.* | 否 | API12+ | 0.16.1 | [br_rnoh0.72](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/tree/br_rnoh0.72) | | ||
| 17 | +| @react-native-oh-tpl/react-native-material-textfield | [<= 0.16.1-0.0.4@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-material-textfield) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-material-textfield/releases) | 0.72.* | 否 | API12+ | 0.16.1 | [sig](https://github.com/react-native-oh-library/react-native-material-textfield/tree/sig) | | ||
| 25 | 18 | ||
| 26 | -* Material design [guidelines][md-textfield] compliance | 19 | +## 简介 |
| 27 | -* Consistent look and feel on iOS and Android | ||
| 28 | -* Animated state transitions (normal, focused and errored) | ||
| 29 | -* Customizable font size, colors and animation duration | ||
| 30 | -* Disabled state (with dotted underline) | ||
| 31 | -* Outlined and filled fields | ||
| 32 | -* Masked input support | ||
| 33 | -* Multiline text input | ||
| 34 | -* Character counter | ||
| 35 | -* Prefix and suffix | ||
| 36 | -* Accessory views | ||
| 37 | -* Helper text | ||
| 38 | -* RTL support | ||
| 39 | -* Pure javascript implementation | ||
| 40 | 20 | ||
| 41 | -## Installation | 21 | +react-native-material-textfield 是一个专为 React Native 应用程序设计的高质量、跨平台文本输入组件库。 |
| 22 | + | ||
| 23 | +## 下载安装 | ||
| 24 | + | ||
| 25 | +进入到工程目录并输入以下命令: | ||
| 26 | + | ||
| 27 | +**npm** | ||
| 42 | 28 | ||
| 43 | ```bash | 29 | ```bash |
| 44 | -npm install --save react-native-material-textfield | 30 | +npm install @react-native-ohos/react-native-material-textfield |
| 31 | +npm install deprecated-react-native-prop-types | ||
| 45 | ``` | 32 | ``` |
| 46 | 33 | ||
| 47 | -## Usage | 34 | +**yarn** |
| 48 | 35 | ||
| 49 | -```javascript | 36 | +```bash |
| 50 | -import React, { Component } from 'react'; | 37 | +yarn add @react-native-ohos/react-native-material-textfield |
| 38 | +yarn add deprecated-react-native-prop-types | ||
| 39 | +``` | ||
| 40 | + | ||
| 41 | +## 约束与限制 | ||
| 42 | + | ||
| 43 | +### 兼容性 | ||
| 44 | + | ||
| 45 | +本文档内容基于以下版本验证通过: | ||
| 46 | + | ||
| 47 | +1. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.868; ROM: 6.0.0.112; | ||
| 48 | +2. RNOH: 0.82.22; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.878; ROM: 6.0.0.130; | ||
| 49 | + | ||
| 50 | +## 使用示例 | ||
| 51 | + | ||
| 52 | +下面的代码展示了这个库的基本使用场景: | ||
| 53 | + | ||
| 54 | +> [!WARNING] 使用时 import 的库名不变。 | ||
| 55 | + | ||
| 56 | +```tsx | ||
| 57 | + | ||
| 58 | +import React, {useState} from 'react'; | ||
| 59 | +import { StyleSheet,SafeAreaView,Platform,ScrollView,View,Button} from 'react-native'; | ||
| 51 | import { | 60 | import { |
| 52 | TextField, | 61 | TextField, |
| 53 | - FilledTextField, | ||
| 54 | - OutlinedTextField, | ||
| 55 | } from 'react-native-material-textfield'; | 62 | } from 'react-native-material-textfield'; |
| 56 | 63 | ||
| 57 | -class Example extends Component { | 64 | +let defaults = { |
| 58 | - fieldRef = React.createRef(); | 65 | + firstname: 'Eddard', |
| 66 | + lastname: 'Stark' | ||
| 67 | +}; | ||
| 59 | 68 | ||
| 60 | - onSubmit = () => { | 69 | +// 导出组件 |
| 61 | - let { current: field } = this.fieldRef; | 70 | +export default function TextfieldDemo() { |
| 71 | + const [errors, setErrors] = useState({}); | ||
| 72 | + const firstnameRef = React.createRef(); | ||
| 73 | + const lastnameRef = React.createRef(); | ||
| 74 | + const emailRef = React.createRef(); | ||
| 75 | + const passwordRef = React.createRef(); | ||
| 62 | 76 | ||
| 63 | - console.log(field.value()); | 77 | + const onSubmit = () => { |
| 64 | - }; | 78 | + let errors = {}; |
| 65 | - | 79 | + ['firstname', 'lastname', 'email', 'password'] |
| 66 | - formatText = (text) => { | 80 | + .forEach((name) => { |
| 67 | - return text.replace(/[^+\d]/g, ''); | 81 | + const ref = name === 'firstname' ? firstnameRef : |
| 68 | - }; | 82 | + name === 'lastname' ? lastnameRef : |
| 69 | - | 83 | + name === 'email' ? emailRef : |
| 70 | - render() { | 84 | + passwordRef; |
| 71 | - return ( | 85 | + let value = ref.current ? ref.current.value() : ''; // 从 ref 中获取值 |
| 72 | - <OutlinedTextField | 86 | + if(!value) { |
| 73 | - label='Phone number' | 87 | + errors[name] = 'Should not be empty'; |
| 74 | - keyboardType='phone-pad' | 88 | + } else { |
| 75 | - formatText={this.formatText} | 89 | + if('password' === name && value.length < 6) { |
| 76 | - onSubmitEditing={this.onSubmit} | 90 | + errors[name] = 'Too short'; |
| 77 | - ref={this.fieldRef} | 91 | + } |
| 78 | - /> | 92 | + } |
| 79 | - ); | 93 | + }); |
| 94 | + setErrors(errors) | ||
| 80 | } | 95 | } |
| 96 | + | ||
| 97 | + return ( | ||
| 98 | + <SafeAreaView style={styles.safeContainer}> | ||
| 99 | + <ScrollView | ||
| 100 | + style={styles.scroll} | ||
| 101 | + contentContainerStyle={styles.contentContainer} | ||
| 102 | + keyboardShouldPersistTaps='handled' | ||
| 103 | + > | ||
| 104 | + <View style={styles.container}> | ||
| 105 | + <TextField | ||
| 106 | + ref={firstnameRef} | ||
| 107 | + value={defaults.firstname} | ||
| 108 | + autoCorrect={false} | ||
| 109 | + enablesReturnKeyAutomatically={true} | ||
| 110 | + returnKeyType='next' | ||
| 111 | + label='First Name' | ||
| 112 | + error={errors.firstname} | ||
| 113 | + /> | ||
| 114 | + | ||
| 115 | + <TextField | ||
| 116 | + ref={lastnameRef} | ||
| 117 | + value={defaults.lastname} | ||
| 118 | + autoCorrect={false} | ||
| 119 | + enablesReturnKeyAutomatically={true} | ||
| 120 | + returnKeyType='next' | ||
| 121 | + label='Last Name' | ||
| 122 | + error={errors.lastname} | ||
| 123 | + /> | ||
| 124 | + | ||
| 125 | + <TextField | ||
| 126 | + ref={emailRef} | ||
| 127 | + keyboardType='email-address' | ||
| 128 | + autoCapitalize='none' | ||
| 129 | + autoCorrect={false} | ||
| 130 | + enablesReturnKeyAutomatically={true} | ||
| 131 | + returnKeyType='next' | ||
| 132 | + label='Email Address' | ||
| 133 | + error={errors.email} | ||
| 134 | + /> | ||
| 135 | + | ||
| 136 | + <TextField | ||
| 137 | + ref={passwordRef} | ||
| 138 | + autoCapitalize='none' | ||
| 139 | + autoCorrect={false} | ||
| 140 | + enablesReturnKeyAutomatically={true} | ||
| 141 | + returnKeyType='done' | ||
| 142 | + label='Password' | ||
| 143 | + title='Choose wisely' | ||
| 144 | + maxLength={30} | ||
| 145 | + secureTextEntry={true} | ||
| 146 | + characterRestriction={20} | ||
| 147 | + error={errors.password} | ||
| 148 | + /> | ||
| 149 | + | ||
| 150 | + <Button title='运行' color='#841584' onPress={onSubmit}></Button> | ||
| 151 | + | ||
| 152 | + </View> | ||
| 153 | + </ScrollView> | ||
| 154 | + | ||
| 155 | + </SafeAreaView> | ||
| 156 | + ); | ||
| 81 | } | 157 | } |
| 158 | + | ||
| 159 | +const styles = StyleSheet.create({ | ||
| 160 | + safeContainer: { | ||
| 161 | + flex: 1, | ||
| 162 | + backgroundColor: '#FFFFFF', | ||
| 163 | + }, | ||
| 164 | + scroll: { | ||
| 165 | + backgroundColor: 'transparent', | ||
| 166 | + }, | ||
| 167 | + | ||
| 168 | + container: { | ||
| 169 | + margin: 8, | ||
| 170 | + marginTop: Platform.select({ harmony:8,ios: 8,android: 32 }), | ||
| 171 | + flex: 1, | ||
| 172 | + }, | ||
| 173 | + | ||
| 174 | + contentContainer: { | ||
| 175 | + padding: 8, | ||
| 176 | + } | ||
| 177 | +}); | ||
| 178 | + | ||
| 82 | ``` | 179 | ``` |
| 83 | 180 | ||
| 84 | -## Properties | 181 | +## 接口说明 |
| 85 | 182 | ||
| 86 | - name | description | type | default | 183 | +> [!TIP] "平台"列表示该属性在原三方库上支持的平台。 |
| 87 | -:--------------------- |:------------------------------------------- | --------:|:------------------ | ||
| 88 | - textColor | Text input color | String | rgba(0, 0, 0, .87) | ||
| 89 | - fontSize | Text input font size | Number | 16 | ||
| 90 | - labelFontSize | Text field label font size | Number | 12 | ||
| 91 | - lineWidth | Text field underline width | Number | 0.5 | ||
| 92 | - activeLineWidth | Text field active underline width | Number | 2 | ||
| 93 | - disabledLineWidth | Text field disabled underline width | Number | 1 | ||
| 94 | - tintColor | Text field accent color | String | rgb(0, 145, 234) | ||
| 95 | - baseColor | Text field base color | String | rgba(0, 0, 0, .38) | ||
| 96 | - label | Text field label text | String | - | ||
| 97 | - title | Text field helper text | String | - | ||
| 98 | - prefix | Text field prefix text | String | - | ||
| 99 | - suffix | Text field suffix text | String | - | ||
| 100 | - error | Text field error text | String | - | ||
| 101 | - errorColor | Text field color for errored state | String | rgb(213, 0, 0) | ||
| 102 | - lineType | Text field line type | String | solid | ||
| 103 | - disabledLineType | Text field line type in disabled state | String | dotted | ||
| 104 | - animationDuration | Text field animation duration in ms | Number | 225 | ||
| 105 | - characterRestriction | Text field soft limit for character counter | Number | - | ||
| 106 | - disabled | Text field availability | Boolean | false | ||
| 107 | - editable | Text field text can be edited | Boolean | true | ||
| 108 | - multiline | Text filed multiline input | Boolean | false | ||
| 109 | - contentInset | Layout configuration object | Object | [{...}](#content-inset) | ||
| 110 | - labelOffset | Label position adjustment | Object | [{...}](#label-offset) | ||
| 111 | - inputContainerStyle | Style for input container view | Object | - | ||
| 112 | - containerStyle | Style for container view | Object | - | ||
| 113 | - labelTextStyle | Style for label inner Text component | Object | - | ||
| 114 | - titleTextStyle | Style for title inner Text component | Object | - | ||
| 115 | - affixTextStyle | Style for affix inner Text component | Object | - | ||
| 116 | - formatText | Input mask callback | Function | - | ||
| 117 | - renderLeftAccessory | Render left input accessory view | Function | - | ||
| 118 | - renderRightAccessory | Render right input accessory view | Function | - | ||
| 119 | - onChangeText | Change text callback | Function | - | ||
| 120 | - onFocus | Focus callback | Function | - | ||
| 121 | - onBlur | Blur callback | Function | - | ||
| 122 | 184 | ||
| 123 | -Other [TextInput][rn-textinput] properties will also work. | 185 | +> [!TIP] "OpenHarmony平台支持"列为 "是" 表示 OpenHarmony 平台支持该属性;"否" 则表示不支持;"部分支持" 表示仅实现了功能的一部分。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 |
| 124 | 186 | ||
| 125 | -### Content Inset | 187 | +### 属性 |
| 126 | 188 | ||
| 127 | - name | description | Normal | Filled | Outlined | 189 | +| 名称 | 参数类型 | 默认值 | 必填 | 平台 | OpenHarmony平台支持 | 描述 | |
| 128 | -:----- |:--------------------------------- | ------:| ------:| --------: | 190 | +|------|----------|--------|------|------|-------------------|------| |
| 129 | - top | Inset on the top side | 16 | 8 | 0 | 191 | +| textColor | String | rgba(0, 0, 0, .87) | 否 | iOS/Android | 是 | 文本输入颜色 | |
| 130 | - left | Inset on the left side | 0 | 12 | 12 | 192 | +| fontSize | Number | 16 | 否 | iOS/Android | 是 | 文本输入字体大小 | |
| 131 | - right | Inset on the right side | 0 | 12 | 12 | 193 | +| labelFontSize | Number | 12 | 否 | iOS/Android | 是 | 文本框标签字体大小 | |
| 132 | - label | Space between label and TextInput | 4 | 4 | 4 | 194 | +| lineWidth | Number | 0.5 | 否 | iOS/Android | 是 | 文本框下划线宽度 | |
| 133 | - input | Space between line and TextInput | 8 | 8 | 16 | 195 | +| activeLineWidth | Number | 2 | 否 | iOS/Android | 是 | 文本框激活时下划线宽度 | |
| 196 | +| disabledLineWidth | Number | 1 | 否 | iOS/Android | 是 | 文本框禁用时下划线宽度 | | ||
| 197 | +| tintColor | String | rgb(0, 145, 234) | 否 | iOS/Android | 是 | 文本框强调色(如光标、激活状态颜色) | | ||
| 198 | +| baseColor | String | rgba(0, 0, 0, .38) | 否 | iOS/Android | 是 | 文本框基础颜色(如下划线默认颜色) | | ||
| 199 | +| label | String | - | 否 | iOS/Android | 是 | 文本框标签文本 | | ||
| 200 | +| title | String | - | 否 | iOS/Android | 是 | 文本框辅助说明文本 | | ||
| 201 | +| prefix | String | - | 否 | iOS/Android | 是 | 文本框前缀文本(如输入框前的固定内容) | | ||
| 202 | +| suffix | String | - | 否 | iOS/Android | 是 | 文本框后缀文本(如输入框后的单位、固定内容) | | ||
| 203 | +| error | String | - | 否 | iOS/Android | 是 | 文本框错误提示文本 | | ||
| 204 | +| errorColor | String | rgb(213, 0, 0) | 否 | iOS/Android | 是 | 文本框错误状态颜色(如错误提示文本、下划线颜色) | | ||
| 205 | +| lineType | String | solid | 否 | iOS/Android | 是 | 文本框下划线样式(如实线、虚线等) | | ||
| 206 | +| disabledLineType | String | dotted | 否 | iOS/Android | 是 | 文本框禁用时下划线样式 | | ||
| 207 | +| animationDuration | Number | 225 | 否 | iOS/Android | 是 | 文本框动画时长(单位:毫秒) | | ||
| 208 | +| characterRestriction | Number | - | 否 | iOS/Android | 是 | 文本框字符计数器软限制(提示最大输入长度,不强制拦截) | | ||
| 209 | +| disabled | Boolean | false | 否 | iOS/Android | 是 | 文本框是否禁用(禁用后无法输入和交互) | | ||
| 210 | +| editable | Boolean | true | 否 | iOS/Android | 是 | 文本框内容是否可编辑 | | ||
| 211 | +| multiline | Boolean | false | 否 | iOS/Android | 是 | 文本框是否支持多行输入 | | ||
| 212 | +| contentInset | Object | { top: 16, label: 4, input: 8, left: 0, right: 0 } | 否 | iOS/Android | 是 | 文本框内容内边距配置对象(控制文本与边框的间距) | | ||
| 213 | +| labelOffset | Object | { x0: 0, y0: 0, x1: 0, y1: 0 } | 否 | iOS/Android | 是 | 文本框标签位置偏移量(调整标签的 x/y 坐标) | | ||
| 214 | +| inputContainerStyle | Object | - | 否 | iOS/Android | 是 | 文本框输入容器视图样式(如输入区域的背景、边框等) | | ||
| 215 | +| containerStyle | Object | - | 否 | iOS/Android | 是 | 文本框整体容器视图样式(如整个组件的背景、边距等) | | ||
| 216 | +| labelTextStyle | Object | - | 否 | iOS/Android | 是 | 文本框标签内部文本组件样式(如标签的字体、颜色等) | | ||
| 217 | +| titleTextStyle | Object | - | 否 | iOS/Android | 是 | 文本框辅助说明文本组件样式 | | ||
| 218 | +| affixTextStyle | Object | - | 否 | iOS/Android | 是 | 文本框前缀 / 后缀文本组件样式 | | ||
| 219 | +| formatText | Function | - | 否 | iOS/Android | 是 | 输入内容格式化回调函数(如实时格式化手机号、日期等) | | ||
| 220 | +| renderLeftAccessory | Function | - | 否 | iOS/Android | 是 | 渲染文本框左侧辅助视图(如左侧图标、按钮等) | | ||
| 221 | +| renderRightAccessory | Function | - | 否 | iOS/Android | 是 | 渲染文本框右侧辅助视图(如右侧清除按钮、密码切换图标等) | | ||
| 222 | +| onChangeText | Function | - | 否 | iOS/Android | 是 | 文本内容变化时的回调函数(返回最新输入文本) | | ||
| 223 | +| onFocus | Function | - | 否 | iOS/Android | 是 | 文本框获取焦点时的回调函数 | | ||
| 224 | +| onBlur | Function | - | 否 | iOS/Android | 是 | 文本框失去焦点时的回调函数 | | ||
| 134 | 225 | ||
| 135 | -### Label Offset | 226 | +### API(TextField) |
| 136 | 227 | ||
| 137 | - name | description | Normal | Filled | Outlined | 228 | +| 名称 | 类型 | 参数类型 | 返回值 | 必填 | 平台 | OpenHarmony平台支持 | 描述 | |
| 138 | -:---- |:------------------------------------ | ------:| ------:| --------: | 229 | +|------|------|----------|--------|------|------|---------------------|------| |
| 139 | - x0 | Horizontal offset for inactive state | 0 | 0 | 0 | 230 | +| focus | function | / | / | 否 | iOS/Android | 是 | 获取焦点 | |
| 140 | - y0 | Vertical offset for inactive state | 0 | -10 | 0 | 231 | +| blur | function | / | / | 否 | iOS/Android | 是 | 释放焦点 | |
| 141 | - x1 | Horizontal offset for active state | 0 | 0 | 0 | 232 | +| clear | function | / | / | 否 | iOS/Android | 是 | 清空文本框内容 | |
| 142 | - y1 | Vertical offset for active state | 0 | -2 | -10 | 233 | +| value | function | / | String | 否 | iOS/Android | 是 | 获取当前输入值 | |
| 234 | +| isFocused | function | / | Boolean | 否 | iOS/Android | 是 | 获取当前焦点状态(是否聚焦) | | ||
| 235 | +| isErrored | function | / | Boolean | 否 | iOS/Android | 是 | 获取当前错误状态(是否存在错误) | | ||
| 236 | +| isRestricted | function | / | Boolean | 否 | iOS/Android | 是 | 获取当前限制状态(是否处于限制中) | | ||
| 237 | +| isDefaultVisible | function | / | Boolean | 否 | iOS/Android | 是 | 获取默认值可见状态(默认值是否显示) | | ||
| 238 | +| isPlaceholderVisible | function | / | Boolean | 否 | iOS/Android | 是 | 获取占位符可见状态(占位符是否显示) | | ||
| 239 | +| setValue | function | String | / | 否 | iOS/Android | 是 | 设置当前输入值 | | ||
| 143 | 240 | ||
| 144 | -## Methods | 241 | +## 遗留问题 |
| 145 | 242 | ||
| 146 | - name | description | returns | 243 | +无 |
| 147 | -:---------------------- |:----------------------------- | -------: | ||
| 148 | - focus() | Acquire focus | - | ||
| 149 | - blur() | Release focus | - | ||
| 150 | - clear() | Clear text field | - | ||
| 151 | - value() | Get current value | String | ||
| 152 | - isFocused() | Get current focus state | Boolean | ||
| 153 | - isErrored() | Get current error state | Boolean | ||
| 154 | - isRestricted() | Get current restriction state | Boolean | ||
| 155 | - isDefaultVisible() | Get default value visibility | Boolean | ||
| 156 | - isPlaceholderVisible() | Get placeholder visibility | Boolean | ||
| 157 | - setValue() | Set current value | - | ||
| 158 | 244 | ||
| 159 | -## Example | 245 | +## 其他 |
| 160 | 246 | ||
| 161 | -```bash | 247 | +无 |
| 162 | -git clone https://github.com/n4kz/react-native-material-textfield | 248 | + |
| 163 | -cd react-native-material-textfield/example | 249 | +## 目录结构 |
| 164 | -npm install | 250 | + |
| 165 | -npm run ios # or npm run android | 251 | +``` |
| 252 | +/rntpc_react-native-material-textfield # 项目根目录 | ||
| 253 | +├── src # RN 库源码 | ||
| 254 | +│ └── components | ||
| 255 | +│ ├── affix # 前缀 / 后缀组件 | ||
| 256 | +│ │ ├── index.js | ||
| 257 | +│ │ └── styles.js | ||
| 258 | +│ ├── counter # 字符计数器组件 | ||
| 259 | +│ │ ├── index.js | ||
| 260 | +│ │ └── styles.js | ||
| 261 | +│ ├── field # TextField 核心组件 | ||
| 262 | +│ │ ├── index.js | ||
| 263 | +│ │ └── styles.js | ||
| 264 | +│ ├── field-filled # FilledTextField 组件 | ||
| 265 | +│ │ ├── index.js | ||
| 266 | +│ │ └── styles.js | ||
| 267 | +│ ├── field-outlined # OutlinedTextField 组件 | ||
| 268 | +│ │ └── index.js | ||
| 269 | +│ ├── helper # 辅助说明文本组件 | ||
| 270 | +│ │ ├── index.js | ||
| 271 | +│ │ └── styles.js | ||
| 272 | +│ ├── label # 浮动标签组件 | ||
| 273 | +│ │ ├── index.js | ||
| 274 | +│ │ └── styles.js | ||
| 275 | +│ ├── line # 下划线组件 | ||
| 276 | +│ │ ├── index.js | ||
| 277 | +│ │ └── styles.js | ||
| 278 | +│ └── outline # 轮廓边框组件 | ||
| 279 | +│ ├── index.js | ||
| 280 | +│ └── styles.js | ||
| 281 | +├── example # 示例工程 | ||
| 282 | +│ ├── src | ||
| 283 | +│ │ └── TextFieldDemo.tsx # 示例页面 | ||
| 284 | +│ ├── harmony # OpenHarmony 示例工程 | ||
| 285 | +│ │ ├── AppScope # 应用全局配置 | ||
| 286 | +│ │ └── entry # OpenHarmony 入口模块 | ||
| 287 | +│ │ └── src/main | ||
| 288 | +│ │ ├── ets | ||
| 289 | +│ │ │ ├── entryability/EntryAbility.ets # 应用入口 | ||
| 290 | +│ │ │ ├── pages/Index.ets # 示例首页 | ||
| 291 | +│ │ │ └── RNPackagesFactory.ets # RN Package 工厂 | ||
| 292 | +│ │ ├── cpp | ||
| 293 | +│ │ │ └── PackageProvider.cpp # C++ Package 入口 | ||
| 294 | +│ │ └── resources # 资源文件 | ||
| 295 | +│ └── index.js # 示例入口 | ||
| 296 | +├── index.js # 库入口(导出 TextField / FilledTextField / OutlinedTextField) | ||
| 297 | +├── package.json | ||
| 298 | +├── README.md # 中文安装使用方法 | ||
| 299 | +└── README_en.md # 英文安装使用方法 | ||
| 166 | ``` | 300 | ``` |
| 167 | 301 | ||
| 168 | -## Copyright and License | 302 | +## 贡献代码 |
| 169 | 303 | ||
| 170 | -BSD License | 304 | +使用过程中发现任何问题都可以提交 [Issue](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/issues),当然,也非常欢迎提交 [PR](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/pulls)。 |
| 305 | + | ||
| 306 | +## 开源协议 | ||
| 171 | 307 | ||
| 172 | -Copyright 2017-2019 Alexander Nazarov. All rights reserved. | 308 | +本项目基于 [The BSD 3-Clause License (BSD-3-Clause)](https://github.com/n4kz/react-native-material-textfield/blob/master/license.txt),请自由地享受和参与开源。 |
| @@ -0,0 +1,309 @@ | |||
| 1 | +> Template version: v0.4.2 | ||
| 2 | + | ||
| 3 | +<p align="center"> | ||
| 4 | + <h1 align="center"> <code>react-native-material-textfield</code> </h1> | ||
| 5 | +</p> | ||
| 6 | + | ||
| 7 | +**English** | [简体中文](./README.md) | ||
| 8 | + | ||
| 9 | +This project is based on [react-native-material-textfield](https://github.com/n4kz/react-native-material-textfield). | ||
| 10 | + | ||
| 11 | +This third-party library has been migrated to AtomGit and is now available for direct download from npm, the new package name is: `@react-native-ohos/react-native-material-textfield`. The version correspondence details are as follows: | ||
| 12 | + | ||
| 13 | +| Third-Party Library Name | Version (npm Address) | Release Information | Supported RN Version | Autolink | Compile API Version | Community Baseline Version | Source Code Address | | ||
| 14 | +| --- | --- | --- | --- | --- | --- | --- | --- | | ||
| 15 | +| @react-native-ohos/react-native-material-textfield | [~ 0.17.0](https://www.npmjs.com/package/@react-native-ohos/react-native-material-textfield) | [AtomGit Releases](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/releases) | 0.77.* /0.82.* | No | API12+ | 0.16.1 | [br_rnoh0.77](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/tree/br_rnoh0.77) | | ||
| 16 | +| @react-native-ohos/react-native-material-textfield | [~ 0.16.1](https://www.npmjs.com/package/@react-native-ohos/react-native-material-textfield) | [AtomGit Releases](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/releases) | 0.72.* | No | API12+ | 0.16.1 | [br_rnoh0.72](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/tree/br_rnoh0.72) | | ||
| 17 | +| @react-native-oh-tpl/react-native-material-textfield | [<= 0.16.1-0.0.4@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-material-textfield) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-material-textfield/releases) | 0.72.* | No | API12+ | 0.16.1 | [sig](https://github.com/react-native-oh-library/react-native-material-textfield/tree/sig) | | ||
| 18 | + | ||
| 19 | +## Introduction | ||
| 20 | + | ||
| 21 | +react-native-material-textfield is a high-quality, cross-platform text input component library designed specifically for React Native apps. | ||
| 22 | + | ||
| 23 | +## Installation | ||
| 24 | + | ||
| 25 | +Run the following command in your project directory: | ||
| 26 | + | ||
| 27 | +**npm** | ||
| 28 | + | ||
| 29 | +```bash | ||
| 30 | +npm install @react-native-ohos/react-native-material-textfield | ||
| 31 | +npm install deprecated-react-native-prop-types | ||
| 32 | +``` | ||
| 33 | + | ||
| 34 | +**yarn** | ||
| 35 | + | ||
| 36 | +```bash | ||
| 37 | +yarn add @react-native-ohos/react-native-material-textfield | ||
| 38 | +yarn add deprecated-react-native-prop-types | ||
| 39 | +``` | ||
| 40 | + | ||
| 41 | +## Constraints | ||
| 42 | + | ||
| 43 | +### Compatibility | ||
| 44 | + | ||
| 45 | +This document is verified based on the following versions: | ||
| 46 | + | ||
| 47 | +1. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.868; ROM: 6.0.0.112; | ||
| 48 | +2. RNOH: 0.82.22; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.878; ROM: 6.0.0.130; | ||
| 49 | + | ||
| 50 | +## Example | ||
| 51 | + | ||
| 52 | +The following code demonstrates a basic usage scenario of this library: | ||
| 53 | + | ||
| 54 | +> [!WARNING] The import library name remains unchanged during use. | ||
| 55 | + | ||
| 56 | +```tsx | ||
| 57 | + | ||
| 58 | +import React, {useState} from 'react'; | ||
| 59 | +import { StyleSheet,SafeAreaView,Platform,ScrollView,View,Button} from 'react-native'; | ||
| 60 | +import { | ||
| 61 | + TextField, | ||
| 62 | +} from 'react-native-material-textfield'; | ||
| 63 | + | ||
| 64 | + | ||
| 65 | +let defaults = { | ||
| 66 | + firstname: 'Eddard', | ||
| 67 | + lastname: 'Stark' | ||
| 68 | +}; | ||
| 69 | + | ||
| 70 | + | ||
| 71 | +export default function TextfieldDemo() { | ||
| 72 | + const [errors, setErrors] = useState({}); | ||
| 73 | + const firstnameRef = React.createRef(); | ||
| 74 | + const lastnameRef = React.createRef(); | ||
| 75 | + const emailRef = React.createRef(); | ||
| 76 | + const passwordRef = React.createRef(); | ||
| 77 | + | ||
| 78 | + const onSubmit = () => { | ||
| 79 | + let errors = {}; | ||
| 80 | + ['firstname', 'lastname', 'email', 'password'] | ||
| 81 | + .forEach((name) => { | ||
| 82 | + const ref = name === 'firstname' ? firstnameRef : | ||
| 83 | + name === 'lastname' ? lastnameRef : | ||
| 84 | + name === 'email' ? emailRef : | ||
| 85 | + passwordRef; | ||
| 86 | + let value = ref.current ? ref.current.value() : ''; | ||
| 87 | + if(!value) { | ||
| 88 | + errors[name] = 'Should not be empty'; | ||
| 89 | + } else { | ||
| 90 | + if('password' === name && value.length < 6) { | ||
| 91 | + errors[name] = 'Too short'; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + }); | ||
| 95 | + setErrors(errors) | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + return ( | ||
| 99 | + <SafeAreaView style={styles.safeContainer}> | ||
| 100 | + <ScrollView | ||
| 101 | + style={styles.scroll} | ||
| 102 | + contentContainerStyle={styles.contentContainer} | ||
| 103 | + keyboardShouldPersistTaps='handled' | ||
| 104 | + > | ||
| 105 | + <View style={styles.container}> | ||
| 106 | + <TextField | ||
| 107 | + ref={firstnameRef} | ||
| 108 | + value={defaults.firstname} | ||
| 109 | + autoCorrect={false} | ||
| 110 | + enablesReturnKeyAutomatically={true} | ||
| 111 | + returnKeyType='next' | ||
| 112 | + label='First Name' | ||
| 113 | + error={errors.firstname} | ||
| 114 | + /> | ||
| 115 | + | ||
| 116 | + <TextField | ||
| 117 | + ref={lastnameRef} | ||
| 118 | + value={defaults.lastname} | ||
| 119 | + autoCorrect={false} | ||
| 120 | + enablesReturnKeyAutomatically={true} | ||
| 121 | + returnKeyType='next' | ||
| 122 | + label='Last Name' | ||
| 123 | + error={errors.lastname} | ||
| 124 | + /> | ||
| 125 | + | ||
| 126 | + <TextField | ||
| 127 | + ref={emailRef} | ||
| 128 | + keyboardType='email-address' | ||
| 129 | + autoCapitalize='none' | ||
| 130 | + autoCorrect={false} | ||
| 131 | + enablesReturnKeyAutomatically={true} | ||
| 132 | + returnKeyType='next' | ||
| 133 | + label='Email Address' | ||
| 134 | + error={errors.email} | ||
| 135 | + /> | ||
| 136 | + | ||
| 137 | + <TextField | ||
| 138 | + ref={passwordRef} | ||
| 139 | + autoCapitalize='none' | ||
| 140 | + autoCorrect={false} | ||
| 141 | + enablesReturnKeyAutomatically={true} | ||
| 142 | + returnKeyType='done' | ||
| 143 | + label='Password' | ||
| 144 | + title='Choose wisely' | ||
| 145 | + maxLength={30} | ||
| 146 | + secureTextEntry={true} | ||
| 147 | + characterRestriction={20} | ||
| 148 | + error={errors.password} | ||
| 149 | + /> | ||
| 150 | + | ||
| 151 | + <Button title='running' color='#841584' onPress={onSubmit}></Button> | ||
| 152 | + | ||
| 153 | + </View> | ||
| 154 | + </ScrollView> | ||
| 155 | + | ||
| 156 | + </SafeAreaView> | ||
| 157 | + ); | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +const styles = StyleSheet.create({ | ||
| 161 | + safeContainer: { | ||
| 162 | + flex: 1, | ||
| 163 | + backgroundColor: '#FFFFFF', | ||
| 164 | + }, | ||
| 165 | + scroll: { | ||
| 166 | + backgroundColor: 'transparent', | ||
| 167 | + }, | ||
| 168 | + | ||
| 169 | + container: { | ||
| 170 | + margin: 8, | ||
| 171 | + marginTop: Platform.select({ harmony:8,ios: 8,android: 32 }), | ||
| 172 | + flex: 1, | ||
| 173 | + }, | ||
| 174 | + | ||
| 175 | + contentContainer: { | ||
| 176 | + padding: 8, | ||
| 177 | + } | ||
| 178 | +}); | ||
| 179 | + | ||
| 180 | +``` | ||
| 181 | + | ||
| 182 | +## Available APIs | ||
| 183 | + | ||
| 184 | +> [!TIP] The "Platform" column indicates the platforms supported by the original third-party library. | ||
| 185 | + | ||
| 186 | +> [!TIP] If the value of "OpenHarmony Platform Support" is "Yes", it means that the OpenHarmony platform supports this property; "No" means the opposite; "Partially" means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android. | ||
| 187 | + | ||
| 188 | +### Properties | ||
| 189 | + | ||
| 190 | +| Name | Parameter Type | Default Value | Required | Platform | OpenHarmony Platform Support | Description | | ||
| 191 | +|------|----------------|---------------|----------|----------|------------------------------|-------------| | ||
| 192 | +| textColor | String | rgba(0, 0, 0, .87) | No | iOS/Android | Yes | Text input color | | ||
| 193 | +| fontSize | Number | 16 | No | iOS/Android | Yes | Text input font size | | ||
| 194 | +| labelFontSize | Number | 12 | No | iOS/Android | Yes | Text field label font size | | ||
| 195 | +| lineWidth | Number | 0.5 | No | iOS/Android | Yes | Text field underline width | | ||
| 196 | +| activeLineWidth | Number | 2 | No | iOS/Android | Yes | Text field active underline width | | ||
| 197 | +| disabledLineWidth | Number | 1 | No | iOS/Android | Yes | Text field disabled underline width | | ||
| 198 | +| tintColor | String | rgb(0, 145, 234) | No | iOS/Android | Yes | Text field accent color (cursor and active state) | | ||
| 199 | +| baseColor | String | rgba(0, 0, 0, .38) | No | iOS/Android | Yes | Text field base color (default underline color) | | ||
| 200 | +| label | String | - | No | iOS/Android | Yes | Text field label text | | ||
| 201 | +| title | String | - | No | iOS/Android | Yes | Text field helper text | | ||
| 202 | +| prefix | String | - | No | iOS/Android | Yes | Text field prefix text | | ||
| 203 | +| suffix | String | - | No | iOS/Android | Yes | Text field suffix text (unit or fixed trailing content) | | ||
| 204 | +| error | String | - | No | iOS/Android | Yes | Text field error text | | ||
| 205 | +| errorColor | String | rgb(213, 0, 0) | No | iOS/Android | Yes | Text field color for errored state | | ||
| 206 | +| lineType | String | solid | No | iOS/Android | Yes | Text field line type (solid, dotted, etc.) | | ||
| 207 | +| disabledLineType | String | dotted | No | iOS/Android | Yes | Text field line type in disabled state | | ||
| 208 | +| animationDuration | Number | 225 | No | iOS/Android | Yes | Text field animation duration in ms | | ||
| 209 | +| characterRestriction | Number | - | No | iOS/Android | Yes | Text field soft limit for character counter | | ||
| 210 | +| disabled | Boolean | false | No | iOS/Android | Yes | Text field availability | | ||
| 211 | +| editable | Boolean | true | No | iOS/Android | Yes | Whether text field content can be edited | | ||
| 212 | +| multiline | Boolean | false | No | iOS/Android | Yes | Whether the text field supports multiline input | | ||
| 213 | +| contentInset | Object | { top: 16, label: 4, input: 8, left: 0, right: 0 } | No | iOS/Android | Yes | Layout configuration object for content insets | | ||
| 214 | +| labelOffset | Object | { x0: 0, y0: 0, x1: 0, y1: 0 } | No | iOS/Android | Yes | Label position adjustment | | ||
| 215 | +| inputContainerStyle | Object | - | No | iOS/Android | Yes | Style for input container view | | ||
| 216 | +| containerStyle | Object | - | No | iOS/Android | Yes | Style for container view | | ||
| 217 | +| labelTextStyle | Object | - | No | iOS/Android | Yes | Style for label inner Text component | | ||
| 218 | +| titleTextStyle | Object | - | No | iOS/Android | Yes | Style for title inner Text component | | ||
| 219 | +| affixTextStyle | Object | - | No | iOS/Android | Yes | Style for affix inner Text component | | ||
| 220 | +| formatText | Function | - | No | iOS/Android | Yes | Input mask callback | | ||
| 221 | +| renderLeftAccessory | Function | - | No | iOS/Android | Yes | Render left input accessory view | | ||
| 222 | +| renderRightAccessory | Function | - | No | iOS/Android | Yes | Render right input accessory view | | ||
| 223 | +| onChangeText | Function | - | No | iOS/Android | Yes | Change text callback | | ||
| 224 | +| onFocus | Function | - | No | iOS/Android | Yes | Focus callback | | ||
| 225 | +| onBlur | Function | - | No | iOS/Android | Yes | Blur callback | | ||
| 226 | + | ||
| 227 | +### API(TextField) | ||
| 228 | + | ||
| 229 | +| Name | Type | Parameter Type | Return Value | Required | Platform | OpenHarmony Platform Support | Description | | ||
| 230 | +|------|------|----------------|--------------|----------|----------|------------------------------|-------------| | ||
| 231 | +| focus | function | / | / | No | iOS/Android | Yes | Acquire focus | | ||
| 232 | +| blur | function | / | / | No | iOS/Android | Yes | Release focus | | ||
| 233 | +| clear | function | / | / | No | iOS/Android | Yes | Clear text field | | ||
| 234 | +| value | function | / | String | No | iOS/Android | Yes | Get current value | | ||
| 235 | +| isFocused | function | / | Boolean | No | iOS/Android | Yes | Get current focus state | | ||
| 236 | +| isErrored | function | / | Boolean | No | iOS/Android | Yes | Get current error state | | ||
| 237 | +| isRestricted | function | / | Boolean | No | iOS/Android | Yes | Get current restriction state | | ||
| 238 | +| isDefaultVisible | function | / | Boolean | No | iOS/Android | Yes | Get default value visibility | | ||
| 239 | +| isPlaceholderVisible | function | / | Boolean | No | iOS/Android | Yes | Get placeholder visibility | | ||
| 240 | +| setValue | function | String | / | No | iOS/Android | Yes | Set current value | | ||
| 241 | + | ||
| 242 | +## Known Issues | ||
| 243 | + | ||
| 244 | +None | ||
| 245 | + | ||
| 246 | +## Other | ||
| 247 | + | ||
| 248 | +None | ||
| 249 | + | ||
| 250 | +## Directory Structure | ||
| 251 | + | ||
| 252 | +``` | ||
| 253 | +/rntpc_react-native-material-textfield # Project root directory | ||
| 254 | +├── src # RN library source | ||
| 255 | +│ └── components | ||
| 256 | +│ ├── affix # Prefix / suffix component | ||
| 257 | +│ │ ├── index.js | ||
| 258 | +│ │ └── styles.js | ||
| 259 | +│ ├── counter # Character counter component | ||
| 260 | +│ │ ├── index.js | ||
| 261 | +│ │ └── styles.js | ||
| 262 | +│ ├── field # TextField core component | ||
| 263 | +│ │ ├── index.js | ||
| 264 | +│ │ └── styles.js | ||
| 265 | +│ ├── field-filled # FilledTextField component | ||
| 266 | +│ │ ├── index.js | ||
| 267 | +│ │ └── styles.js | ||
| 268 | +│ ├── field-outlined # OutlinedTextField component | ||
| 269 | +│ │ └── index.js | ||
| 270 | +│ ├── helper # Helper text component | ||
| 271 | +│ │ ├── index.js | ||
| 272 | +│ │ └── styles.js | ||
| 273 | +│ ├── label # Floating label component | ||
| 274 | +│ │ ├── index.js | ||
| 275 | +│ │ └── styles.js | ||
| 276 | +│ ├── line # Underline component | ||
| 277 | +│ │ ├── index.js | ||
| 278 | +│ │ └── styles.js | ||
| 279 | +│ └── outline # Outline border component | ||
| 280 | +│ ├── index.js | ||
| 281 | +│ └── styles.js | ||
| 282 | +├── example # Example project | ||
| 283 | +│ ├── src | ||
| 284 | +│ │ └── TextFieldDemo.tsx # Demo page | ||
| 285 | +│ ├── harmony # OpenHarmony example project | ||
| 286 | +│ │ ├── AppScope # App-level configuration | ||
| 287 | +│ │ └── entry # OpenHarmony entry module | ||
| 288 | +│ │ └── src/main | ||
| 289 | +│ │ ├── ets | ||
| 290 | +│ │ │ ├── entryability/EntryAbility.ets # App entry | ||
| 291 | +│ │ │ ├── pages/Index.ets # Demo home page | ||
| 292 | +│ │ │ └── RNPackagesFactory.ets # RN Package factory | ||
| 293 | +│ │ ├── cpp | ||
| 294 | +│ │ │ └── PackageProvider.cpp # C++ Package entry | ||
| 295 | +│ │ └── resources # Resource files | ||
| 296 | +│ └── index.js # Example entry | ||
| 297 | +├── index.js # Library entry (exports TextField / FilledTextField / OutlinedTextField) | ||
| 298 | +├── package.json | ||
| 299 | +├── README.md # Chinese installation and usage guide | ||
| 300 | +└── README_en.md # English installation and usage guide | ||
| 301 | +``` | ||
| 302 | + | ||
| 303 | +## How to Contribute | ||
| 304 | + | ||
| 305 | +If you find any problem when using react-native-material-textfield, submit an [Issue](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/issues) or a [PR](https://atomgit.com/CPF-RN/rntpc_react-native-material-textfield/pulls). | ||
| 306 | + | ||
| 307 | +## License | ||
| 308 | + | ||
| 309 | +This project is based on [The BSD 3-Clause License (BSD-3-Clause)](https://github.com/n4kz/react-native-material-textfield/blob/master/license.txt). Feel free to enjoy and participate in open source. | ||
【AI-Review】【一般】【编码规范】【其他编码规范】 ● 问题: 根目录 README.md 默认语言为中文(第 7 行
**简体中文**加粗表示当前语言),英文版本需通过链接跳转至 README_en.md。通用检视规则 5 要求"根目录 README.md 和文档默认首页/默认语言必须为英文",当前设置将中文作为默认入口。● 影响: 非中文开发者在访问仓库时默认看到中文文档,需要额外点击切换至英文。
● 建议: 将根目录 README.md 改为英文版本,中文版改为 README_zh.md 并提供切换链接。如 CPF-RN 社区 v0.4.2 模板统一采用中文默认,建议在仓库自定义检视规范中明确豁免此通用规则。