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,和用于创建更 ...
随机推荐
- 2017年4月16日 一周AnswerOpenCV佳作赏析
2017年4月16日 一周AnswerOpenCV佳作赏析 1.HelloHow to smooth edge of text in binary image, based on threshold. ...
- 20145216史婧瑶《Java程序设计》第3周学习总结
20145216 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 4.1 类与对象 •对象(Object):存在的具体实体,具有明确的状态和行为 •类(Class) ...
- 20145321 《Java程序设计》第3周学习总结
20145321 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 4.1 类与对象 1.定义类:类定义时用关键词 class. 一个原始码中可以有多个类定义,但只能有一个公开 ...
- bzoj 3450: Tyvj1952 Easy
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 411 Solved: 309[Submit][Status][Discuss] Descriptio ...
- 那些年java MD5加密字符编码的坑
相信做过MD5加密的童鞋都遇到过字符编码的坑,一般加密出来的结果和其他人不一样都是字符编码不一致导致的,比如类文件的字符编码.浏览器的字符编码等和对方不一致,所以就需要转码统一字符. 以下是笔者转码过 ...
- [小问题笔记(八)] 常用SQL(读字段名,改字段名,打印影响行数,添加默认值,查找存储过程等)
读取所有字段,自然排序 declare @fields varchar(max) Select @fields=ISNULL(@fields,'')++name+',' from syscolumns ...
- 使用阿里云ECS安装HDFS的小问题
毕设涉及HDFS,理论看的感觉差不多了,想搭起来测试一下性能来验证以便进行开题报告,万万没想到装HDFS花费了许多天,踩了许多坑,记录一下. 背景:使用两台阿里云学生机ECS,分处不同账号不同区域,一 ...
- uva 1619 - Feel Good || poj 2796 单调栈
1619 - Feel Good Time limit: 3.000 seconds Bill is developing a new mathematical theory for human ...
- Android系统源代码
Android系统源代码 在线源码网站 1,http://androidxref.com 2,http://www.grepcode.com/ 3,http://www.androidos.net.c ...
- Java 类的构造器的调用顺序
规则如下: 对于一个复杂的对象,构建器的调用遵照下面的顺序: (1) 调用父类构建器.这个步骤会不断重复下去,首先得到构建的是分级结构的根部,然后是下一个子类,等等.直到抵达最深一层的子类. (2) ...