上一篇 react-native文章提到了TextInput组件对安卓的适配问题,因此对该组件进行封装很有必要。

文章地址  react native定报预披项目知识点总结

TextInput介绍

官网地址:

https://facebook.github.io/react-native/docs/textinput

附加中文网地址:https://reactnative.cn/docs/textinput/

TextInput是一个允许用户在应用中通过键盘输入文本的基本组件。本组件的属性提供了多种特性的配置,譬如自动完成、自动大小写、占位文字,以及多种不同的键盘类型(如纯数字键盘)等等。最简单的用法就是丢一个TextInput到应用里,然后订阅它的onChangeText事件来读取用户的输入。

'use strict';
import React, { Component } from 'react'
import PropTypes from 'prop-types'
//import rpx from '../util/unit' import {
TextInput,
StyleSheet,
Platform,
Dimensions
} from 'react-native' const deviceH = Dimensions.get('window').height
const deviceW = Dimensions.get('window').width const basePx = 750 function rpx(px) {
return px * deviceW / basePx
} export default class Input extends Component{
constructor(props) {
super(props)
}
static propTypes = {
value:PropTypes.string
}
shouldComponentUpdate(nextProps){
return Platform.OS !== 'ios' || (this.props.value === nextProps.value &&
(nextProps.defaultValue == undefined || nextProps.defaultValue == '' )) ||
(this.props.defaultValue === nextProps.defaultValue && (nextProps.value == undefined || nextProps.value == '' )); }
blur() {
this.refs.textInput.blur()
}
render() {
return (
<TextInput
ref="textInput"
placeholderTextColor='#ccc'
placeholder={'输入代码、名称或简拼'}
style={[styles.textInput,this.props.style]}
underlineColorAndroid="transparent"
{...this.props}
/>
)
}
}
const styles = StyleSheet.create({
textInput:{
height:rpx(60),
fontSize:rpx(30),
color:'#333',
backgroundColor:'#fff',
borderRadius:rpx(4),
paddingHorizontal:rpx(20),
paddingVertical: 0
}
})

https://blog.csdn.net/halo1416/article/details/82703503

备注:TextInput组件内容超出加省列号:ellipsizeMode = 'tail' numberOfLines = {1 }

注明:IOS下TextInput不能输入中文,需要加上

shouldComponentUpdate(nextProps){
return Platform.OS !== 'ios' || (this.props.value === nextProps.value &&
(nextProps.defaultValue == undefined || nextProps.defaultValue == '' )) ||
(this.props.defaultValue === nextProps.defaultValue && (nextProps.value == undefined || nextProps.value == '' )); }

关于shouldComponentUpdate 可参考文章:http://www.80iter.com/blog/1512370656110845

最新文章

  1. Linux 硬盘分区生效命令partprobe
  2. EXT总结例子
  3. 【BZOJ-2668】交换棋子 最小费用最大流
  4. thinkPHP CRUD操作
  5. Libliner 中的-s 参数选择:primal 和dual
  6. iOS开发——UI基础-提示框
  7. ado.net 修改,查询
  8. Atom Remote-FTP connecting FTP with SSL/TLS
  9. XP下Winform背景透明问题
  10. SQL SERVER全面优化
  11. 使用jcrop进行头像剪切
  12. java中File类的常用所有方法及其应用
  13. Java中的switch语句后面的控制表达式的数据类型
  14. Dynamics CRM2015 Update1 新功能之表单增强功能
  15. 谈ObjC对象的两段构造模式
  16. 动态改变swiper的属性
  17. cmd命令行编码设置
  18. redis在linux下的安装和配置
  19. ubuntu安装软件包apt-get和dpkg方法
  20. 百度地图API图标、文本、图例与连线

热门文章

  1. SpringBoot2 application.properties方式加载配置文件
  2. 如何将数据库中的值经过servlet传入到jsp页面,并且用EL表达式显示出值
  3. VSCode瞎折腾记
  4. java.sql.SQLException: The server time zone value &#39;???&#250;&#177;&#234;&#215;??&#177;??&#39; is unrecognized or represents more than one time zone.
  5. SQL实验一
  6. 中国移动能力开放商店OneNET View数据可视化公测 10分钟轻便生成行业可视化界面
  7. 【心得】Lattice和Xilinx工具关键特性对比(Diamond、ISE)
  8. 第二章 Python基本图形绘制
  9. 利用 keras_proprecessing.image 扩增自己的遥感数据(多波段)
  10. Photoshop实例视频教程