1。无法从内容组件内部导航到提及屏幕
import React, { Component } from "react";
import {View,Text,Button,Image,StyleSheet,TouchableOpacity} from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons'
import SettingsScreen from '../screens/SettingsScreen'
export default class DrawerScreen extends Component{
static navigationOptions= ({navigation}) =>({
});
render(){
return(
<View style={styles.container}>
<Image style={styles.Image}
source={require('../images/defalut.png')} />
<Text> @username </Text>
<View>
<Icon
name='ios-settings'
color='#000'
size={14}
/>
<Button
onPress={() =>{
const { navigate } = this.props.navigation.navigate;
navigate('SettingsScreen')}}
color="orange"
title="Settings"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
},
Image:{
width:70,
height:80,
borderRadius:40
}
});
答案 0 :(得分:0)
很遗憾,我还不能添加评论,因此我必须使用答案。
您是否为DrawerScreen组件定义了一条路线? 否则,它将无法获得导航作为道具,afaik。
答案 1 :(得分:0)
问题在这里:
const { navigate } = this.props.navigation.navigate;
navigate('SettingsScreen')}}
您正在尝试从导航功能中获取导航功能。
仅使用什么问题:
this.props.navigation.navigate('SettingsScreen');