逻辑分析: 
首页(Home)加载的购物中心组件(ShopCenter),传递url数据; 
ShopCenter里根据url加载购物中心详细页组件(ShopCenterDetail), 
ShopCenterDetail中利用WebView展示。

1.Home.js

  1. /**
  2. * 首页
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. TouchableOpacity,
  11. TextInput,
  12. Image,
  13. Platform,
  14. ScrollView
  15. } from 'react-native';
  16.  
  17. var Dimensions = require('Dimensions');
  18. var screenW = Dimensions.get('window').width;
  19. var screenH = Dimensions.get('window').height;
  20.  
  21. /*======导入外部组件类======*/
  22. var HomeDetail = require('./HomeDetail');
  23. var TopView = require('./HomeTopView');
  24. var MiddleView = require('./HomeMiddleView');
  25. var MiddleBottom = require('./MiddleBottomView');
  26. var ShopCenter = require('./ShopCenter');
  27. var ShopCenterDetail = require('./ShopCenterDetail');
  28.  
  29. // ES5
  30. var Home = React.createClass({
  31. render() {
  32. return (
  33. <View style={styles.container}>
  34. {/*首页的导航条*/}
  35. {this.renderNavBar()}
  36. {/*首页主要内容*/}
  37. <ScrollView>
  38. {/*头部的View*/}
  39. <TopView />
  40. {/*中间上部分的view*/}
  41. <MiddleView />
  42. {/*中间下部分内容*/}
  43. <MiddleBottom
  44. popTopHome={(data)=>{this.pushToDetail(data)}}
  45. />
  46. {/*购物中心*/}
  47. <ShopCenter
  48. popToHomeView={(url)=>this.pushToShopCenterDetail(url)}
  49. />
  50. </ScrollView>
  51. </View>
  52. );
  53. },
  54.  
  55. // 首页的导航条
  56. renderNavBar(){
  57. return(
  58. <View style={styles.navBarStyle}>
  59. <TouchableOpacity onPress={()=>{this.pushToDetail()}} >
  60. <Text style={styles.leftTitleStyle}>宁波</Text>
  61. </TouchableOpacity>
  62. <TextInput placeholder="输入商家,品类,商圈" style={styles.topInputStyle} />
  63. <View style={styles.rightNavViewStyle}>
  64. <TouchableOpacity onPress={()=>{alert('点击了')}} >
  65. <Image source={{uri:'icon_homepage_message'}} style={styles.navRightImgStyle} />
  66. </TouchableOpacity>
  67. <TouchableOpacity onPress={()=>{alert('点击了')}} >
  68. <Image source={{uri:'icon_homepage_scan'}} style={styles.navRightImgStyle} />
  69. </TouchableOpacity>
  70. </View>
  71. </View>
  72. )
  73. },
  74.  
  75. // 跳转到首页详细页
  76. pushToDetail(data){
  77. this.props.navigator.push({
  78. component:HomeDetail, // 要跳转过去的组件
  79. title:'首页详细页'
  80. });
  81. },
  82.  
  83. // 跳转到购物中心详细页
  84. pushToShopCenterDetail(url){
  85. this.props.navigator.push({
  86. component:ShopCenterDetail, // 要跳转过去的组件
  87. passProps:{'url':this.dealWithImgUrl(url)}, // 传递数据到下一个界面
  88. });
  89. },
  90.  
  91. // URL处理函数
  92. dealWithImgUrl(url){
  93. return url.replace('imeituan://www.meituan.com/web/?url=','');
  94. },
  95. });
  96.  
  97. const styles = StyleSheet.create({
  98. // 导航栏
  99. navBarStyle:{
  100. height:Platform.OS === 'ios' ? 64 : 44,
  101. backgroundColor:'rgba(255,96,0,1)',
  102. // 主轴方向
  103. flexDirection:'row',
  104. // 侧轴对齐方式 垂直居中
  105. alignItems:'center',
  106. // 主轴对齐方式
  107. justifyContent:'space-around', // 平均分布
  108. },
  109. // 导航条左侧文字
  110. leftTitleStyle:{
  111. color:'white',
  112. fontSize:16,
  113. },
  114. // 导航栏输入框
  115. topInputStyle:{
  116. width:screenW * 0.71,
  117. height:Platform.OS === 'ios' ? 35 : 30,
  118. backgroundColor:'white',
  119. marginTop:Platform.OS === 'ios' ? 18 : 0,
  120. // 圆角
  121. borderRadius:18,
  122. paddingLeft:10,
  123. },
  124. // 导航条右侧视图
  125. rightNavViewStyle:{
  126. flexDirection:'row',
  127. height:64,
  128. // 侧轴对齐方式
  129. alignItems:'center',
  130. // backgroundColor:'blue',
  131. },
  132. // 导航栏右侧图片
  133. navRightImgStyle:{
  134. width:Platform.OS === 'ios' ? 28 : 24,
  135. height:Platform.OS === 'ios' ? 28 : 24,
  136. },
  137. container: {
  138. flex: 1,
  139. backgroundColor: '#e8e8e8',
  140. },
  141. welcome: {
  142. fontSize: 20,
  143. textAlign: 'center',
  144. margin: 10,
  145. },
  146.  
  147. });
  148.  
  149. // 输出
  150. module.exports = Home;

  

