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 ...
随机推荐
- java虚拟机学习总结之GC回收算法与GC收集器
GC回收算法 1.标记清除算法分为标记阶段和清除阶段标记阶段:通过特定的判断方式找出无用的对象实例并将其标记清除阶段:将已标记的对象所占用的内存回收缺点:运行多次以后容易产生空间碎片,当需要一整段连续 ...
- vue点击除了某组件本身的其它地方, 隐藏该组件的方法
点击emoji表情标签, 出现标签组件,点击其它地方, 改组件消失的效果; <template> <div class="writeZoon"> <d ...
- yaf框架安装
第一步:明白yaf框架是以扩展的形式要先配置到php里面,对于windows系统的使用者,首先要去官网:http://code.google.com/p/yafphp/downloads/list如果 ...
- [LeetCode] 135. 分发糖果
题目链接 : https://leetcode-cn.com/problems/candy/ 题目描述: 老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分 ...
- 小白如何入门 Python 爬虫?
本文针对初学者,我会用最简单的案例告诉你如何入门python爬虫! 想要入门Python 爬虫首先需要解决四个问题 熟悉python编程 了解HTML 了解网络爬虫的基本原理 学习使用python爬虫 ...
- 似乎在梦中见过的样子 (KMP)
# 10047. 「一本通 2.2 练习 3」似乎在梦中见过的样子 [题目描述] 「Madoka,不要相信 QB!」伴随着 Homura 的失望地喊叫,Madoka 与 QB 签订了契约. 这是 Mo ...
- Restful风格API中用put还是post做新增操作有什么区别?
Restful风格API中用put还是post做新增操作有什么区别? 转 头条面试归来,有些话想和Java开发者说!>>> 这个是华为面试官问我的问题,回来我找了很多资料,想验证这个 ...
- SpringBoot_03mybatisPlus
注意: mybatisPlus默认加载resources下的mapper文件夹下的xml文件 默认将数据库表的字段用驼峰标识转换成实体类的属性 官方网站: https://mp.baomidou.co ...
- 修改默认select样式
<style type="text/css"> .select_demo,.select_list { width: 400px; height: 60px; } .s ...
- 从零开始学MySQL(四)
上节连接:https://www.cnblogs.com/RajXie/p/10880809.html 上节说到,在创建表的同时,需要给出列的定义.列的定义可展开如下: 列名 列的数据类型 列的一些其 ...