RN实现头部NavBar
来源:互联网 发布:php 开源 客服系统 编辑:程序博客网 时间:2024/05/21 12:42
(1)实现NavBar
import React, {Component, PropTypes} from 'react';import { AppRegistry, StyleSheet, Text, View, Dimensions, Platform} from 'react-native';const {width, height} = Dimensions.get('window');export default class GDNavBar extends Component { static propTypes = { leftItem: PropTypes.func, titleItem: PropTypes.func, rightItem: PropTypes.func, }; renderLeftItem() { if (this.props.leftItem === undefined) { return; } return this.props.leftItem(); }; renderTitleItem() { if (this.props.titleItem === undefined) { return; } return this.props.titleItem(); }; renderRightItem() { if (this.props.rightItem === undefined) { return; } return this.props.rightItem(); }; render() { return ( <View style={styles.container}> <View> {this.renderLeftItem()} </View> <View> {this.renderTitleItem()} </View> <View> {this.renderRightItem()} </View> </View> ); }}const styles = StyleSheet.create({ container: { width: width, height: Platform.OS === 'ios' ? 64 : 44, backgroundColor: 'red', flexDirection: 'row',//按行排列 justifyContent: 'space-between', alignItems: 'center', borderBottomWidth: 0.5, borderBottomColor: 'gray', paddingTop: Platform.OS === 'ios' ? 15 : 0, },});
(2)调用
import React, {Component} from 'react';import { AppRegistry, StyleSheet, Text, View, TouchableOpacity, Image, ListView, Dimensions} from 'react-native';import NavBar from '../main/GDNavBar';import Cell from '../main/GDHotCell';const {width, height} = Dimensions.get('window');export default class GDHalfHourHot extends Component { constructor(props) { super(props); } renderTitleItem() { return ( <Text style={styles.titleItem}>近半小时热门</Text> ); }; renderRightItem() { return ( <TouchableOpacity> <Text style={styles.rightItem}>关闭</Text> </TouchableOpacity> ); }; render() { return ( //这里left默认没有 <View style={styles.container}> <NavBar titleItem={() => this.renderTitleItem()} rightItem={() => this.renderRightItem()} /> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', backgroundColor: 'white', }, titleItem: { fontSize: 17, color: 'black', marginLeft: 50, }, rightItem: { fontSize: 17, color: 'rgba(123,178,114,1.0)', marginRight: 15, },});
阅读全文
0 0
- RN实现头部NavBar
- navbar
- RN实现轮播器
- RN实现九宫格
- RN实现ListView
- RN实现TabNavigator
- RN
- RN
- RN
- RN
- ObservableScrollView 实现粘性头部
- 头部视差的实现
- 实现头部透明度变化
- RN仿QQ实现滑动删除
- 原生android工程实现RN集成
- 基于RN实现顶部tab导航切换
- pubsub-js 实现RN组件间通信
- 实现表格的头部固定
- IndexerApplication
- launch mode 应用场景
- Android 调试安装apk 报错 Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
- 执行sql 语句(在C++中执行)
- 最长上升子序列
- RN实现头部NavBar
- 目标检测(三)--DPM
- 8月英语--榜样的力量
- bat 文件操作
- softmax回归详解【转载】
- 分享一个bat脚本,比较文件输出是否相同,并输出第一个不同的位置
- 4078:实现堆结构
- 简单CrackMe分析(样本名:ReverseMe)
- 一个在线音乐软件的故事(五、让我们开始写代码吧)