2.ShopCenter.js

  1. /**
  2. * 首页购物中心
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. ScrollView,
  11. Image,
  12. TouchableOpacity
  13. } from 'react-native';
  14.  
  15. // 导入外部组件类
  16. var TitleView = require('./TitleCommonCell');
  17. // 导入json数据
  18. var Home_D5 = require('../../LocalData/XMG_Home_D5.json');
  19.  
  20. // ES5
  21. var ShopCenter = React.createClass({
  22. getDefaultPorps(){
  23. return{
  24. popToHomeView:null, // 回调函数
  25. }
  26. },
  27. render() {
  28. return (
  29. <View style={styles.container}>
  30. <TitleView
  31. leftIcon="gw"
  32. leftTitle="购物中心"
  33. rightTitle={Home_D5.tips}
  34. />
  35. <ScrollView
  36. style={styles.scrollViewStyle}
  37. horizontal={true}
  38. showsHorizontalScrollIndicator={false}
  39. >
  40. {this.renderAllItem()}
  41. </ScrollView>
  42. </View>
  43. );
  44. },
  45.  
  46. // 返回所有item
  47. renderAllItem(){
  48. var itemArr = [];
  49. var shopData = Home_D5.data;
  50. for (var i=0;i<shopData.length;i++){
  51. var data = shopData[i];
  52. itemArr.push(
  53. <ShopCenterItem
  54. key={i}
  55. shopImage={data.img}
  56. shopSale={data.showtext.text}
  57. shopName={data.name}
  58. detailurl={data.detailurl}
  59. popToShopCenter={(url)=>this.popTopHome(url)}
  60. />
  61. )
  62. }
  63. return itemArr;
  64. },
  65.  
  66. // 返回首页
  67. popTopHome(url){
  68. if(this.props.popToHomeView != null){
  69. this.props.popToHomeView(url);
  70. }
  71. }
  72. });
  73.  
  74. // 每一个商场
  75. var ShopCenterItem = React.createClass({
  76. getDefaultProps(){
  77. return{
  78. shopImage:'',
  79. shopSale:'',
  80. shopName:'',
  81. detailurl:'',
  82. popToShopCenter:null
  83. }
  84. },
  85. render() {
  86. return (
  87. <TouchableOpacity activeOpacity={0.8} onPress={()=>this.clickItem(this.props.detailurl)}>
  88. <View style={styles.itemViewStyle}>
  89. <Image source={{uri:this.props.shopImage}} style={styles.imageStyle}/>
  90. <Text style={styles.shopSaleStyle}>{this.props.shopSale}</Text>
  91. <Text style={styles.shopNameStyle}>{this.props.shopName}</Text>
  92. </View>
  93. </TouchableOpacity>
  94. );
  95. },
  96.  
  97. // 点击事件
  98. clickItem(url){
  99. if(this.props.detailurl != null){
  100. this.props.popToShopCenter(url);
  101. }
  102. },
  103. });
  104.  
  105. const styles = StyleSheet.create({
  106. container: {
  107. marginTop:10,
  108. },
  109. scrollViewStyle:{
  110. flexDirection:'row',
  111. backgroundColor:'white',
  112. padding:10,
  113. },
  114. itemViewStyle:{
  115. margin:8,
  116. },
  117. imageStyle:{
  118. width:120,
  119. height:100,
  120. borderRadius:8,
  121. },
  122. shopSaleStyle:{
  123. // 定位
  124. position:'absolute',
  125. left:0,
  126. bottom:30,
  127. backgroundColor:'red',
  128. color:'white',
  129. padding:3,
  130. },
  131. shopNameStyle:{
  132. textAlign:'center',
  133. marginTop:5,
  134. },
  135. });
  136.  
  137. // 输出
  138. module.exports = ShopCenter;

  

3.ShopCenterDetail.js

  1. /**
  2. * 购物中心详情
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Platform,
  11. Image,
  12. TouchableOpacity,
  13. WebView
  14. } from 'react-native';
  15.  
  16. // ES5
  17. var ShopCenterDetail = React.createClass({
  18. getInitialState(){
  19. return{
  20. detailUrl: this.props.url
  21. }
  22. },
  23. render() {
  24. return (
  25. <View style={styles.container}>
  26. {this.renderNavBar()}
  27. <WebView
  28. automaticallyAdjustContentInsets={true}
  29. source={{uri: this.state.detailUrl}}
  30. javaScriptEnabled={true}
  31. decelerationRate="normal"
  32. startInLoadingState={true}
  33. />
  34. </View>
  35. );
  36. },
  37. // 导航条
  38. renderNavBar(){
  39. return(
  40. <View style={styles.navOutViewStyle}>
  41. <TouchableOpacity activeOpacity={0.8} onPress={()=>{this.props.navigator.pop()}} style={styles.LeftViewStyle}>
  42. <Image source={{uri:'icon_camera_back_normal'}} style={styles.navImgStyle} />
  43. </TouchableOpacity>
  44. <Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>购物中心</Text>
  45. <TouchableOpacity style={styles.rightViewStyle}>
  46. <Image source={{uri:'icon_mine_setting'}} style={styles.navImgStyle} />
  47. </TouchableOpacity>
  48. </View>
  49. )
  50. }
  51. });
  52.  
  53. const styles = StyleSheet.create({
  54. container: {
  55. flex:1,
  56. },
  57. // 导航条视图
  58. navOutViewStyle:{
  59. height:Platform.OS === 'ios' ? 64 : 44,
  60. backgroundColor:'rgba(255,96,0,1)',
  61. // 主轴方向
  62. flexDirection:'row',
  63. // 侧轴对齐方式 垂直居中
  64. alignItems:'center',
  65. // 主轴方向居中
  66. justifyContent:'center',
  67. },
  68. // 导航条左侧
  69. LeftViewStyle:{
  70. position:'absolute',
  71. left:10,
  72. bottom:15,
  73. },
  74. // 导航栏右侧
  75. rightViewStyle:{
  76. // 绝对定位
  77. position:'absolute',
  78. right:10,
  79. bottom:15,
  80. },
  81. // 导航条上图片
  82. navImgStyle:{
  83. width:Platform.OS === 'ios' ? 28 : 24,
  84. height:Platform.OS === 'ios' ? 28 : 24,
  85. },
  86.  
  87. });
  88.  
  89. // 输出
  90. module.exports = ShopCenterDetail;

  

4.效果图

React Native商城项目实战16 - 购物中心详细页的更多相关文章

  1. React Native商城项目实战15 - 首页购物中心

    1.公共的标题栏组件TitleCommonCell.js /** * 首页购物中心 */ import React, { Component } from 'react'; import { AppR ...

  2. React Native商城项目实战14 - 首页中间下部分

    1.MiddleBottomView.js /** * 首页中间下部分 */ import React, { Component } from 'react'; import { AppRegistr ...

  3. React Native商城项目实战13 - 首页中间上部分内容

    1.HomeMiddleView.js /** * 首页中间上部分内容 */ import React, { Component } from 'react'; import { AppRegistr ...

  4. React Native商城项目实战12 - 首页头部内容

    1.HomeTopView为首页头部内容,HomeTopListView为HomeTopView子视图. 2.HomeTopView.js /** * 首页头部内容 */ import React, ...

  5. React Native商城项目实战05 - 设置首页的导航条

    1.Home.js /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Te ...

  6. React Native商城项目实战03 - 包装Navigator

    1.在Home目录下新建首页详细页HomeDetail.js /** * 首页详情页 */ import React, { Component } from 'react'; import { App ...

  7. React Native商城项目实战04 - 封装TabNavigator.Item的创建

    1.Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, View, Im ...

  8. React Native商城项目实战07 - 设置“More”界面导航条

    1.More/More.js /** * 更多 */ import React, { Component } from 'react'; import { AppRegistry, StyleShee ...

  9. React Native商城项目实战02 - 主要框架部分(tabBar)

    1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...

随机推荐

  1. mysql学习记录(一)

    #打开MySQL服务 sudo service mysql start #Ubuntu Linux 安装配置MySQL #安装MySQL服务器,核心程序 sudo apt-get install my ...

  2. python列表,字典,集合

    初识模块 import sys print(sys.path)#查看化境变量 print(sys.argv)#查看文件的相对路径,但是在pachrm中 会自动转为绝对路径 import os #os. ...

  3. 计算机系统结构总结_Memory Hierarchy and Memory Performance

    Textbook: <计算机组成与设计——硬件/软件接口>  HI <计算机体系结构——量化研究方法>       QR 这是youtube上一个非常好的memory syst ...

  4. 剑指offer-用两个栈来实现一个队列-队列与栈-python

    用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路:使用两个栈,stackA 用来接收node stackB 用来接收 stackA 的出栈 # -*- cod ...

  5. spring cloud zuul过滤器修改requestURI 忽略大小写

    通过zuul网关处理requestURI可以做很多事情,如对uri的解密,转发,大小写转化等. 这里对URI做一个简单的大小写的转化. 写一个filter实现ZuulFilter: package c ...

  6. 【 React - 1/100 】React绑定事件this指向问题--改变state中的值

    /** * 报错: * Cannot read property 'setState' of undefined * 原因: this指向不一致.btnAddCount中的this 和render中的 ...

  7. 15.Linux-CentOS系统重启网卡ping不通问题(云环境)

    问题: CentOS系统网络不通,重启网卡后能ping通,等一会就又不通. 解决: 在云环境管理平台下,KVM系统的MAC地址,使其重新生成一下.

  8. SpringCloude学习脑图

    SpringCloude学习脑图 http://naotu.baidu.com/file/3e619862813ac331c5d9806486771b42?token=1a7206b777280c6b

  9. gremlin语言语法--学习笔记

    学习gremlin语言的目的:测试图数据,支持gremlin语句,所以必须系统学习一下!!!! 一.基础查询 g.V() 查询所有的顶点 g.V(3) 查询顶点id为3的点.字符串id的要到引号V(& ...

  10. Node.js企业开发:应用场景

    要想用Node.js首先需要知道它到底是什么, 有哪些优缺点. 然后我们才能知道到底 Node.js 适合哪些应用场景. Node.js 维基百科:“Node.js 是谷歌 V8 引擎.libuv平台 ...