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. 太原fpxt招标

    5.31号13点多赶到太原,到yy公司,准备参加6.1号的jzfpxt投标,一起到yy山西分公司的还有北京yy总公司D工,Y工,W工等, D工负责标书及系统演示,我主要是根据D工的演示思路调整系统,演 ...

  2. linux下定时器的实现

    简介: linux下经常有这样的需求,需要定时轮询执行某种任务,当然,用shell脚本的话,crontab和at就可以满足要求.如果从C语言的角度来看,实现定时器也是一个比较简单的任务,因为具有普遍性 ...

  3. 06: django+celery+redis

    目录: 1.1 Celery介绍 1.2 celery 组件 1.3 安装相关包 与 管理命令 1.4 celery与Django执行异步任务 1.5 在django中使用计划任务功能 1.1 Cel ...

  4. Django 调试models 输出的SQL语句 定位查看结果

    django 调试models变得更为简单了,不用像之前的版本, 手工去调用django query, 才能打印出之前的代码是执行的什么SQL语句. 1.3开始只需在settings.py里,配置如下 ...

  5. P4050 [JSOI2007]麻将

    传送门 怎么好像没什么人写 $dp$ ...? 设 $f[i][j][k][0/1]$ 表示当前处理完前 $1$ 到 $i$ 的数,上一位开始的顺子有 $j$ 个,当前位开始的顺子有 $k$ 个,是否 ...

  6. numpy.random.randn()和numpy.random.rand()

    1 numpy.random.rand() (1)numpy.random.rand(d0,d1,…,dn) rand函数根据给定维度生成[0,1)之间的数据,包含0,不包含1 dn表格每个维度 返回 ...

  7. 什么情况下会出现undefined

    1.函数定义形参不传值,2.预解释,只声明不定义时输出变量3.对象取属性值,属性值不存在

  8. 使用Cookie记住登录用户

    在登录表单中,写入: 记住我: <select name="cookie">       <option value="0" selected ...

  9. verilog版插值

      开发环境:IDE:LIBERO 9.0(ACTEL公司的)芯片:AFS600 (BGA256),是混合系列的FPGA仿真软件:modelsim atcel 6.5d综合软件:synplify pr ...

  10. Python字符串(str)方法调用

    # str# n = 'pianYU'# v = n.capitalize() # 将字符串的首字母大写# print(v)## n = 'pianYI'# v1 = n.isupper() # 判断 ...