React Native商城项目实战16 - 购物中心详细页
逻辑分析:
首页(Home)加载的购物中心组件(ShopCenter),传递url数据;
ShopCenter里根据url加载购物中心详细页组件(ShopCenterDetail),
ShopCenterDetail中利用WebView展示。
1.Home.js
- /**
- * 首页
- */
- import React, { Component } from 'react';
- import {
- AppRegistry,
- StyleSheet,
- Text,
- View,
- TouchableOpacity,
- TextInput,
- Image,
- Platform,
- ScrollView
- } from 'react-native';
- var Dimensions = require('Dimensions');
- var screenW = Dimensions.get('window').width;
- var screenH = Dimensions.get('window').height;
- /*======导入外部组件类======*/
- var HomeDetail = require('./HomeDetail');
- var TopView = require('./HomeTopView');
- var MiddleView = require('./HomeMiddleView');
- var MiddleBottom = require('./MiddleBottomView');
- var ShopCenter = require('./ShopCenter');
- var ShopCenterDetail = require('./ShopCenterDetail');
- // ES5
- var Home = React.createClass({
- render() {
- return (
- <View style={styles.container}>
- {/*首页的导航条*/}
- {this.renderNavBar()}
- {/*首页主要内容*/}
- <ScrollView>
- {/*头部的View*/}
- <TopView />
- {/*中间上部分的view*/}
- <MiddleView />
- {/*中间下部分内容*/}
- <MiddleBottom
- popTopHome={(data)=>{this.pushToDetail(data)}}
- />
- {/*购物中心*/}
- <ShopCenter
- popToHomeView={(url)=>this.pushToShopCenterDetail(url)}
- />
- </ScrollView>
- </View>
- );
- },
- // 首页的导航条
- renderNavBar(){
- return(
- <View style={styles.navBarStyle}>
- <TouchableOpacity onPress={()=>{this.pushToDetail()}} >
- <Text style={styles.leftTitleStyle}>宁波</Text>
- </TouchableOpacity>
- <TextInput placeholder="输入商家,品类,商圈" style={styles.topInputStyle} />
- <View style={styles.rightNavViewStyle}>
- <TouchableOpacity onPress={()=>{alert('点击了')}} >
- <Image source={{uri:'icon_homepage_message'}} style={styles.navRightImgStyle} />
- </TouchableOpacity>
- <TouchableOpacity onPress={()=>{alert('点击了')}} >
- <Image source={{uri:'icon_homepage_scan'}} style={styles.navRightImgStyle} />
- </TouchableOpacity>
- </View>
- </View>
- )
- },
- // 跳转到首页详细页
- pushToDetail(data){
- this.props.navigator.push({
- component:HomeDetail, // 要跳转过去的组件
- title:'首页详细页'
- });
- },
- // 跳转到购物中心详细页
- pushToShopCenterDetail(url){
- this.props.navigator.push({
- component:ShopCenterDetail, // 要跳转过去的组件
- passProps:{'url':this.dealWithImgUrl(url)}, // 传递数据到下一个界面
- });
- },
- // URL处理函数
- dealWithImgUrl(url){
- return url.replace('imeituan://www.meituan.com/web/?url=','');
- },
- });
- const styles = StyleSheet.create({
- // 导航栏
- navBarStyle:{
- height:Platform.OS === 'ios' ? 64 : 44,
- backgroundColor:'rgba(255,96,0,1)',
- // 主轴方向
- flexDirection:'row',
- // 侧轴对齐方式 垂直居中
- alignItems:'center',
- // 主轴对齐方式
- justifyContent:'space-around', // 平均分布
- },
- // 导航条左侧文字
- leftTitleStyle:{
- color:'white',
- fontSize:16,
- },
- // 导航栏输入框
- topInputStyle:{
- width:screenW * 0.71,
- height:Platform.OS === 'ios' ? 35 : 30,
- backgroundColor:'white',
- marginTop:Platform.OS === 'ios' ? 18 : 0,
- // 圆角
- borderRadius:18,
- paddingLeft:10,
- },
- // 导航条右侧视图
- rightNavViewStyle:{
- flexDirection:'row',
- height:64,
- // 侧轴对齐方式
- alignItems:'center',
- // backgroundColor:'blue',
- },
- // 导航栏右侧图片
- navRightImgStyle:{
- width:Platform.OS === 'ios' ? 28 : 24,
- height:Platform.OS === 'ios' ? 28 : 24,
- },
- container: {
- flex: 1,
- backgroundColor: '#e8e8e8',
- },
- welcome: {
- fontSize: 20,
- textAlign: 'center',
- margin: 10,
- },
- });
- // 输出
- module.exports = Home;
2.ShopCenter.js
- /**
- * 首页购物中心
- */
- import React, { Component } from 'react';
- import {
- AppRegistry,
- StyleSheet,
- Text,
- View,
- ScrollView,
- Image,
- TouchableOpacity
- } from 'react-native';
- // 导入外部组件类
- var TitleView = require('./TitleCommonCell');
- // 导入json数据
- var Home_D5 = require('../../LocalData/XMG_Home_D5.json');
- // ES5
- var ShopCenter = React.createClass({
- getDefaultPorps(){
- return{
- popToHomeView:null, // 回调函数
- }
- },
- render() {
- return (
- <View style={styles.container}>
- <TitleView
- leftIcon="gw"
- leftTitle="购物中心"
- rightTitle={Home_D5.tips}
- />
- <ScrollView
- style={styles.scrollViewStyle}
- horizontal={true}
- showsHorizontalScrollIndicator={false}
- >
- {this.renderAllItem()}
- </ScrollView>
- </View>
- );
- },
- // 返回所有item
- renderAllItem(){
- var itemArr = [];
- var shopData = Home_D5.data;
- for (var i=0;i<shopData.length;i++){
- var data = shopData[i];
- itemArr.push(
- <ShopCenterItem
- key={i}
- shopImage={data.img}
- shopSale={data.showtext.text}
- shopName={data.name}
- detailurl={data.detailurl}
- popToShopCenter={(url)=>this.popTopHome(url)}
- />
- )
- }
- return itemArr;
- },
- // 返回首页
- popTopHome(url){
- if(this.props.popToHomeView != null){
- this.props.popToHomeView(url);
- }
- }
- });
- // 每一个商场
- var ShopCenterItem = React.createClass({
- getDefaultProps(){
- return{
- shopImage:'',
- shopSale:'',
- shopName:'',
- detailurl:'',
- popToShopCenter:null
- }
- },
- render() {
- return (
- <TouchableOpacity activeOpacity={0.8} onPress={()=>this.clickItem(this.props.detailurl)}>
- <View style={styles.itemViewStyle}>
- <Image source={{uri:this.props.shopImage}} style={styles.imageStyle}/>
- <Text style={styles.shopSaleStyle}>{this.props.shopSale}</Text>
- <Text style={styles.shopNameStyle}>{this.props.shopName}</Text>
- </View>
- </TouchableOpacity>
- );
- },
- // 点击事件
- clickItem(url){
- if(this.props.detailurl != null){
- this.props.popToShopCenter(url);
- }
- },
- });
- const styles = StyleSheet.create({
- container: {
- marginTop:10,
- },
- scrollViewStyle:{
- flexDirection:'row',
- backgroundColor:'white',
- padding:10,
- },
- itemViewStyle:{
- margin:8,
- },
- imageStyle:{
- width:120,
- height:100,
- borderRadius:8,
- },
- shopSaleStyle:{
- // 定位
- position:'absolute',
- left:0,
- bottom:30,
- backgroundColor:'red',
- color:'white',
- padding:3,
- },
- shopNameStyle:{
- textAlign:'center',
- marginTop:5,
- },
- });
- // 输出
- module.exports = ShopCenter;
3.ShopCenterDetail.js
- /**
- * 购物中心详情
- */
- import React, { Component } from 'react';
- import {
- AppRegistry,
- StyleSheet,
- Text,
- View,
- Platform,
- Image,
- TouchableOpacity,
- WebView
- } from 'react-native';
- // ES5
- var ShopCenterDetail = React.createClass({
- getInitialState(){
- return{
- detailUrl: this.props.url
- }
- },
- render() {
- return (
- <View style={styles.container}>
- {this.renderNavBar()}
- <WebView
- automaticallyAdjustContentInsets={true}
- source={{uri: this.state.detailUrl}}
- javaScriptEnabled={true}
- decelerationRate="normal"
- startInLoadingState={true}
- />
- </View>
- );
- },
- // 导航条
- renderNavBar(){
- return(
- <View style={styles.navOutViewStyle}>
- <TouchableOpacity activeOpacity={0.8} onPress={()=>{this.props.navigator.pop()}} style={styles.LeftViewStyle}>
- <Image source={{uri:'icon_camera_back_normal'}} style={styles.navImgStyle} />
- </TouchableOpacity>
- <Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>购物中心</Text>
- <TouchableOpacity style={styles.rightViewStyle}>
- <Image source={{uri:'icon_mine_setting'}} style={styles.navImgStyle} />
- </TouchableOpacity>
- </View>
- )
- }
- });
- const styles = StyleSheet.create({
- container: {
- flex:1,
- },
- // 导航条视图
- navOutViewStyle:{
- height:Platform.OS === 'ios' ? 64 : 44,
- backgroundColor:'rgba(255,96,0,1)',
- // 主轴方向
- flexDirection:'row',
- // 侧轴对齐方式 垂直居中
- alignItems:'center',
- // 主轴方向居中
- justifyContent:'center',
- },
- // 导航条左侧
- LeftViewStyle:{
- position:'absolute',
- left:10,
- bottom:15,
- },
- // 导航栏右侧
- rightViewStyle:{
- // 绝对定位
- position:'absolute',
- right:10,
- bottom:15,
- },
- // 导航条上图片
- navImgStyle:{
- width:Platform.OS === 'ios' ? 28 : 24,
- height:Platform.OS === 'ios' ? 28 : 24,
- },
- });
- // 输出
- module.exports = ShopCenterDetail;
4.效果图
React Native商城项目实战16 - 购物中心详细页的更多相关文章
- React Native商城项目实战15 - 首页购物中心
1.公共的标题栏组件TitleCommonCell.js /** * 首页购物中心 */ import React, { Component } from 'react'; import { AppR ...
- React Native商城项目实战14 - 首页中间下部分
1.MiddleBottomView.js /** * 首页中间下部分 */ import React, { Component } from 'react'; import { AppRegistr ...
- React Native商城项目实战13 - 首页中间上部分内容
1.HomeMiddleView.js /** * 首页中间上部分内容 */ import React, { Component } from 'react'; import { AppRegistr ...
- React Native商城项目实战12 - 首页头部内容
1.HomeTopView为首页头部内容,HomeTopListView为HomeTopView子视图. 2.HomeTopView.js /** * 首页头部内容 */ import React, ...
- React Native商城项目实战05 - 设置首页的导航条
1.Home.js /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Te ...
- React Native商城项目实战03 - 包装Navigator
1.在Home目录下新建首页详细页HomeDetail.js /** * 首页详情页 */ import React, { Component } from 'react'; import { App ...
- React Native商城项目实战04 - 封装TabNavigator.Item的创建
1.Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, View, Im ...
- React Native商城项目实战07 - 设置“More”界面导航条
1.More/More.js /** * 更多 */ import React, { Component } from 'react'; import { AppRegistry, StyleShee ...
- React Native商城项目实战02 - 主要框架部分(tabBar)
1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...
随机推荐
- mysql学习记录(一)
#打开MySQL服务 sudo service mysql start #Ubuntu Linux 安装配置MySQL #安装MySQL服务器,核心程序 sudo apt-get install my ...
- python列表,字典,集合
初识模块 import sys print(sys.path)#查看化境变量 print(sys.argv)#查看文件的相对路径,但是在pachrm中 会自动转为绝对路径 import os #os. ...
- 计算机系统结构总结_Memory Hierarchy and Memory Performance
Textbook: <计算机组成与设计——硬件/软件接口> HI <计算机体系结构——量化研究方法> QR 这是youtube上一个非常好的memory syst ...
- 剑指offer-用两个栈来实现一个队列-队列与栈-python
用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路:使用两个栈,stackA 用来接收node stackB 用来接收 stackA 的出栈 # -*- cod ...
- spring cloud zuul过滤器修改requestURI 忽略大小写
通过zuul网关处理requestURI可以做很多事情,如对uri的解密,转发,大小写转化等. 这里对URI做一个简单的大小写的转化. 写一个filter实现ZuulFilter: package c ...
- 【 React - 1/100 】React绑定事件this指向问题--改变state中的值
/** * 报错: * Cannot read property 'setState' of undefined * 原因: this指向不一致.btnAddCount中的this 和render中的 ...
- 15.Linux-CentOS系统重启网卡ping不通问题(云环境)
问题: CentOS系统网络不通,重启网卡后能ping通,等一会就又不通. 解决: 在云环境管理平台下,KVM系统的MAC地址,使其重新生成一下.
- SpringCloude学习脑图
SpringCloude学习脑图 http://naotu.baidu.com/file/3e619862813ac331c5d9806486771b42?token=1a7206b777280c6b
- gremlin语言语法--学习笔记
学习gremlin语言的目的:测试图数据,支持gremlin语句,所以必须系统学习一下!!!! 一.基础查询 g.V() 查询所有的顶点 g.V(3) 查询顶点id为3的点.字符串id的要到引号V(& ...
- Node.js企业开发:应用场景
要想用Node.js首先需要知道它到底是什么, 有哪些优缺点. 然后我们才能知道到底 Node.js 适合哪些应用场景. Node.js 维基百科:“Node.js 是谷歌 V8 引擎.libuv平台 ...