我在expo / react native中为应用程序添加了导航,并且在开发环境中一切正常。但是,当我使用expo build:android生成apk时,导航无法正常工作,它将带我回到初始屏幕,而不是带我进入事件屏幕(在示例中) 注意:抽屉导航正常。
我一开始尝试使用这种方法进行导航:
function navigateToEvent(id){
state.props.navigation.navigate('EventScreen', { id: id });
}
它在开发中有效,但在apk中不起作用,所以我尝试使用相同的抽屉方式(由于抽屉导航有效):
navigateToEvent = (id) => {
const navigateAction = NavigationActions.navigate({
routeName: 'EventScreen',
params: {id:id}
});
this.state.props.navigation.dispatch(navigateAction);
}
但是给了我相同的结果。
这是我的索引(仅缩小到两页,尽管除了导航到抽屉式页面之外,它在任何页面上均不起作用)也许我在这里出错:
class RightNavigationDrawerStructure extends React.Component {
toggleDrawer = () => {
this.props.navigationProps.toggleDrawer();
};
render() {
return (
<View style={{ flexDirection: "row" }}>
<TouchableOpacity onPress={this.toggleDrawer.bind(this)} style={{marginRight:10, transform: [{ rotateY: '180deg'}]}}>
{/*Donute Button Image */}
<Icon
name='sort'
size={30}
color='#000'
onPress={() => this.toggleDrawer()}
/></TouchableOpacity>
</View>
);
}
}
class LeftArrowNavigationDrawerStructure extends React.Component {
backDrawer = () => {
this.props.navigationProps.pop(this.props.pops);
};
render() {
return (
<View style={{ flexDirection: "row" }}>
<TouchableOpacity onPress={this.backDrawer.bind(this)}>
<Image
source={require("./assets/images/back.png")}
style={{
width: 30,
height: 30,
marginLeft: 10
}}
/>
</TouchableOpacity>
</View>
);
}
}
const Drawer_SplashScreen= createDrawerNavigator(
{
SplashScreen: {
screen: SplashScreen,
navigationOptions: {
drawerLabel: () => null
}
}
}
);
const Drawer_EventScreen = createDrawerNavigator(
{
EventScreen: {
screen: EventScreen,
navigationOptions: {
drawerLabel: () => null
}
}
},
{
drawerPosition: "right",
contentComponent: SideMenu,
navigationOptions: {
headerTintColor: "#fff",
headerStyle: {
backgroundColor: "#fff"
}
}
}
);
const Drawer_AllEventsScreen = createDrawerNavigator(
{
AllEventsScreen: {
screen: AllEventsScreen,
navigationOptions: {
drawerLabel: () => null
}
}
},
{
drawerPosition: "right",
contentComponent: SideMenu,
navigationOptions: {
headerTintColor: "#fff",
headerStyle: {
backgroundColor: "#fff"
}
}
}
);
const Router = createStackNavigator(
{
SplashScreen: {
screen: Drawer_SplashScreen,
navigationOptions:{
headerShown:false
}
},
AllEventsScreen: {
screen: Drawer_AllEventsScreen,
navigationOptions: ({ navigation }) => ({
headerTitle: (
<View style={{ flex: 1, alignItems: "center" }}>
<Image source={require('./assets/images/logo.png')}
style={{height:50 ,width:150,flex:1 }} resizeMode='contain'/>
</View>
),
headerTitleContainerStyle: {backgroundColor:'#fff', width:'60%'},
headerRightContainerStyle:{backgroundColor:'#fff',width:'20%'},
headerLeftContainerStyle: {backgroundColor:'#fff',width:'20%'},
headerRight: (
<RightNavigationDrawerStructure navigationProps={navigation} />
),
headerLeft: (
<View></View>
)
})
},
EventScreen: {
screen: Drawer_EventScreen,
navigationOptions: ({ navigation }) => ({
title: "EventScreen",
headerRight: (
<RightNavigationDrawerStructure navigationProps={navigation} />
),
headerTitle: (
<View style={{ flex: 1, alignItems: "center" }}>
<Image source={require('./assets/images/logo.png')}
style={{height:50 ,width:150,flex:1 }} resizeMode='contain'/>
</View>
),
headerTitleContainerStyle: {backgroundColor:'#fff', width:'60%'},
headerRightContainerStyle:{backgroundColor:'#fff',width:'20%'},
headerLeftContainerStyle: {backgroundColor:'#fff',width:'20%'},
headerLeft: (
<LeftArrowNavigationDrawerStructure
navigationProps={navigation}
pops={1}
/>
)
})
},
}
);
export default createAppContainer(Router);
请帮助我解决问题。谢谢!