ReactNativeの初心者 私はNavigatorEX
クラスを作成しました。これは通常MiladView
をレンダリングしますが、HadiView
クラスにナビゲートしていません。 route
またはpush
メソッドの問題点は何ですか? このコードはReact-Native 0.25によってES6で書かれています。React Native NavigatorIOS
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
NavigatorIOS
} from 'react-native';
class NavigatorEX extends Component {
render() {
return (
<NavigatorIOS
style={styles.nav}
titleTextColor="#212121"
navigationBarHidden={false}
initialRoute={{
component: MiladView,
title: 'Milad',
rightButtonTitle: 'Go',
onRightButtonPress:() => {
this.props.navigator.push({
component: HadiView,
title: 'Hadi',
leftButtonTitle: 'Back',
onLeftButtonPress:() => this.props.navigator.pop(),
});
},
}}
/>
);
}
}
class HadiView extends Component {
render(){
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Hadi
</Text>
</View>
)
}
}
class MiladView extends Component {
render(){
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Milad
</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#FAFAFA',
},
nav: {
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('NavigatorEX',() => NavigatorEX);
対
this.navigator.push
私はあなたが '私が変更した' onRightButtonClick' –@NaderDabit対onRightButtonPress'必要かもしれないと思いますそれは動作しません。 chromeデバッガは次の点を指摘しています: 'this.props.navigator.push({' –