1.设置页面跳转

半小时热门组件  GDHalfHourHot.js

/*** 近半小时热门*/
import React, { Component } from 'react';
import {StyleSheet,Text,View,TouchableOpacity,Image,
} from 'react-native';// 引入自定义导航栏组件
import CommunalNavBar from '../main/GDCommunalNavBar';export default class GDHalfHourHot extends Component {// 返回中间按钮renderTitleItem() {return(<Text style={styles.navbarTitleItemStyle}>近半小时热门</Text>);}// 返回右边按钮renderRightItem() {return(<TouchableOpacity><Text style={styles.navbarRightItemStyle}>关闭</Text></TouchableOpacity>);}render() {return (<View style={styles.container}>{/* 导航栏样式 */}<CommunalNavBartitleItem = {() => this.renderTitleItem()}rightItem = {() => this.renderRightItem()}/></View>);}
}const styles = StyleSheet.create({container: {flex: 1,alignItems: 'center',backgroundColor: '#F5FCFF',},navbarTitleItemStyle: {fontSize:17,color:'black',marginLeft:50},navbarRightItemStyle: {fontSize:17,color:'rgba(123,178,114,1.0)',marginRight:15},
});

首页调用  GDHome.js

/*** 首页*/
import React, { Component } from 'react';
import {StyleSheet,Text,View,TouchableOpacity,Image,
} from 'react-native';// 引入自定义导航栏组件
import CommunalNavBar from '../main/GDCommunalNavBar';
// 引入 近半小时热门组件
import HalfHourHot from './GDHalfHourHot';export default class GDHome extends Component {// 跳转到近半小时热门pushToHalfHourHot() {// this.props 可以获取所有组件属性this.props.navigator.push({component: HalfHourHot,})}// 返回左边按钮renderLeftItem() {// 将组件返回出去return(<TouchableOpacityonPress={() => {this.pushToHalfHourHot()}}><Image source={{uri:'hot_icon_20x20'}} style={styles.navbarLeftItemStyle} /></TouchableOpacity>);}// 返回中间按钮renderTitleItem() {return(<TouchableOpacity><Image source={{uri:'navtitle_home_down_66x20'}} style={styles.navbarTitleItemStyle} /></TouchableOpacity>);}// 返回右边按钮renderRightItem() {return(<TouchableOpacity><Image source={{uri:'search_icon_20x20'}} style={styles.navbarRightItemStyle} /></TouchableOpacity>);}render() {return (<View style={styles.container}>{/* 导航栏样式 */}<CommunalNavBarleftItem = {() => this.renderLeftItem()}titleItem = {() => this.renderTitleItem()}rightItem = {() => this.renderRightItem()}/></View>);}
}const styles = StyleSheet.create({container: {flex: 1,alignItems: 'center',backgroundColor: '#F5FCFF',},navbarLeftItemStyle: {width:20,height:20,marginLeft:15,},navbarTitleItemStyle: {width:66,height:20,},navbarRightItemStyle: {width:20,height:20,marginRight:15,},
});

效果图:

  

2.先从 半小时热门 开始,像这样的数据展示,我们肯定是优先选择 ListView ,其中,cell 的样式分解如下:

GDCommunalHotCell.js

/*** 近半小时热门 cell*/
import React, { Component, PropTypes } from 'react';
import {StyleSheet,Text,View,Dimensions,Platform,Image,
} from 'react-native';// 获取屏幕宽高
const {width, height} = Dimensions.get('window');export default class GDCommunalHotCell extends Component {// 定义成员属性static propTypes = {image: PropTypes.string,  // 外部传字符串title: PropTypes.string,}render() {return (<View style={styles.container}>{/* 左边的图片 */}<Image source={{uri:this.props.image}} style={styles.imageStyle} />{/* 中间的文字 */}<View><Text numberOfLines={3} style={styles.titleStyle}>{this.props.title}</Text></View>{/* 右边的箭头 */}<Image source={{uri:'icon_cell_rightArrow'}} style={styles.arrowStyle} /></View>);}
}const styles = StyleSheet.create({container: {flexDirection:'row',alignItems:'center',justifyContent:'space-between',backgroundColor:'white',height:100,width:width,borderBottomWidth:0.5,borderBottomColor:'gray',marginLeft:15},imageStyle: {width:70,height:70,},titleStyle: {width:width*0.65,},arrowStyle: {width:10,height:10,marginRight:30}
});

