1.新建一个MineMiddleView.js,专门用于构建中间的内容

/**
* 个人中心中间内容设置
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity
} from 'react-native'; /**-------导入外部的json数据-------***/
var MiddleData = require('./MiddleData.json'); var MineMiddleView = React.createClass({
render() {
return (
<View style={styles.container}>
{this.renderAllItem()}
</View>
);
}, renderAllItem(){
// 定义组件数组
var itemArr = [];
// 遍历
for(var i=0; i<MiddleData.length; i++){
// 取出单独的数据
var data = MiddleData[i];
// 创建组件装入数组
itemArr.push(
<InnerView key={i} iconName={data.iconName} title={data.title}/>
);
}
// 返回
return itemArr;
}
}); // 里面的组件类
var InnerView = React.createClass({
getDefaultProps(){
return{
iconName: '',
title:''
}
}, render(){
return(
<TouchableOpacity activeOpacity={0.5} onPress={()=>{alert('0')}}>
<View style={styles.innerViewStyle}>
<Image source={{uri: this.props.iconName}} style={{width:40, height:30, marginBottom:3}}/>
<Text style={{color:'gray'}}>{this.props.title}</Text>
</View>
</TouchableOpacity>
);
}
}); const styles = StyleSheet.create({
container: {
// 设置主轴的方向
flexDirection:'row',
alignItems: 'center',
backgroundColor: 'white',
// 设置主轴的对齐方式
justifyContent:'space-around'
}, innerViewStyle:{
width:70,
height:70, // 水平和垂直居中
justifyContent:'center',
alignItems:'center'
}
}); // 输出组件类
module.exports = MineMiddleView;

2.Mine.js里使用该组件

/**
* 我的
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
ScrollView
} from 'react-native'; /*======导入外部组件类======*/
var MyCell = require('./CommonMyCell');
var MiddleView = require('./MineMiddleView'); // ES5
var Mine = React.createClass({
render() {
return (
<ScrollView style={styles.scrollViewStyle}>
<View style={{marginTop:20}}>
<MyCell
leftIconName="collect"
leftTitle="我的订单"
rightTitle="查看全部订单"
/>
<MiddleView />
</View>
<View style={{marginTop:20}}>
<MyCell
leftIconName="draft"
leftTitle="钱包"
rightTitle="账号余额:¥100.88"
/>
</View>
<View style={{marginTop:20}}>
<MyCell
leftIconName="voucher"
leftTitle="抵用券"
rightTitle="10张"
/>
</View>
<View style={{marginTop:20}}>
<MyCell
leftIconName="mall"
leftTitle="积分商城"
rightTitle=""
/>
</View>
<View style={{marginTop:20}}>
<MyCell
leftIconName="recommend"
leftTitle="今日推荐"
rightTitle=""
/>
</View>
</ScrollView>
);
}
}); const styles = StyleSheet.create({
scrollViewStyle:{ }
}); // 输出
module.exports = Mine;

3.效果图

4.MiddleData.json

[
{"iconName":"order1", "title": "待付款"},
{"iconName":"order2", "title": "待使用"},
{"iconName":"order3", "title": "待评价"},
{"iconName":"order4", "title": "退款/售后"}
]

.

React Native商城项目实战10 - 个人中心中间内容设置的更多相关文章

  1. React Native商城项目实战11 - 个人中心头部内容

    1.创建MineHeaderView.js /** * 个人中心头部内容 */ import React, { Component } from 'react'; import { AppRegist ...

  2. React Native商城项目实战09 - 个人中心自定义cell

    1.新建组件CommonMyCell.js /** * 个人中心自定义cell */ import React, { Component } from 'react'; import { AppReg ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. MyBatis框架 课程笔记

    MyBatis框架 课程笔记   第1章 MyBatis简介 1.1 MyBatis历史 1)MyBatis是Apache的一个开源项目iBatis, 2010年6月这个项目由Apache Softw ...

  2. C++中的const分析

    1,C 语言中的 const: 1,const 修饰的变量是只读的,本质还是变量: 1,C 语言中的 const 使变量具有只读属性: 2,const 只在编译期有用,在运行期无用: 3,const ...

  3. Linux :环境变量设置和本地变量加载

    bash: 全局变量: /etc/profile,  /etc/profile.d/*,  /etc/bashrc 个人变量: ~/.bash_profile,   ~/.bashrc bash运行方 ...

  4. winform 窗体间传值

    WinForm 两窗体之间传值实例 2010-12-27 22:10:11|  分类: 学业|举报|字号 订阅     下载LOFTER我的照片书  |     窗体Form1和Form2 Form2 ...

  5. Windows 环境下安装redis 及其PHP Redis扩展

    1.安装Redis (1)这里选择在github官网上下载Redis,地址:Redis下载地址 下载压缩包(如下图),并解压到本地目录,我放在D:\redis (2)验证Redis安装是否成功打开命令 ...

  6. UDP即时小通信

    package 第十二章; import java.io.IOException; import java.net.*; public class UDPServer { /*** * * @para ...

  7. 基于TCP/UDP协议的socket

    基于TCP协议的socket tcp是基于链接的,必须先启动服务端,然后再启动客户端去链接服务端 server端 import socket sk = socket.socket() sk.bind( ...

  8. 写了一个简单可用的IOC

    根据<架构探险从零开始写javaweb框架>内容写的一个简单的 IOC 学习记录    只说明了主要的类,从上到下执行的流程,需要分清主次,无法每个类都说明,只是把整个主线流程说清楚,避免 ...

  9. [人工智能]IBM Watson人工智能API|一步步创建智能微信翻译官|第一章

    最近参加了IBM可认知内部创业活动,想从零创建一个微信翻译工具,这就是我的AI翻译官.

  10. linux 性能分析常用命令汇总

    CPU性能分析工具: vmstatpssartimestracepstreetop Memory(内存)性能分析工具:vmstatstracetopipcsipcrmcat /proc/meminfo ...