热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ReactNative之GD(十五)搜索模块及设置模块

1.搜索模块GDSearch.js***搜索页面*importReact,{Component}fromreact;import{StyleSheet,Text,View,To

1.搜索模块

GDSearch.js

/*** 搜索页面*/
import React, { Component } from 'react';
import {StyleSheet,Text,View,TouchableOpacity,Image,ListView,Dimensions,ActivityIndicator,Modal, // 模态AsyncStorage, // 缓存数据库(数据持久化)TextInput, // 输入框组件
} from 'react-native';// 引入 下拉刷新组件
import {PullList} from 'react-native-pull';
// 导航器
import CustomerComponents, {Navigator
} from 'react-native-deprecated-custom-components';// 获取屏幕宽高
const {width, height} = Dimensions.get('window');
// 监听 键盘函数
const dismissKeyboard = require('dismissKeyboard');// 引入自定义导航栏组件
import CommunalNavBar from '../main/GDCommunalNavBar';
// 引入 公共cell
import CommunalCell from '../main/GDCommunalCell';
// 引入 详情页 组件
import CommunalDetail from '../main/GDCommunalDetail';
// 引入 空白页组件
import NoDataView from '../main/GDNoDataView';export default class GDSearch extends Component {// 构造constructor(props) {super(props);// 初始状态this.state = {dataSource: new ListView.DataSource({rowHasChanged:(r1, r2) => r1 !== r2}), // 数据源 优化loaded: false, // 用于判断是否显示空白页isModal: false, // 用于判断模态的可见性};// 全局定义一个空数组用于存储列表数据this.data = [];this.changeText = '';// 绑定this.loadData = this.loadData.bind(this);this.loadMore = this.loadMore.bind(this);}// 加载最新数据网络请求loadData(resolve) {if (!this.changeText) return;let params = {"q" : this.changeText};HTTPBase.get('http://guangdiu.com/api/getresult.php', params).then((responseData) => {// 情况数组(刷新时)this.data = [];// 拼接数据this.data = this.data.concat(responseData.data);// 重新渲染this.setState({dataSource: this.state.dataSource.cloneWithRows(this.data),loaded:true,});// 关闭刷新动画if (resolve !== undefined){setTimeout(() => {resolve();}, 1000);}// 存储数组中最后一个元素的idlet searchLastID = responseData.data[responseData.data.length - 1].id;AsyncStorage.setItem('searchLastID', searchLastID.toString());}).catch((error) => {})}// 加载更多数据的网络请求loadMoreData(value) {let params = {"q" : this.changeText,"sinceid" : value};HTTPBase.get('http://guangdiu.com/api/getresult.php', params).then((responseData) => {// 拼接数据this.data = this.data.concat(responseData.data);this.setState({dataSource: this.state.dataSource.cloneWithRows(this.data),loaded:true,});// 存储数组中最后一个元素的idlet searchLastID = responseData.data[responseData.data.length - 1].id;AsyncStorage.setItem('searchLastID', searchLastID.toString());}).catch((error) => {})}// 加载更多数据操作loadMore() {// 读取idAsyncStorage.getItem('searchLastID').then((value) => {// 数据加载操作this.loadMoreData(value);})}// 返回上一页pop() {// 回收键盘dismissKeyboard();this.props.navigator.pop();}// 返回左边按钮renderLeftItem() {// 将组件返回出去return( {this.pop()}}>返回);}// 返回中间按钮renderTitleItem() {return(搜索全网折扣);}// ListView尾部renderFooter() {return ();}// 根据网络状态决定是否渲染 listViewrenderListView() {if(this.state.loaded === false) {// 显示空白页return();}else{return( this.loadData(resolve)}// 数据源 通过判断dataSource是否有变化,来判断是否要重新渲染dataSource={this.state.dataSource} renderRow={this.renderRow.bind(this)}// 隐藏水平线showsHorizontalScrollIndicator={false}style={styles.listViewStyle}initialListSize={7} // 默认渲染数据条数// 返回 listView 头部renderHeader={this.renderHeader}// 上拉加载更多onEndReached={this.loadMore}onEndReachedThreshold={60}renderFooter={this.renderFooter}/>);}}// 通过id 跳转详情页pushToDetail(value) {this.props.navigator.push({component:CommunalDetail,params: {url: 'https://guangdiu.com/api/showdetail.php' + '?' + 'id=' + value}})}// 返回每一行cell的样式renderRow(rowData) {// 使用cell组件return( this.pushToDetail(rowData.id)}>);}render() {return ({/* 导航栏样式 */} this.renderLeftItem()}titleItem = {() => this.renderTitleItem()}/>{/* 顶部工具栏 */}{/* 左边 */} {this.changeText = text}} // 监听文本改变,将文字返回onEndEditing={() => this.loadData()} // 结束编辑状态/>{/* 右边 */} this.pop()}>取消{/* 根据网络状态决定是否渲染 listview */}{this.renderListView()});}
}const styles = StyleSheet.create({container: {flex: 1,alignItems: 'center',},navbarLeftItemStyle: {width:20,height:20,marginLeft:15,},navbarTitleItemStyle: {fontSize:17,color:'black',marginRight:50},toolsViewStyle: {width:width,height:44,flexDirection:'row',alignItems:'center',justifyContent:'space-between',},inputViewStyle: {height:35,flexDirection:'row',alignItems:'center',justifyContent:'center',backgroundColor:'rgba(239,239,241,1.0)',marginLeft:10,borderRadius:5},searchImageStyle: {width:15,height:15,marginLeft:8},textInputStyle: {width:width * 0.75,height:35,marginLeft:8},listViewStyle: {width:width,},
});

 

监听 键盘函数

// 监听 键盘函数
const dismissKeyboard = require('dismissKeyboard');// 返回上一页
pop() {// 回收键盘dismissKeyboard();this.props.navigator.pop();
}

 

效果图:

 

2.设置模块

GDSettings.js

/*** 设置页面*/
import React, { Component } from 'react';
import {StyleSheet,Text,View,Image,TouchableOpacity,ScrollView,
} from 'react-native';// 引入自定义导航栏组件
import CommunalNavBar from '../main/GDCommunalNavBar';
// 引入 设置页 Cell组件
import SettingsCell from './GDSettingsCell';export default class GDSettings extends Component {// 返回上一页pop() {this.props.navigator.pop();}// 返回左边按钮renderLeftItem() {// 将组件返回出去return( {this.pop()}}>返回);}// 返回中间按钮renderTitleItem() {return(设置);}render() {return({/* 导航栏样式 */} this.renderLeftItem()}titleItem = {() => this.renderTitleItem()}/>{/* 内容 */}{/* 第一个cell */}{/* 第二个cell */})}
}const styles = StyleSheet.create({container: {flex:1},navbarLeftItemStyle: {width:20,height:20,marginLeft:15,},navbarTitleItemStyle: {fontSize:17,color:'black',marginRight:50},scollViewStyle: {backgroundColor:'white',},
});

 

GDSettingsCell.js

/*** 设置页 Cell*/
import React, { Component, PropTypes } from 'react';
import {StyleSheet,View,Image,Text,Switch,Platform,
} from 'react-native';export default class GDSettingsCell extends Component {static propTypes = {leftTitle:PropTypes.string,isShowSwitch:PropTypes.bool,};// 构造constructor(props) {super(props);// 初始状态this.state = {isOn:false,};}// 返回需要的组件renderRightContent() {let component;if (this.props.isShowSwitch) { // 显示 Switch 按钮component = {this.setState({isOn: !this.state.isOn})}} />}else {component = }return(component)}render() {return({/* 左边 */}{this.props.leftTitle}{/* 右边 */}{this.renderRightContent()})}
}const styles = StyleSheet.create({container: {flex:1,flexDirection:'row',height:Platform.OS === 'ios' ? 44 : 36,justifyContent:'space-between',alignItems:'center',borderBottomColor:'gray',borderBottomWidth:0.5,marginLeft:15,},rightViewStyle:{marginRight:15,},arrowStyle: {width:10,height:10,}
});

效果图:

.



推荐阅读
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
  • {moduleinfo:{card_count:[{count_phone:1,count:1}],search_count:[{count_phone:4 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • 本文介绍了一个React Native新手在尝试将数据发布到服务器时遇到的问题,以及他的React Native代码和服务器端代码。他使用fetch方法将数据发送到服务器,但无法在服务器端读取/获取发布的数据。 ... [详细]
  • python3 nmap函数简介及使用方法
    本文介绍了python3 nmap函数的简介及使用方法,python-nmap是一个使用nmap进行端口扫描的python库,它可以生成nmap扫描报告,并帮助系统管理员进行自动化扫描任务和生成报告。同时,它也支持nmap脚本输出。文章详细介绍了python-nmap的几个py文件的功能和用途,包括__init__.py、nmap.py和test.py。__init__.py主要导入基本信息,nmap.py用于调用nmap的功能进行扫描,test.py用于测试是否可以利用nmap的扫描功能。 ... [详细]
  • 本文概述了JNI的原理以及常用方法。JNI提供了一种Java字节码调用C/C++的解决方案,但引用类型不能直接在Native层使用,需要进行类型转化。多维数组(包括二维数组)都是引用类型,需要使用jobjectArray类型来存取其值。此外,由于Java支持函数重载,根据函数名无法找到对应的JNI函数,因此介绍了JNI函数签名信息的解决方案。 ... [详细]
  • 本文介绍了使用C++Builder实现获取USB优盘序列号的方法,包括相关的代码和说明。通过该方法,可以获取指定盘符的USB优盘序列号,并将其存放在缓冲中。该方法可以在Windows系统中有效地获取USB优盘序列号,并且适用于C++Builder开发环境。 ... [详细]
  • {moduleinfo:{card_count:[{count_phone:1,count:1}],search_count:[{count_phone:4 ... [详细]
author-avatar
mobiledu2502898253
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有