
TextInput是一个允许用户在应用中通过键盘输入文本的基本组件。本组件的属性提供了多种特性的配置,譬如自动完成、自动大小写、占位文字,以及多种不同的键盘类型(如纯数字键盘)等等。最简单的用法就是丢一个TextInput到应用里,然后订阅它的onChangeText事件来读取用户的输入。
numeric(纯数字键盘)。 这些值在所有平台都可用:
(18)iosreturnKeyType:iosreturnKeyType enum('done', 'go', 'next', 'search', 'send', 'none', 'previous', 'default', 'emergency-call', 'google', 'join', 'route', 'yahoo') 决定“确定”按钮显示的内容。在Android上你还可以使用returnKeyLabel来自定义文本。
跨平台
下列这些选项是跨平台可用的:
donegonextsearchsend限Android
下列这些选项仅限Android使用:
noneprevious限iOS
下列这些选项仅限iOS使用:
defaultemergency-callgooglejoinrouteyahoo(19)selectTextOnFocus:如果为true,当获得焦点的时候,所有的文字都会被选中。
(20)selection:selection {start: number, end: number} 设置选中文字的范围(指定首尾的索引值)。如果首尾为同一索引位置,则相当于指定光标的位置。
(21)selectionColor:设置输入框高亮时的颜色(在iOS上还包括光标)
{x, y, width, height}。 (8)onScroll:在内容滚动时持续调用,传回参数的格式形如 { nativeEvent: { contentOffset: { x, y } } }。 也可能包含其他和滚动事件相关的参数,但是在Android上,出于性能考虑,不会提供contentSize参数。 (9)onSelectionChange:长按选择文本时,选择范围变化时调用此函数,传回参数的格式形如 { nativeEvent: { selection: { start, end } } }。 (10)iosonKeyPress:当一个键被按下的时候调用此回调。传递给回调函数的参数为 { nativeEvent: { key: keyValue } },其中keyValue即为被按下的键。会在onChange之前调用。 封装组件InputView.js的使用实例,如有需要完整的代码,请留言评论
1 <View >
2 <Text>请认真填写资料</Text>
3 <View style={{ marginTop: 12 }}>
4 <InputView name={'账号'}
5 hintText={''}
6 editableV={false}
7 value={String(lephone)}
8 />
9 <InputView name={'支付密码'}
10 isPassword={true}
11 hintText={'请输入数字+字母的组合'}
12 onChangeText={(inputData) => { this.setState({ password: inputData }) }}
13 />
14 <InputView name={'再次确认'}
15 isPassword={true}
16 //value={this.state.nickname}
17 hintText={'请再次输入'}
18 onChangeText={(inputData) => { this.setState({ confirmPass: inputData }) }}
19 />
20
21 </View>
22 </View> 富文本RichTextView的使用实例,如有需要完整的代码,请留言评论
1 <View style={{ marginTop: 20 }}>
2 <Text
3 style={{
4 fontSize: 14,
5 color: AppSetting.BLACK,
6 paddingLeft: 20,
7 marginBottom: 10
8 }}>奖品描述</Text>
9 <RichTextView
10 inputStyle={styles.inputStyle}
11 placeholder="请填写奖品描述(1000字以内哦)"
12 minHeight={240} // 最小高度,默认为100
13 maxLength={1000} // 最大长度,默认为100
14 onChangeText={(inputValue) => {
15 let desPrizes = CommonMethod.filteremoji(inputValue, 1)//表情过滤机制
16 this.setState({ desPrizes: desPrizes })
17 }}
18 showCount={true} // 展示剩余文字, 默认为true
19 />
20
21 </View> RichTextView.js富文本编辑组件
1 /**
2 * Created by jackson on 2018/08/13.
3 * 富文本
4 */
5 import React, {Component} from 'react';
6 import PropTypes from 'prop-types'
7 import {
8 StyleSheet,
9 View,
10 TextInput,
11 Text,
12 Dimensions
13 } from 'react-native';
14 const ScreenHeight = ('window').height;
15 const ScreenWidth = ('window').width;
16 const defaultMinHeight = 100
17 //模块声名并导出
18 export default class RichTextView extends Component {
19 //属性声名
20 static propTypes = {
21 style:PropTypes.object,
22 inputStyle:PropTypes.any,
23 maxLength:PropTypes.number, // 限制文字长度
24 placeholder:PropTypes.string, // 占位文字
25 minHeight:PropTypes.number, // 最小高度
26 showCount:PropTypes.bool,
27 onChangeText:PropTypes.func,//获取编辑的文本
28 };
29
30 //默认属性
31 static defaultProps = {
32 maxLength: 100,
33 showCount: true,
34 minHeight: defaultMinHeight
35 };
36
37 //构造函数
38 constructor(props) {
39 super(props);
40 //状态机变量声明
41 this.state = {
42 text: '',
43 };
44 }
45
46 //渲染
47 render() {
48 return (
49 <View style={ainer}>
50 <View style={[styles.inputViewStyle,this.props.style,{minHeight:this.props.minHeight}]}>
51 <TextInput
52 style={[styles.inputTextStyle,this.props.inputStyle,{minHeight:this.props.minHeight}]}
53 placeholder={this.props.placeholder ? this.props.placeholder :'请输入'}
54 multiline={true}
55 paddingVertical={0}
56 selectionColor = {'#b2b2b2'}
57 textAlignVertical={'top'}
58 placeholderTextColor={'#b2b2b2'}
59 underlineColorAndroid={'transparent'}
60 maxLength={this.props.maxLength}
61 defaultValue = {}
62 onChangeText={
63 (text) => {
64 ChangeText(text)
65 this.setState({
66 text: text
67 })
68 }
69 }
70 />
71 {
72 this.props.showCount ?
73 <Text style={{position: 'absolute', bottom: 5, right: 10, fontSize: 14}}>
74 {length}/{this.props.maxLength}
75 </Text>
76 :
77 null
78 }
79 </View>
80 </View>
81 );
82 }
83 };
84
85 const styles = ate({
86 container: {
87 flex: 1,
88 alignItems: 'center',
89 backgroundColor: '#FFFFFF',
90 },
91 inputViewStyle: {
92 width:ScreenWidth - 40,
93 minHeight: defaultMinHeight,
94 },
95 inputTextStyle: {
96 fontSize: 14,
97 color: '#666666',
98 width: '100%',
99 minHeight: defaultMinHeight,
100 padding: 10,
101 paddingBottom: 30,
102 paddingTop: 10
103 }
104 });
转载于:.html
本文发布于:2024-02-03 00:10:37,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170689023947374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
| 留言与评论(共有 0 条评论) |