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 ...
随机推荐
- 极*Java速成教程 - (6)
Java高级特性 String String是Java中的字符串类型,字符串类型在内存中是一个不可变的对象.如果要对字符串对象进行修改,如果是较少的修改可以使用+运算符,Java会自动进行优化,但如果 ...
- mysql5.7单机多实例安装
基于之前的mysql5.7单实例安装 修改/etc/my.cnf文件如下(这里配置4个实例,可自行修改数目) # # 多实例配置文件,可以mysqld_multi --example 查看例子 # [ ...
- Python中对 文件 的各种骚操作
Python中对 文件 的各种骚操作 python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Python脚本工作的目录路径: os.getc ...
- STL 之 queue
默认容器为双端队列deque 常用的函数有: empty Test whether container is empty (public member function ) size Return s ...
- 从零开始配置安装Flutter开发环境
flutter 中文网 https://flutterchina.club/get-started/install/ 1.配置全局环境 PUB_HOSTED_URL=https://pub.flutt ...
- C# wpf 列出文件夹所有文件
在网上找了 cmd输入 dir "要列出的文件夹*.*" /a /b /s>"要输出的文件" 可以重定向把文件夹内容输出到文件 tree "要列 ...
- diff 比较两个文件的不同
1.命令功能 diff 逐行比较文件内容,并输出文件差异. 2.语法格式 diff option file1 file2 diff 选项 文件1 文件2 参数说明 参数 参数说明 ...
- P4315 月下“毛景树” (树链剖分+边剖分+区间覆盖+区间加+区间最大值)
题目链接:https://www.luogu.org/problem/P4315 题目大意: 有N个节点和N-1条树枝,但节点上是没有毛毛果的,毛毛果都是长在树枝上的.但是这棵“毛景树”有着神奇的魔力 ...
- springboot+HttpInvoke 实现RPC调用
开始用springboot2+hession4实现RPC服务时,发现第一个服务可以调用成功,但第二个就一直报 '<' is an unknown code.第一个服务还是可以调用的.参考网上的方 ...
- 前端之JavaScript:JS之DOM对象一
js之DOM对象一 一.什么是HTML DOM HTML Document Object Model(文档对象模型) HTML DOM 定义了访问和操作HTML文档的标准方法 HTML DOM 把 ...