React Native商城项目实战09 - 个人中心自定义cell
来源:互联网 发布:贱人软件5.9破解 编辑:程序博客网 时间:2024/05/10 17:10
1.新建组件CommonMyCell.js
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, Image, TouchableOpacity, Platform,} from 'react-native';// ES5var 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里如何使用?
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, ScrollView} from 'react-native';/*======导入外部组件类======*/var MyCell = require('./CommonMyCell');// ES5var 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;
0 0
- React Native商城项目实战09 - 个人中心自定义cell
- React Native商城项目实战11 - 个人中心头部内容
- React Native商城项目实战10 - 个人中心中间内容设置
- React Native商城项目实战08 - 设置“More”界面cell
- React Native项目实战之搭建美团个人中心界面
- react native 实战[商城DEMO]
- React Native商城项目实战01 - 初始化设置
- React Native商城项目实战02 - 主要框架部分(tabBar)
- React Native商城项目实战03 - 包装Navigator
- React Native商城项目实战12 - 首页头部内容
- React Native商城项目实战13 - 首页中间上部分内容
- React Native商城项目实战14 - 首页中间下部分
- React Native商城项目实战15 - 首页购物中心
- React Native商城项目实战16 - 购物中心详细页
- React Native实战项目
- React Native 学习(三)---个人中心
- 商城项目实战15:Dubbo监控中心
- React Native商城项目实战04 - 封装TabNavigator.Item的创建
- JAVA学习笔记【java环境搭建01】
- 20160823模拟赛T2
- 设置窗口满屏 隐藏虚拟键盘
- SAP.CO.Standard Hierarchies
- 【Sqlserver】各种数据库的锁表和解锁操作
- React Native商城项目实战09 - 个人中心自定义cell
- 2016物联网版图:物联网奇点是否已经来临?
- 图片轮播器以及NSTimer的使用
- C++中的虚函数
- Double转BigDecimal进行四舍五入操作时会出现数据损失
- 3.2 vidioc_int_* 类函数的调用过程
- 线程池任务统计应用
- PS常见问题01——如何旋转纸张
- 在spring cloud eureka中使用ip而不是hostname