1.自定义可复用的cell 
More/CommonCell.js:

/**
* 自定义可复用的cell
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform,
Switch
} from 'react-native'; // ES5
var CommonCell = React.createClass({
getDefaultProps(){
return{
title:'', // cell标题文字
isSwitch:false, // 是否展示开关
rightTitle:'', //cell右侧标题
}
}, getInitialState(){
return{
isOn:false,
}
}, render() {
return (
<TouchableOpacity onPress={()=>{alert('点击了')}}>
<View style={styles.container}>
<Text>{this.props.title}</Text>
{this.renderRightView()}
</View>
</TouchableOpacity>
);
}, // cell右侧指示图标视图
renderRightView(){
if(this.props.isSwitch){
return(
<Switch value={this.state.isOn == true} onValueChange={()=>{this.setState({isOn:!this.state.isOn})}} />
)
}else{
return(
<View style={{flexDirection:'row',alignItems:'center'}}>
{this.renderRightTitle()}
<Image source={{uri:'icon_cell_rightArrow'}} style={{width:8,height:13}} />
</View>
)
}
}, // cell右侧标题视图
renderRightTitle(){
if(this.props.rightTitle.length > 0){
return(
<Text style={{color:'gray',marginRight:10}}>{this.props.rightTitle}</Text>
)
}
},
}); const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
height:Platform.OS == 'ios' ? 40 : 30,
borderBottomColor:'#ddd',
borderBottomWidth:0.5,
flexDirection:'row',
justifyContent:'space-between',
// 垂直居中
alignItems:'center',
paddingLeft:10,
paddingRight:10,
},
}); // 输出
module.exports = CommonCell;

2.在More.js里使用cell:

/**
* 更多
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform,
ScrollView
} from 'react-native'; /*======导入外部组件类======*/
var CommonCell = require('./CommonCell'); // ES5
var More = React.createClass({
render() {
return (
<View style={styles.container}>
{/*导航条*/}
{this.renderNavBar()}
<ScrollView>
<View style={{marginTop:20}}>
<CommonCell
title="扫一扫"
/>
</View>
<View style={{marginTop:20}}>
<CommonCell
title="省流量模式"
isSwitch={true}
/>
<CommonCell
title="扫一扫"
/>
<CommonCell
title="扫一扫"
/>
<CommonCell
title="扫一扫"
/>
<CommonCell
title="清空缓存"
rightTitle="1.99M"
/>
</View>
<View style={{marginTop:20}}>
<CommonCell
title="省流量模式"
isSwitch={true}
/>
<CommonCell
title="扫一扫"
/>
<CommonCell
title="扫一扫"
/>
<CommonCell
title="扫一扫"
/>
<CommonCell
title="扫一扫"
/>
</View>
</ScrollView>
</View>
);
}, // 导航条
renderNavBar(){
return(
<View style={styles.navOutViewStyle}>
<Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>更多</Text>
<TouchableOpacity onPress={()=>{alert('点击了')}} style={styles.rightViewStyle}>
<Image source={{uri:'icon_mine_setting'}} style={styles.navImgStyle} />
</TouchableOpacity>
</View>
)
}
}); const styles = StyleSheet.create({
// 导航条视图
navOutViewStyle:{
height:Platform.OS === 'ios' ? 64 : 44,
backgroundColor:'rgba(255,96,0,1)',
// 主轴方向
flexDirection:'row',
// 侧轴对齐方式 垂直居中
alignItems:'center',
// 主轴方向居中
justifyContent:'center',
},
// 导航栏右侧
rightViewStyle:{
// 绝对定位
position:'absolute',
right:10,
bottom:15,
},
// 导航条上图片
navImgStyle:{
width:Platform.OS === 'ios' ? 28 : 24,
height:Platform.OS === 'ios' ? 28 : 24,
},
container: {
flex: 1,
backgroundColor: '#e8e8e8',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}, }); // 输出
module.exports = More;

3.效果图

React Native商城项目实战08 - 设置“More”界面cell的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. React Native商城项目实战03 - 包装Navigator

    1.在Home目录下新建首页详细页HomeDetail.js /** * 首页详情页 */ import React, { Component } from 'react'; import { App ...

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

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

随机推荐

  1. .net 与directX

    微软早期出过managed assembly.但后来因为XXX的原因,没有继续出,只支持c++了..net的开发者就哭了.这篇博客解释了前世今生: https://blogs.msdn.microso ...

  2. Serilog

    参考 asp.net core使用serilog将日志推送到腾讯云日志服务

  3. Python 余弦相似度与皮尔逊相关系数 计算

    夹角余弦(Cosine) 也可以叫余弦相似度. 几何中夹角余弦可用来衡量两个向量方向的差异,机器学习中借用这一概念来衡量样本向量之间的差异. (1)在二维空间中向量A(x1,y1)与向量B(x2,y2 ...

  4. Spring基础12——使用外部属性文件

    1.使用外部属性文件 在配置文件里配置Bean时,有时需要在Bean的配置文件里引入系统部署的细节信息(例如:文件的路径.数据源配置信息等),而这些部署细节实际上需要和bean配置相分离,因为我们修改 ...

  5. NOTIFY - 生成一个通知

    SYNOPSIS NOTIFY name DESCRIPTION 描述 NOTIFY 命令向当前数据库中所有执行过 LISTEN name, 正在监听特定通知条件的前端应用发送一个通知事件. 传递给前 ...

  6. Qt下载(多种下载通道+所有版本)

    http://c.biancheng.net/view/3851.html Qt 体积很大,有 1GB~3GB,官方下载通道非常慢,相信很多读者会崩溃,所以建议大家使用国内的镜像网站(较快),或者使用 ...

  7. 计蒜客 蓝桥模拟 G. 数列求值

    递归式移项得Ai+1 = 2Ai + 2Ci - Ai-1; 1.A2 = 2A1 + 2C1 - A0; 2.A3 = 2A2 + 2C2 - A1; . . . n.An+1 = 2An + 2C ...

  8. 【学习】020 Redis

    Java缓存机制 Java中要用到缓存的地方很多,首当其冲的就是持久层缓存,针对持久层谈一下:  要实现java缓存有很多种方式,最简单的无非就是static HashMap,这个显然是基于内存缓存, ...

  9. thinkphp5.0.19 request

    一.请求类型 request类中 [F:\phpStudy\WWW\csweb\thinkphp\library\think\Request.php] 获取请求类型的方法分别是: isGet() .i ...

  10. BZOJ2160 拉拉队排练 PAM

    题意简述 询问一个串中所有奇回文按照长度降序排列,前k个奇回文的长度乘积. 做法 回文自动机(PAM)模板题. 维护每个回文自动机的结点回文串出现次数,跳fail得到每个长度的出现次数,双关键字排序后 ...