React Native商城项目实战10 - 个人中心中间内容设置
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 - 个人中心中间内容设置的更多相关文章
- React Native商城项目实战11 - 个人中心头部内容
1.创建MineHeaderView.js /** * 个人中心头部内容 */ import React, { Component } from 'react'; import { AppRegist ...
- React Native商城项目实战09 - 个人中心自定义cell
1.新建组件CommonMyCell.js /** * 个人中心自定义cell */ import React, { Component } from 'react'; import { AppReg ...
- React Native商城项目实战04 - 封装TabNavigator.Item的创建
1.Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, View, Im ...
- React Native商城项目实战01 - 初始化设置
1.创建项目 $ react-native init BuyDemo 2.导入图片资源 安卓:把文件夹放到/android/app/src/main/res/目录下,如图: iOS: Xcode打开工 ...
- React Native商城项目实战07 - 设置“More”界面导航条
1.More/More.js /** * 更多 */ import React, { Component } from 'react'; import { AppRegistry, StyleShee ...
- 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商城项目实战02 - 主要框架部分(tabBar)
1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...
- React Native商城项目实战16 - 购物中心详细页
逻辑分析: 首页(Home)加载的购物中心组件(ShopCenter),传递url数据: ShopCenter里根据url加载购物中心详细页组件(ShopCenterDetail), ShopCent ...
随机推荐
- spring boot @Transactional的一个小坑
同一个类Service下,有两个函数 method_1和 method_2,且method_1内部调用了method_2,那么希望method_2内部意外时,数据库回滚,那么一定要在method_1上 ...
- 使用CyclicBarrier+线程池,按总页数分批次开多线程执行逻辑
通过CyclicBarrier+线程池的方式,同步的方式分页分批次并发高效处理逻辑,将总页数分成多个批次并发执行每页逻辑,每个批次处理DO_MAX_SIZE个页,每个批次等待DO_MAX_SIZE个页 ...
- 使用before和after双伪元素清除浮动
使用方法: .clearfix:before,.clearfix:after { content:"."; display:table; } .clearfix:after { c ...
- Python 入门之Python简介
Python 入门之Python简介 1.Python简介: (1) Python的出生: python的创始人为吉多·范罗苏姆(Guido van Rossum)(中文名字:龟叔).1989年的 ...
- Android数据库使用指南(上)
前言Android上的数据库是sqlite,虽然这个数据库是轻量级的,但是储存的东西可不少,sqlite官方表示理论存储容量为140TB,目前应该没有那么大容量的手机,存储能力太强了. 关于如何使用S ...
- SSM框架返回json数据
常见错误:No converter found for return value of type: class .................. 原因分析:这是因为springmvc默认是没有对象 ...
- python之路之——操作系统的发展历史
阅读目录 手工操作 —— 穿孔卡片 批处理 —— 磁带存储和批处理系统 多道程序系统 分时系统 实时系统 通用操作系统 操作系统的进一步发展 操作系统的作用 手工操作 —— 穿孔卡片 1946年第一台 ...
- Linux学习--第二天--分区、格式化、系统安装、vmware、远程管理工具
分区 主分区加上扩展分区只能有四个,其中扩展分区只能有一个,扩展分区不能写入数据,不能格式化,只能包含逻辑分区.这是硬盘的限制. 格式化 分为高级与低级.文件系统是高级格式化.低级是硬盘操作. 扩展分 ...
- modesim 仿真问题
> unisim (ERROR: Library path "d:/Xilinx/14.3/ISE_DS/ISE//vhdl/mti_se/10.1a/nt64/unisim/unis ...
- ubuntu不能登陆
开机按shift,找到之前的内核版本或者recovery 安装vmtools 报错Not enough free space to extract VMwareTools 解决办法:将此文件夹复制到另 ...