在 GDHalfHourHot.js 引入组件

/*** 近半小时热门*/
import React, { Component } from 'react';
import {StyleSheet,Text,View,TouchableOpacity,Image,ListView,Dimensions,
} from 'react-native';// 获取屏幕宽高
const {width, height} = Dimensions.get('window');// 引入自定义导航栏组件
import CommunalNavBar from '../main/GDCommunalNavBar';
// 引入 cell
import CommunalHotCell from '../main/GDCommunalHotCell';export default class GDHalfHourHot extends Component {// 构造constructor(props) {super(props);// 初始状态this.state = {dataSource: new ListView.DataSource({rowHasChanged:(r1, r2) => r1 !== r2}), // 数据源 优化};// 绑定this.fetchData = this.fetchData.bind(this);}// 网络请求fetchData() {fetch('http://guangdiu.com/api/gethots.php')  // 请求地址.then((response) => response.json())  // 定义名称 将数据转为json格式.then((responseData) => { // 处理数据// 修改dataSource的值this.setState({dataSource: this.state.dataSource.cloneWithRows(responseData.data)});}).done() // 结束}popToHome() {this.props.navigator.pop();}// 返回中间按钮renderTitleItem() {return(<Text style={styles.navbarTitleItemStyle}>近半小时热门</Text>);}// 返回右边按钮renderRightItem() {return(<TouchableOpacity><Text style={styles.navbarRightItemStyle}>关闭</Text></TouchableOpacity>);}// 返回每一行cell的样式renderRow(rowData) {// 使用cell组件return(<CommunalHotCellimage={rowData.image}title={rowData.title}/>);}// 生命周期 组件渲染完成 已经出现在dom文档里componentDidMount() {// 请求数据this.fetchData();}render() {return (<View style={styles.container}>{/* 导航栏样式 */}<CommunalNavBartitleItem = {() => this.renderTitleItem()}rightItem = {() => this.renderRightItem()}/>{/* 商品列表 */}<ListViewdataSource={this.state.dataSource}  // 数据源 通过判断dataSource是否有变化,来判断是否要重新渲染、renderRow={this.renderRow}showsHorizontalScrollIndicator={false} // 隐藏水平线style={styles.listViewStyle}/></View>);}
}const styles = StyleSheet.create({container: {flex:1,alignItems: 'center',},navbarTitleItemStyle: {fontSize:17,color:'black',marginLeft:50},navbarRightItemStyle: {fontSize:17,color:'rgba(123,178,114,1.0)',marginRight:15},listViewStyle: {width:width,}
});

3.效果图

转载于:https://www.cnblogs.com/crazycode2/p/7429852.html

