1.MiddleBottomView.js

/**
* 首页中间下部分
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity
} from 'react-native'; var Dimensions = require('Dimensions');
var screenW = Dimensions.get('window').width; // 导入json数据
var JsonData = require('../../LocalData/XMG_Home_D4.json'); // 导入外部组件
var CommonView = require('./MiddleCommonView'); // ES5
var MiddleBottom = React.createClass({
render() {
return (
<View style={styles.container}>
<View style={styles.topViewStyle}></View>
<View style={styles.bottomViewStyle}>
{this.renderBottomItem()}
</View>
</View>
);
}, renderBottomItem(){
var itemArr = [];
var dataArr = JsonData.data;
for (var i=0;i<dataArr.length;i++){
var data = dataArr[i];
itemArr.push(
<CommonView
key={i}
title={data.maintitle}
subTitle={data.deputytitle}
rightIcon={this.dealWithImgUrl(data.imageurl)}
titleColor={data.typeface_color}
/>
);
}
return itemArr;
}, // 处理图片url的方法
dealWithImgUrl(url){
if (url.search('w.h') == -1){ // 没有找到,正常返回
return url;
}else{
return url.replace('w.h', '120.90');
}
},
}); const styles = StyleSheet.create({
container: {
marginTop:10,
},
topViewStyle:{},
bottomViewStyle:{
flexDirection:'row',
// 换行
width:screenW,
flexWrap:'wrap',
justifyContent:'center',
alignItems:'center',
},
}); // 输出
module.exports = MiddleBottom;

2.用到的json数据

{
"stid": "720698155324449024",
"data": [{
"position": 0,
"typeface_color": "#ff9900",
"id": 7486,
"share": {
"message": "1元能吃肯德基",
"url": "http://i.meituan.com/firework/kfchanbao"
},
"title": "1元能吃肯德基",
"module": false,
"maintitle": "1元肯德基",
"tplurl": "imeituan://www.meituan.com/web?url=http://i.meituan.com/firework/kfchanbao",
"type": 1,
"imageurl": "http://p0.meituan.net/w.h/groupop/9aa35eed64db45aa33f9e74726c59d938450.png",
"solds": 0,
"deputytitle": "新用户专享"
}, {
"position": 0,
"typeface_color": "#f6687d",
"id": 15351,
"share": {
"message": "刷新颜值啦!领最高188元红包,更有疯狂立减ing~",
"url": "http://i.meituan.com/firework/beautyactivity0328"
},
"title": "4月开春大促",
"module": false,
"maintitle": "领21元红包",
"tplurl": "imeituan://www.meituan.com/web?url=http://i.meituan.com/firework/beautyactivity0328",
"type": 1,
"imageurl": "http://p0.meituan.net/w.h/groupop/b8fb2def2c0063c9acabed6cbf1c65449452.png",
"solds": 0,
"deputytitle": "小长假美美哒"
}, {
"position": 0,
"typeface_color": "#6bbd00",
"id": 15444,
"share": {
"message": "",
"url": "http://i.meituan.com/firework/160115xinyonghu?activity_id=611"
},
"title": "外卖0401-0417刘莉君新客",
"module": false,
"maintitle": "新用户专享",
"tplurl": "imeituan://www.meituan.com/web?url=http://i.meituan.com/firework/160115xinyonghu?activity_id=611",
"type": 1,
"imageurl": "http://p0.meituan.net/w.h/groupop/e1855577efd5280c905ab7a438b83f3d5000.png",
"solds": 0,
"deputytitle": "最高立减25元"
}, {
"position": 0,
"typeface_color": "#06c1ae",
"id": 15182,
"share": {
"message": "",
"url": "http://mpay.meituan.com/resource/oneyuan/deal-list.html?entry=home#deal-list/"
},
"title": "一元抢吧",
"module": false,
"maintitle": "一元抢吧",
"tplurl": "imeituan://www.meituan.com/web?url=http://mpay.meituan.com/resource/oneyuan/deal-list.html?entry=home#deal-list/",
"type": 1,
"imageurl": "http://p1.meituan.net/w.h/groupop/286f56222bac7bfd7462af56a64ce4a59032.png",
"solds": 0,
"deputytitle": "爆品抢到手软"
}],
"server": {
"time": 1459731016
},
"paging": {
"count": 5
}
}

3.Home.js 引入 MiddleBottom

/**
* 首页
*/
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'); // ES5
var Home = React.createClass({
render() {
return (
<View style={styles.container}>
{/*首页的导航条*/}
{this.renderNavBar()}
{/*首页主要内容*/}
<ScrollView>
{/*头部的View*/}
<TopView />
{/*中间上部分的view*/}
<MiddleView />
{/*中间下部分内容*/}
<MiddleBottom
popTopHome={(data)=>{this.pushToDetail(data)}}
/>
</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:'首页详细页'
});
},
}); 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;

  

4.效果图

React Native商城项目实战14 - 首页中间下部分的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. React Native商城项目实战01 - 初始化设置

    1.创建项目 $ react-native init BuyDemo 2.导入图片资源 安卓:把文件夹放到/android/app/src/main/res/目录下,如图: iOS: Xcode打开工 ...

  9. React Native商城项目实战16 - 购物中心详细页

    逻辑分析: 首页(Home)加载的购物中心组件(ShopCenter),传递url数据: ShopCenter里根据url加载购物中心详细页组件(ShopCenterDetail), ShopCent ...

随机推荐

  1. webpack e6转化成es5 配置方法

    方法一: https://www.babeljs.cn/setup#installation 按照babel官方的配置配 方法二: https://www.jianshu.com/p/ce28cedd ...

  2. HNUSTOJ-1253 Babelfish(字典树)

    1253: Problem C: Babelfish 时间限制: 1 Sec  内存限制: 128 MB提交: 14  解决: 3[提交][状态][讨论版] 题目描述 Problem C: Babel ...

  3. Jafka源码分析——网络架构

    在kafka中.每个broker都是一个server.依照一般理解,server就是一个SocketServer,其不断接收用户的请求并进行处理.在Java中进行网络连接有两种方式一种为堵塞模式一种为 ...

  4. 攻防世界--when_did_you_born5

    测试文件:https://adworld.xctf.org.cn/media/task/attachments/24937e95ca4744818feebe82ab96902d 1.准备 root@l ...

  5. git init error:Malformed value for push.default: simple

    git init error:Malformed value for push.default: simple 1.git config --global push.default matching

  6. MacOS X快捷键一览(http://www.cnblogs.com/ios8/p/Mac-OSX-keyword-cmd.html)

    ctrl+shift                                    快速放大dock的图标会暂时放大,而如果你开启了dock放大Command+Option+W         ...

  7. python基础知识的入门介绍

    一.什么是编程语言 任何词语都是一种高度的概括和总结,所以找关键字.如下: (1)1.什么是"语言":一个人与另一个人沟通的介质 2人将自己的思维逻辑和想法通过计算机能过识别的语言 ...

  8. <mvc:argument-resolvers> 自定义注解处理参数

    直接看引自: http://blog.csdn.net/u013160932/article/details/50609092

  9. 一、在 ASP.NET Core 中使用 SignalR

    一.介绍 SignalR 是一个用于实现实时网站的 Microsoft .NET 库.它使用多种技术来实现服务器与客户端间的双向通信,服务器可以随时将消息推送到连接的客户端. https://docs ...

  10. 10年前文章_ vi编辑器查找与替换方法

    vi编辑器查找与替换方法1.查找:/ 当前行往下找:? 当前行往上找找到后继续查找同方向 n反方向 N2.替换格式: range s/source/target/g解释:range表示要搜索的范围 & ...