React Native商城项目实战08 - 设置“More”界面cell
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的更多相关文章
- 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 ...
- React Native商城项目实战09 - 个人中心自定义cell
1.新建组件CommonMyCell.js /** * 个人中心自定义cell */ import React, { Component } from 'react'; import { AppReg ...
- React Native商城项目实战10 - 个人中心中间内容设置
1.新建一个MineMiddleView.js,专门用于构建中间的内容 /** * 个人中心中间内容设置 */ import React, { Component } from 'react'; im ...
- React Native商城项目实战01 - 初始化设置
1.创建项目 $ react-native init BuyDemo 2.导入图片资源 安卓:把文件夹放到/android/app/src/main/res/目录下,如图: iOS: Xcode打开工 ...
- React Native商城项目实战04 - 封装TabNavigator.Item的创建
1.Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, View, Im ...
- React Native商城项目实战03 - 包装Navigator
1.在Home目录下新建首页详细页HomeDetail.js /** * 首页详情页 */ import React, { Component } from 'react'; import { App ...
- React Native商城项目实战02 - 主要框架部分(tabBar)
1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...
随机推荐
- 51nod1769 Clarke and math 2
题目 实际上就是要求\(f*I^k\). 因为\(I^k\)是一个积性函数,所以我们只需要考虑如何求\(I^k(p^a)\). 把这个东西转化成一个长度为\(k\)的序列,每一位是\(\frac{i_ ...
- 20170309工作笔记--------如何用好dialog,想变什么样就变成什么样
(1)首先自定义一个dialog的div,并且写内容 (2)运用相应的代码进行控制,弹出dialog $(".tel").click(function() { $("#d ...
- 如何将数据库导入到本地MySQL
有两个方法:(1)在MySQL的客户端进行导入,比如: http://jingyan.baidu.com/article/6dad507517c11aa123e36ea0.html (2)方法:常用s ...
- 2、Java调用C语言(JNative法)
这个方法也是挺麻烦的…… 一.下载JNative.jar,把它放在你jdk下的\jre\lib\ext目录下 二.在 F:\MinGW\JNative 新建 Test.java: public cla ...
- go & cron
https://github.com/robfig/cron - 源码 cron - GoDoc 参考 go---定时任务 cron,gin 静态文件 go语言里比较好用的计划任务调度模块
- uni-app中页面部分内容使用索引列表(uni-indexed-list),动态数据
一.引入uni-indexed-list.uni-icons组件 从uni-app插件市场下载或从HBuilder X提供的hello uni-app模板中复制 二.页面中引用 三.对请求获得的数据处 ...
- unittest生成报告
# html报告文件路径 report_abspath = os.path.join(report_path, "result.html") fp = open(rep ...
- iOS APP 国际化
pp Store 中很多流行的应用程序有多种语言版本.虽然这些应用程序可能因为很多因素而变得流行,但是具有多种本地化版本,肯定是其中一个因素.越多的人可以理解并使用您的应用程序,潜在的买家也就越多. ...
- CDate()函数
CDate 函数 返回表达式,此表达式已被转换为 Date 子类型的 Variant. CDate(date) date 参数是任意有效的日期表达式. 说明 IsDate 函数用于判断 date 是否 ...
- Python中numpy的应用
#创建ndarray import numpy as np nd = np.array([2,4,6,'])#numpy中默认ndarray的所有元素的数据类型是相同,如果数据的类型不同,会统一为统一 ...