React-Native 之 GD (三)近半小时热门相关推荐

  1. oracle查询一小时内数据,ORACLE 查询近一天, 近半小时内的数据

    ORACLE 查询近一天, 近半小时内的数据 SELECT 字段 FROM 表名 WHERE 时间字段 BETWEEN SYSDATE-1 AND SYSDATE; // 查询一天内的数据 sysda ...

  2. Uber CEO亲自体验送外卖:三个半小时挣了106美元

    6月29日,Uber现任CEO达拉·科斯罗萨西在推特上说,上周末他花了部分时间在自家公司的UberEats(外卖)部门体验了外卖配送工作. UberEats类似于中国的美团和饿了么,不同的是他们的员工 ...

  3. 我如何为我的第一个自由客户构建第一个React Native应用程序

    by Charlie Jeppsson 查理·杰普森(Charlie Jeppsson) 我如何为我的第一个自由客户构建第一个React Native应用程序 (How I built my firs ...

  4. 最火移动端跨平台方案盘点:React Native、weex、Flutter

    本文原文由"恋猫月亮"原创发布,原题为<移动端跨平台开发的深度解析>,本次重新整理后,为了优化阅读体验,内容略有改动,感谢原作者的无私分享. 1.前言 跨平台一直是老生 ...

  5. React Native初探

    React Native初探 转自:博客园 叶小钗  前言 很久之前就想研究React Native了,但是一直没有落地的机会,我一直认为一个技术要有落地的场景才有研究的意义,刚好最近迎来了新的APP ...

  6. React Native Apps的最佳主题

    您是否对默认格式和无聊的应用程序感到厌倦? React Native主题可以帮助使您的应用美观. 应用主题或React Native模板可以帮助您单击按钮来创建杰作. 如果您想节省数百小时的开发工作, ...

  7. React Native资源汇总

    初级 入门 React Native for Android 接入实践 ReactNative调用Android原生模块 Native项目迁入React-Native过程中遇到的坑(0.4x版本) 从 ...

  8. 从 Android 到 React Native 开发(四、打包流程解析和发布为 Maven 库 )

    1.从 Android 到 React Native 开发(一.入门) 2.从 Android 到 React Native 开发(二.通信与模块实现) 3.从 Android 到 React Nat ...

  9. 半小时深刻理解React

    声明:本文来自腾讯增值产品部官方公众号小时光茶社,为CSDN原创投稿,未经许可,禁止任何形式的转载. 作者:左明,企鹅电竞前端团队leader,腾讯高级工程师.从事web开发超过8年,主导过微云web ...

最新文章

  1. python监控端口_python3 端口监控
  2. [转]C# 将类的内容写成JSON格式的字符串
  3. mysql学习笔记-insert扩展
  4. js滚动条下拉一定值_JS逆向 | 无限Debugger之淘大象
  5. 多项logistic回归系数解释_因变量无序多分类资料的logistic回归
  6. PHP导出excel文件的多种方式
  7. java制作主页,JSP教程基础篇之简单首页制作
  8. 黑苹果安装教程---联想G480安装懒人版10.9.5
  9. Blender建模(三)
  10. 共射极单管放大器的Multisim仿真实验
  11. 凸包旋转卡壳(andrew)
  12. HTTP就绪状态和HTTP状态码
  13. uni-app AppStore推广内购、SKPaymentTransactionObser
  14. 转:新浪给微米定下了哪些要求?
  15. ndk开发教程,Android工程师面试该怎么准备?真香!
  16. 华为p30自带浏览器 样式表命名为skin.css 里面的color样式不起作用
  17. mac os终端设置
  18. python处在哪个阶段_如何在学Python的过程中更好地成长技术
  19. 2021 百度指数采集工具与研究
  20. 数字签名算法及JAVA实现案例

热门文章

  1. debian 安装 php,Ubuntu/Debian上安装Nginx+php环境详细教程
  2. mindray心电监护仪使用说明_界面张力仪的使用步骤以及画面清晰度相关说明
  3. maven的pom文件出现Multiple annotations found at this line...,已解决
  4. 如何查看docker的内核版本_查看Linux内核版本的方法有几个?你也是这样操作吗?...
  5. 橱柜高度与身高对照表_170身高和橱柜高度对照表 详细解析
  6. 不染计算机演奏教程,全国计算机等级考试一级教程-第1章 计算机基础知识 .pdf...
  7. android面试 源码,Android面试题-onCreate源码都没看过,怎好意思说自己做android-Go语言中文社区...
  8. console查看对象结构
  9. 智能一代云平台(六):移动开发之Ionic研究
  10. 智能一代云平台(四):15年上半年维护过程中精彩小插曲