前面使用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的使用实现搜索功能的更多相关文章

  1. React Native 组件之TextInput

    React Native 组件之TextInput类似于iOS中的UITextView或者UITextField,是作为一个文字输入的组件,下面的TextInput的用法和相关属性. /** * Sa ...

  2. 从零学React Native之11 TextInput

    TextInput 组件是用来通过键盘输入文字,可以使用View组件和Text组件样式,没有自己特定的样式. 与Text组件类似,TextInput组件内部的元素不再使用FlexBox布局,而采用文本 ...

  3. react native进阶

    一.前沿||潜心修心,学无止尽.生活如此,coding亦然.本人鸟窝,一只正在求职的鸟.联系我可以直接微信:jkxx123321 二.项目总结 **||**文章参考资料:1.  http://blog ...

  4. React Native 接入微博、微信、QQ 登录功能

    在 App 开发中我们经常需要在用户登录模块接入 SNS 登录组件,这样会大大提高用户的注册体验.特别当一个不是刚性需求 App 推广的时候,这样会很大的降低用户体验的成本,没有人愿意忍受输入邮箱.手 ...

  5. 教你轻松在React Native中集成统计(umeng)的功能(最新版)

    关于在react-native中快速集成umeng统计,网上的文章或者教程基本来自----贾鹏辉老师的文章http://www.devio.org/2017/09/03/React-Native-In ...

  6. React Native随笔——组件TextInput

    一.实例 先看一下我要做的搜索框的样子 需要一个Image,和一个TextInput 去掉默认下划线 underlineColorAndroid='transparent' 设置光标颜色 select ...

  7. (转)React Native 使用react-native-image-picker库实现图片上传功能

    react-native-image-picker作为一个集成相机和相册的功能的第三方库,因为其使用相对简单受到前端开发人员的喜爱. react-native-image-picker使用 首先,安装 ...

  8. [React Native]高度自增长的TextInput组件

    之前我们学习了从零学React Native之11 TextInput了解了TextInput相关的属性. 在开发中,我们有时候有这样的需求, 希望输入区域的高度随着输入内容的长度而增长, 如下: 这 ...

  9. React Native 学习笔记--进阶(二)--动画

    React Native 进阶(二)–动画 动画 流畅.有意义的动画对于移动应用用户体验来说是非常必要的.我们可以联合使用两个互补的系统:用于全局的布局动画LayoutAnimation,和用于创建更 ...

随机推荐

  1. [Linux 001]——计算机和操作系统的基础知识

    在正式开始学习 Linux 操作系统之前,有必要先回顾/学习一下计算机和操作系统的基本知识,为我们在后续的学习中铺路搭桥,在了解计算机一些基础原理的条件下再去进行学习,理解应该会更透彻一些.我会从一个 ...

  2. Seccon2017-pwn500-video_player

    感觉这个题目并不值500分,有些地方比较牵强,漏洞也比较明显,解题方法有多种,出题者把堆的布局随机化了,不过使用fastbin doublefree的话,可以完全忽视被打乱的堆. from pwn i ...

  3. Jquery11 动画效果

    学习要点: 1.显示.隐藏 2.滑动.卷动 3.淡入.淡出 4.自定义动画 5.列队动画方法 6.动画相关方法 7.动画全局属性 在以前很长一段时间里,网页上的各种特效还需要采用 flash 在进行. ...

  4. bzoj 3657 斐波那契数列(fib.cpp/pas/c/in/out)

    空间 512M  时限2s [题目描述] 有n个大于1的正整数a1,a2,…,an,我们知道斐波那契数列的递推式是f(i)=f(i-1)+f(i-2),现在我们修改这个递推式变为f(i)=f(i-1) ...

  5. keras安装配置指南【linux环境】【转】

    本文转载自:https://keras-cn.readthedocs.io/en/latest/for_beginners/keras_linux/#kerasmnist 本教程不得用于任何形式的商业 ...

  6. linux中__weak关键字的作用

    答:1.可以重新定义同名函数或变量而编译时不报错

  7. git 常用命令速查

    git 常用命令速查 命令速查表 一.克隆项目 把远程仓库上的项目克隆到本地.一般来说项目是有1个或2个分支,主要是做开发和线上的区别.既然所属分支不一样,那命令也会有一点区别.这里假设是有2个分支, ...

  8. SpringMVC封装表单数据

    1.domain类 package com.xiaostudy.domain; public class User { private int id; private String username; ...

  9. ubuntu16.04后续工作

    一.ruijie https://blog.csdn.net/u012217085/article/details/24369335 https://blog.csdn.net/Lv_Victor/a ...

  10. [小问题笔记(四)] Enum枚举类型转换为DataTable( C# )

    枚举: public enum ProductType { 小产品=, 大产品, 超大产品 } 转换方法: /// <summary> /// 枚举类型转化为DataTable /// & ...