React Native商城项目实战09 - 个人中心自定义cell
1.新建组件CommonMyCell.js

/**
* 个人中心自定义cell
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform,
} from 'react-native'; // ES5
var MyCell = React.createClass({
getDefaultProps(){
return{
leftIconName:'', // cell左侧图标
leftTitle:'', // cell左侧标题
rightIconName:'', // cell右侧图标
rightTitle:'', // cell右侧标题
}
}, render() {
return (
<TouchableOpacity onPress={()=>{alert('点击了')}}>
<View style={styles.container}>
<View style={styles.leftViewStyle}>
<Image source={{uri:this.props.leftIconName}} style={styles.leftImgStyle} />
<Text style={styles.leftTitleStyle}>{this.props.leftTitle}</Text>
</View>
<View style={styles.rightViewStyle}>
{this.rightSubView()}
</View>
</View>
</TouchableOpacity>
);
}, // cell右侧子视图
rightSubView(){
return(
<View style={{flexDirection:'row',alignItems:'center'}}>
{this.renderRightContent()}
<Image source={{uri:'icon_cell_rightArrow'}} style={{width:8, height:13, marginRight:8, marginLeft:5}} />
</View>
)
}, // cell右侧具体内容
renderRightContent(){
if(this.props.rightIconName.length == 0){ // 不返回图片
return(
<Text style={{color:'gray'}}>{this.props.rightTitle}</Text>
)
}else{
<Image source={{uri:this.props.rightIconName}} style={{width:24, height:13}} />
}
},
}); const styles = StyleSheet.create({
container: {
// 主轴的方向
flexDirection:'row',
// 主轴的对齐方式
justifyContent:'space-between',
// 背景颜色
backgroundColor:'white',
// 垂直居中
alignItems:'center',
// 高度
height:Platform.OS == 'ios' ? 40 : 36, // 下边框
borderBottomColor:'#e8e8e8',
borderBottomWidth:0.5
},
leftViewStyle:{
// 主轴的方向
flexDirection:'row',
// 侧轴居中
alignItems:'center',
// 左外边距
marginLeft:8
}, rightViewStyle:{ }, leftImgStyle:{ // 左边的图片
width:24,
height:24,
marginRight:6,
// 圆角
borderRadius:12
}, leftTitleStyle:{
fontSize:16
}
}); // 输出
module.exports = MyCell;
2.Mine.js里如何使用?
/**
* 我的
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
ScrollView
} from 'react-native'; /*======导入外部组件类======*/
var MyCell = require('./CommonMyCell'); // ES5
var Mine = React.createClass({
render() {
return (
<ScrollView>
<View style={{marginTop:20}}>
<MyCell
leftIconName="draft"
leftTitle="钱包"
rightTitle="账户余额:¥100.88"
/>
</View>
</ScrollView>
);
}
}); const styles = StyleSheet.create({ }); // 输出
module.exports = Mine;
3.效果图

React Native商城项目实战09 - 个人中心自定义cell的更多相关文章
- React Native商城项目实战11 - 个人中心头部内容
1.创建MineHeaderView.js /** * 个人中心头部内容 */ import React, { Component } from 'react'; import { AppRegist ...
- React Native商城项目实战10 - 个人中心中间内容设置
1.新建一个MineMiddleView.js,专门用于构建中间的内容 /** * 个人中心中间内容设置 */ import React, { Component } from 'react'; im ...
- React Native商城项目实战08 - 设置“More”界面cell
1.自定义可复用的cell More/CommonCell.js: /** * 自定义可复用的cell */ import React, { Component } from 'react'; imp ...
- React Native商城项目实战04 - 封装TabNavigator.Item的创建
1.Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, View, Im ...
- React Native商城项目实战02 - 主要框架部分(tabBar)
1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...
- 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商城项目实战06 - 设置安卓中的启动页
1.Main 目录下新建LaunchImage.js: /** * 启动页 */ import React, { Component } from 'react'; import { AppRegis ...
随机推荐
- CVE-2016-8655,af_packet Linux 內核通殺提權漏洞淺析
簡單寫一下思路 這個東西需要namespace方面的支援, 首先open socket , 一連串路徑(packet_set_ring()->init_prb_bdqc()->prb_se ...
- 46. Permutations (JAVA)
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...
- Django中利用type动态操作数据库表
场景分析: 后台MySql数据库保存了一大批按股票代码命名的数据表,每张表保存的是每只股票的日线数据. stock_000002 stock_600030 stock_600020 ...一共3000 ...
- Keepalived高可用服务器案例
部署Keepalived高可用软件,实现如下: - 使用Keepalived实现web服务器的高可用 - Web服务器IP地址分别为192.168.4.100和192.168.4.200 - Web服 ...
- rev 反向输出文件内容
1.命令功能 rev 按行反向输出文件内容 2.语法格式 rev file 3.使用范例 [root@localhost ~]# echo {a..k} >> test [root@lo ...
- python json、pickle
文章部分转自:https://www.cnblogs.com/lincappu/p/8296078.html json:用于字符串和Python数据类型间进行转换pickle: 用于python特有的 ...
- Centos7.5 mysql5.7.26二进制安装方式
1 yum安装所需相关依赖包. yum -y install gcc-c++ yum -y install zlib zlib-devel pcre pcre-devel yum -y inst ...
- python碎片 - 函数参数
一个*传参: 方式1:如果想传一个列表中的值,实参前加*.如: *[1,2,3] 方式2:直接传入一个列表,不加*.如[1,2,3],则传入的是一整个列表,包括[] 两个**传参: 方式1,:{nam ...
- LOJ#2330 榕树之心 树形dp
瞎扯 这个题和\(\mathsf{ISIJ2019 Au}\)神仙学弟\(\mathsf{\color{red}c}\mathsf{hangruinian2020}\)争辩了半个多小时. 概括一下就是 ...
- 【BZOJ2870】最长道路
权限题 题意 给出一棵树,点有点权,找到树上的一条路径使得路径上点的个数和其中点权最小的点的点权之积最大,输出最大值. Sol 边分治板子题啦. 边分治后对于分出来的两棵子树 , 按到左右根的最小点权 ...