热门标签 | 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,}
});

效果图:

.



推荐阅读
  • 本文详细介绍了GetModuleFileName函数的用法,该函数可以用于获取当前模块所在的路径,方便进行文件操作和读取配置信息。文章通过示例代码和详细的解释,帮助读者理解和使用该函数。同时,还提供了相关的API函数声明和说明。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • 如何在HTML中获取鼠标的当前位置
    本文介绍了在HTML中获取鼠标当前位置的三种方法,分别是相对于屏幕的位置、相对于窗口的位置以及考虑了页面滚动因素的位置。通过这些方法可以准确获取鼠标的坐标信息。 ... [详细]
  • JavaScript和HTML之间的交互是经由过程事宜完成的。事宜:文档或浏览器窗口中发作的一些特定的交互霎时。能够运用侦听器(或处置惩罚递次来预订事宜),以便事宜发作时实行相应的 ... [详细]
  • React基础篇一 - JSX语法扩展与使用
    本文介绍了React基础篇一中的JSX语法扩展与使用。JSX是一种JavaScript的语法扩展,用于描述React中的用户界面。文章详细介绍了在JSX中使用表达式的方法,并给出了一个示例代码。最后,提到了JSX在编译后会被转化为普通的JavaScript对象。 ... [详细]
  • 本文详细介绍了Android中的坐标系以及与View相关的方法。首先介绍了Android坐标系和视图坐标系的概念,并通过图示进行了解释。接着提到了View的大小可以超过手机屏幕,并且只有在手机屏幕内才能看到。最后,作者表示将在后续文章中继续探讨与View相关的内容。 ... [详细]
  • wpf+mvvm代码组织结构及实现方式
    本文介绍了wpf+mvvm代码组织结构的由来和实现方式。作者回顾了自己大学时期接触wpf开发和mvvm模式的经历,认为mvvm模式使得开发更加专注于业务且高效。与此同时,作者指出mvvm模式相较于mvc模式的优势。文章还提到了当没有mvvm时处理数据和UI交互的例子,以及前后端分离和组件化的概念。作者希望能够只关注原始数据结构,将数据交给UI自行改变,从而解放劳动力,避免加班。 ... [详细]
  • node.jsurlsearchparamsAPI哎哎哎 ... [详细]
  • C语言自带的快排和二分查找
    Author🚹:CofCaiEmail✉️:cai.dongjunnexuslink.cnQQ😙:1664866311personalPage&#x ... [详细]
  • {moduleinfo:{card_count:[{count_phone:1,count:1}],search_count:[{count_phone:4 ... [详细]
  • 【爬虫】关于企业信用信息公示系统加速乐最新反爬虫机制
    ( ̄▽ ̄)~又得半夜修仙了,作为一个爬虫小白,花了3天时间写好的程序,才跑了一个月目标网站就更新了,是有点悲催,还是要只有一天的时间重构。升级后网站的层次结构并没有太多变化,表面上 ... [详细]
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社区 版权所有