首页 > 代码库 > React Native学习之自定义Navigator
React Native学习之自定义Navigator
有些常用的组件还是留着方便一点.
import React, { Component } from ‘react‘;
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
Platform,
TouchableOpacity
} from ‘react-native‘;
var Dimensions = require(‘Dimensions‘);
var width = Dimensions.get(‘window‘).width;
var Height = Dimensions.get(‘window‘).height;
var NavigatorView = React.createClass ({
render() {
return (
<View style = {styles.container}>
{this.renderNavBar()}
</View>
);
},
renderNavBar() {
return(
<View style={styles.NavBarStytle}>
<TouchableOpacity activeOpacity={0.5} style={styles.leftViewStytle} onPress={()=> {this.popToHome()}}>
<Image source={{uri: ‘nav_btn_back‘}} style={styles.NavLeftImageStyle} />
</TouchableOpacity>
<Text style={{color: ‘black‘, fontSize: 16, fontWeight: ‘bold‘, bottom:-5}}>{this.props.title}</Text>
</View>
)
},
popToHome() {
this.props.navigator.pop();
},
pushToDetil(nextVC, titleName) {
this.props.navigator.push({
component: nextVC,
title: titleName,
passProps: {‘title‘: titleName}
});
},
})
const styles = StyleSheet.create({ container: {
flex: 1,
alignItems: ‘center‘,
backgroundColor: ‘#F5FCFF‘,
},
NavBarStytle: {
width: width,
height: Platform.OS == ‘ios‘ ? 64 : 44,
backgroundColor: ‘#F2F2F2‘,
flexDirection: ‘row‘,
alignItems: ‘center‘,
justifyContent: ‘center‘
},
leftViewStytle: {
position: ‘absolute‘,
left: 15,
bottom: 15
},
NavLeftImageStyle: {
width: Platform.OS == ‘ios‘ ? 15 : 15,
height: Platform.OS == ‘ios‘ ? 15 : 15,
},
});
module.exports = NavigatorView;
React Native学习之自定义Navigator
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。