React Native学习之自定义Navigator
Posted 伟大是熬出来的
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
ReactNative学习之控件:react-native-elements