1.创建MineHeaderView.js

  1. /**
  2. * 个人中心头部内容
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity
  12. } from 'react-native';
  13.  
  14. // 导入系统类
  15. var Dimensions = require('Dimensions');
  16. var screenW = Dimensions.get('window').width;
  17.  
  18. // ES5
  19. var HeaderView = React.createClass({
  20. render() {
  21. return (
  22. <View style={styles.container}>
  23. {this.renderTopView()}
  24. {this.renderBottomView()}
  25. </View>
  26. );
  27. },
  28.  
  29. renderTopView(){
  30. return(
  31. <View style={styles.topViewStyle}>
  32. <Image source={{uri:'see'}} style={styles.leftIconStyle} />
  33. <View style={styles.conterViewStyle}>
  34. <Text style={{fontSize:18,color:'white',fontWeight:'bold'}}>京东电商</Text>
  35. <Image source={{uri:'avatar_vip'}} style={{width:17,height:17}} />
  36. </View>
  37. <Image source={{uri:'icon_cell_rightArrow'}} style={{width:8,height:13,marginRight:8}} />
  38. </View>
  39. )
  40. },
  41. renderBottomView(){
  42. return(
  43. <View style={styles.bottomViewStyle}>
  44. {this.renderBottomItem()}
  45. </View>
  46. )
  47. },
  48.  
  49. renderBottomItem(){
  50. // 组件数组
  51. var items = [];
  52. // 数据
  53. var dataArr = [{'number':'100', 'title':'购物券'},{'number':'12', 'title':'评价'},{'number':'50', 'title':'收藏'}];
  54. // 遍历创建组件转入数组
  55. for (var i=0;i<dataArr.length;i++){
  56. var data = dataArr[i];
  57. items.push(
  58. <TouchableOpacity key={i}>
  59. <View style={styles.bottomInnerViewStyle}>
  60. <Text style={{color:'white'}}>{data.number}</Text>
  61. <Text style={{color:'white'}}>{data.title}</Text>
  62. </View>
  63. </TouchableOpacity>
  64. );
  65. }
  66. return items;
  67. },
  68. });
  69.  
  70. const styles = StyleSheet.create({
  71. container: {
  72. height:200,
  73. backgroundColor:'rgb(255,96,0)'
  74. },
  75. topViewStyle:{
  76. flexDirection:'row',
  77. marginTop:80,
  78. alignItems:'center',
  79. justifyContent:'space-around'
  80. },
  81. leftIconStyle:{
  82. width:70,
  83. height:70,
  84. borderRadius:35,
  85. borderWidth:3,
  86. borderColor:'rgba(0,0,0,0.2)',
  87. },
  88. conterViewStyle:{
  89. flexDirection:'row',
  90. width:screenW * 0.6,
  91. },
  92. bottomViewStyle:{
  93. flexDirection:'row',
  94. position:'absolute',
  95. bottom:0,
  96. },
  97. bottomInnerViewStyle:{
  98. width:(screenW/3)+1,
  99. height:40,
  100. backgroundColor:'rgba(255,255,255,0.4)',
  101.  
  102. justifyContent:'center',
  103. alignItems:'center',
  104.  
  105. borderRightWidth:1,
  106. borderRightColor:'white'
  107. }
  108. });
  109.  
  110. // 输出
  111. module.exports = HeaderView;

2.Mine.js使用这个组件

  1. /**
  2. * 我的
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. ScrollView
  11. } from 'react-native';
  12.  
  13. /*======导入外部组件类======*/
  14. var MyCell = require('./CommonMyCell');
  15. var MiddleView = require('./MineMiddleView');
  16. var HeaderView = require('./MineHeaderView');
  17.  
  18. // ES5
  19. var Mine = React.createClass({
  20. render() {
  21. return (
  22. <ScrollView style={styles.scrollViewStyle}>
  23. <HeaderView />
  24. <View style={{marginTop:20}}>
  25. <MyCell
  26. leftIconName="collect"
  27. leftTitle="我的订单"
  28. rightTitle="查看全部订单"
  29. />
  30. <MiddleView />
  31. </View>
  32. <View style={{marginTop:20}}>
  33. <MyCell
  34. leftIconName="draft"
  35. leftTitle="钱包"
  36. rightTitle="账号余额:¥100.88"
  37. />
  38. </View>
  39. <View style={{marginTop:20}}>
  40. <MyCell
  41. leftIconName="voucher"
  42. leftTitle="抵用券"
  43. rightTitle="10张"
  44. />
  45. </View>
  46. <View style={{marginTop:20}}>
  47. <MyCell
  48. leftIconName="mall"
  49. leftTitle="积分商城"
  50. rightTitle=""
  51. />
  52. </View>
  53. <View style={{marginTop:20}}>
  54. <MyCell
  55. leftIconName="recommend"
  56. leftTitle="今日推荐"
  57. rightTitle=""
  58. />
  59. </View>
  60. </ScrollView>
  61. );
  62. }
  63. });
  64.  
  65. const styles = StyleSheet.create({
  66. scrollViewStyle:{
  67.  
  68. }
  69. });
  70.  
  71. // 输出
  72. module.exports = Mine;

3.效果图

React Native商城项目实战11 - 个人中心头部内容的更多相关文章

  1. React Native商城项目实战10 - 个人中心中间内容设置

    1.新建一个MineMiddleView.js,专门用于构建中间的内容 /** * 个人中心中间内容设置 */ import React, { Component } from 'react'; im ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. React Native商城项目实战06 - 设置安卓中的启动页

    1.Main 目录下新建LaunchImage.js: /** * 启动页 */ import React, { Component } from 'react'; import { AppRegis ...

随机推荐

  1. centos7使用kubeadm搭建kubernetes集群

    一.本地实验环境准备 服务器虚拟机准备 IP CPU 内存 hostname 192.168.222.129 >=2c >=2G master 192.168.222.130 >=2 ...

  2. [LeetCode] 211. 添加与搜索单词 - 数据结构设计

    题目链接:https://leetcode-cn.com/problems/add-and-search-word-data-structure-design/ 题目描述: 设计一个支持以下两种操作的 ...

  3. linux-导入python自定义模块的使用方法

    #!/usr/bin/python # -*- coding:utf -8 -*- import os import sys sys.path.append("/h/s/compare_f& ...

  4. redis 教程(一)-基础知识

    redis 简介 redis 是高性能的 key-value 数据库,读的速度是110000次/s,写的速度是81000次/s ,它以内存作为主存储 具有以下优点: 1. 支持数据的持久化,将内存中的 ...

  5. HNUST-1681 机器人走格子(找规律)

    1681: 机器人走格子 时间限制: 1 Sec  内存限制: 128 MB提交: 244  解决: 58[提交][状态][讨论版] 题目描述 一个长X宽Y的棋盘,有XY个格子.将机器人放在某个格子中 ...

  6. RabbitMQ几种队列模式

  7. 剑指offer-旋转数组的最小数字-数组-python

    题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...

  8. xss过滤与单例模式(对象的实例永远用一个)

    kindeditor里面可以加入script代码,使用re可以过滤掉python有个专门的模块可以处理这种情况,beautifulsoup4 调用代码: content = XSSFilter().p ...

  9. C Makefile初学基础

    # this is make file hello.out: max.o min.o hello.c gcc max.o min.o hello.c -o hello.out max.o:max.c ...

  10. 008-流程控制 case 语句

    流程控制 case 语句 与if...elif...else 语句一样都是多分支条件语句,不过if语句可以判断多种条件关系,case只能判断一种条件关系 [root@zabbix lianxi]# . ...