React-Native进阶_7.TextInput的使用实现搜索功能
前面使用TabBar 实现了底部tab标签,通过stackNavigator 实现了页面跳转,接下来,使用TextInput 来实现一个搜索功能。
TextInput 属性比较多,不一一介绍,具体可以百度搜索或者结合源码。
下面介绍介个比较常用的属性
<TextInput style={{height:50}} placeholder ="搜索 ..."// = android EditText hint placeholderTextColor="#6435c9"// = hint color underlineColorAndroid='transparent'// 下划线透明 // clearButtonMode="while-editing" onChangeText={(query) =>{ this.setState({ query:query, loaded:false, });// 当内容改变时执行该方法 }} onSubmitEditing={this.fetchData.bind(this)} //secureTextEntry // onFocus={() =>console.log('onFocus')} //选中文本框 // onBlur={() =>console.log('onBlur')}//离开文本框 // onChange={() =>console.log('onChange')}//文本框内容变化 // onChangeText={(text) =>console.log(text)}//文本框内容变化,变化的内容 // onEndEditing={() =>console.log('onEndEditing')}//文本框编译结束 // onSubmitEditing={() =>console.log('onSubmitEditing')}//按下回车键 // autoFocus // defaultValue="火星救援" // autoCorrect={false} //editable={false} //keyboardType='url' web-search />
实现思路跟前面两个页面一样,集合TabBar 在主页面,添加第三个底部tab标签 搜索标签,搜索页面使用TextInput 实现输入框功能
输入框中输入能容点击回车 跳转到搜索结果列表页,由前面的 stackNavigator 实现 ,点击列表页,跳转到详情页,也是由stackNavigator实现。
const App = StackNavigator({ Main: {screen: SearchForm, navigationOptions: { title: "搜索", headerLeft: null, headerStyle:{ elevation: 0 }, headerTitleStyle:{ alignSelf:'center'}, },}, //搜索结果列表 SearchResult: {screen: SearchResult, navigationOptions:({navigation,screenProps}) =>({ headerTitle: navigation.state.params.title, } ) }, //详情页 Detail: {screen: MovieDetail, navigationOptions:({navigation,screenProps}) =>({ headerTitle: navigation.state.params.info, } ) }, });
展示UI跟前面的列表相同由ListView 实现。
render() { return ( <View style={styles.Container}> <TabNavigator> <TabNavigator.Item selected={this.state.selectedTab === 'home'} title="推荐电影" renderIcon={() => <Image source={TAB_NORMAL_1} style={styles.icon}/>} renderSelectedIcon={() => <Image source={TAB_PRESS_1} style={styles.icon}/>} badgeText="1" onPress={() => this.setState({selectedTab: 'home'})}> <Feature/> </TabNavigator.Item> <TabNavigator.Item selected={this.state.selectedTab === 'profile'} title="北美票房" renderIcon={() => <Image source={TAB_NORMAL_2} style={styles.icon}/>} renderSelectedIcon={() => <Image source={TAB_PRESS_2} style={styles.icon}/>} onPress={() => this.setState({selectedTab: 'profile'})}> <USBox/> </TabNavigator.Item> <TabNavigator.Item renderIcon={() => <Image source={{uri:icons.search}} style={styles.icon}/>} selected={this.state.selectedTab === 'search'} title="搜索" onPress={() => this.setState({selectedTab: 'search'})}> <Search/> </TabNavigator.Item> </TabNavigator> </View> ); }
UI效果展示:
React-Native进阶_7.TextInput的使用实现搜索功能的更多相关文章
- React Native 组件之TextInput
React Native 组件之TextInput类似于iOS中的UITextView或者UITextField,是作为一个文字输入的组件,下面的TextInput的用法和相关属性. /** * Sa ...
- 从零学React Native之11 TextInput
TextInput 组件是用来通过键盘输入文字,可以使用View组件和Text组件样式,没有自己特定的样式. 与Text组件类似,TextInput组件内部的元素不再使用FlexBox布局,而采用文本 ...
- react native进阶
一.前沿||潜心修心,学无止尽.生活如此,coding亦然.本人鸟窝,一只正在求职的鸟.联系我可以直接微信:jkxx123321 二.项目总结 **||**文章参考资料:1. http://blog ...
- React Native 接入微博、微信、QQ 登录功能
在 App 开发中我们经常需要在用户登录模块接入 SNS 登录组件,这样会大大提高用户的注册体验.特别当一个不是刚性需求 App 推广的时候,这样会很大的降低用户体验的成本,没有人愿意忍受输入邮箱.手 ...
- 教你轻松在React Native中集成统计(umeng)的功能(最新版)
关于在react-native中快速集成umeng统计,网上的文章或者教程基本来自----贾鹏辉老师的文章http://www.devio.org/2017/09/03/React-Native-In ...
- React Native随笔——组件TextInput
一.实例 先看一下我要做的搜索框的样子 需要一个Image,和一个TextInput 去掉默认下划线 underlineColorAndroid='transparent' 设置光标颜色 select ...
- (转)React Native 使用react-native-image-picker库实现图片上传功能
react-native-image-picker作为一个集成相机和相册的功能的第三方库,因为其使用相对简单受到前端开发人员的喜爱. react-native-image-picker使用 首先,安装 ...
- [React Native]高度自增长的TextInput组件
之前我们学习了从零学React Native之11 TextInput了解了TextInput相关的属性. 在开发中,我们有时候有这样的需求, 希望输入区域的高度随着输入内容的长度而增长, 如下: 这 ...
- React Native 学习笔记--进阶(二)--动画
React Native 进阶(二)–动画 动画 流畅.有意义的动画对于移动应用用户体验来说是非常必要的.我们可以联合使用两个互补的系统:用于全局的布局动画LayoutAnimation,和用于创建更 ...
随机推荐
- 20145328 《Java程序设计》实验五实验报告
20145328 <Java程序设计>实验五实验报告 实验名称 Java网络编程 实验内容 用书上的TCP代码,实现服务器与客户端. 客户端与服务器连接 客户端中输入明文,利用DES算法加 ...
- 20145240《网络对抗》PC平台逆向破解_advanced
PC平台逆向破解_advanced shellcode注入 Shellcode实际是一段代码(也可以是填充数据),是用来发送到服务器利用特定漏洞的代码,一般可以获取权限.另外,Shellcode一般是 ...
- STL学习笔记(不定期更新)
algorithm *1.sort() 用法:sort(数组名,名+长度(,cmp)); int cmp(T a,T b)//T是要排序的a,b的类型,也可以是结构体中任意成员变量 { return ...
- linux input输入子系统分析《四》:input子系统整体流程全面分析
1 input输入子系统整体流程 本节分析input子系统在内核中的实现,包括输入子系统(Input Core),事件处理层(Event Handler)和设备驱动层.由于上节代码讲解了设备 ...
- 定制Writable类
以IntWritable为例介绍,定制writable的步骤 //继承 WritableComparable接口(继承了writable接口和comparable接口) public class In ...
- Nagios监控mysql主从复制
因为公司的nagios用了很久监控项目很多,也在zabbix迁移中,也就先临时用nagios监控mysql主从了 mysql> show slave status\G 查看其输出,即可判定主从复 ...
- TeeChart.Direct2D.dll的使用
这个dll本身依赖于第三方的控件,SlimDX ,可以从 http://slimdx.org/ 下载. .net4.0的版本区分x86和x64 帧数的概念 我们通常说帧数,简单地说,就是在1秒钟时间 ...
- 迟到的thuwc&noiwc2018总结
已经4个多月没写博客了呢. thuwc和noiwc都炸了,接下来的一段时间都没怎么写题,靠文化课和游戏麻醉自己.这篇博客也算是向之前自闭.颓废的自己告别吧.. 先写一发游记: thuwc:Day1炸, ...
- 07_ZkClient提供的API使用
1. ZkClient API简介 zkclient是Github上一个开源的ZooKeeper客户端,在原生ZooKeeper API接口上进行包装,同时在内部实现了session超时重连,Watc ...
- 一个带展示的jsp上传控件模型
带展示上传控件的基本模型,无样式 jsp部分: <td> <form id="form1" enctype="multipart/form-data&q ...