Reactjs 来自React导航抽屉的React本机显示模式
我有一个应用程序,我希望当用户单击某些导航路线时,它们在当前页面上显示模态,而不是导航到完全不同的页面。我现有的代码是:Reactjs 来自React导航抽屉的React本机显示模式,reactjs,react-native,navigation-drawer,react-navigation-drawer,Reactjs,React Native,Navigation Drawer,React Navigation Drawer,我有一个应用程序,我希望当用户单击某些导航路线时,它们在当前页面上显示模态,而不是导航到完全不同的页面。我现有的代码是: const DrawerNavigator = () => { return ( <Drawer.Navigator> <Drawer.Screen name="My Porfolio" component={Portfolio} /> <Drawer.Screen n
const DrawerNavigator = () => {
return (
<Drawer.Navigator>
<Drawer.Screen name="My Porfolio" component={Portfolio} />
<Drawer.Screen name="Account" component={Account} />
<Drawer.Screen name="NBA" component = {NBALobby} />
<Drawer.Screen name="NFL" component = {NFLLobby} />
<Drawer.Screen name="How To Play" component = {HowToPlayModal} />
</Drawer.Navigator>
);
}
我的模式显示如预期,但它似乎显示在一个新的、完全空白的页面上。是否有一种方法可以从抽屉导航器调用一个函数来显示模式
我的模式代码是:
import React, { Component, useState } from 'react';
import {Text, TextInput, View, TouchableOpacity} from 'react-native';
import Modal from 'react-native-modal';
import {styles} from '../styles/signUpIn';
const HowToPlayModal = () => {
return(
<Modal isVisible = {true}>
<View style={styles.container2}>
<View style={{flexDirection: 'row'}}>
<Text style={styles.title}>How To Play</Text>
<View style= {{flex:1, alignItems: 'flex-end'}}>
<Text style={[styles.fieldTitle, {marginLeft: 0}]}>Remember?</Text>
<Text style={styles.accent} >Sign In</Text>
</View>
</View>
</View>
</Modal>
);
}
export default HowToPlayModal;
您需要创建一个根堆栈导航器,其中包括模态组件和抽屉导航器
const Drawer = createDrawerNavigator();
const RootStack = createStackNavigator();
const DrawerNavigator = () => {
return (
<Drawer.Navigator>
<Drawer.Screen name="My Porfolio" component={Portfolio} />
<Drawer.Screen name="Account" component={Account} />
<Drawer.Screen name="NBA" component = {NBALobby} />
<Drawer.Screen name="NFL" component = {NFLLobby} />
</Drawer.Navigator>
);
};
const RootStackScreen = () => {
return (
<NavigationContainer>
<RootStack.Navigator mode="modal">
<RootStack.Screen
name="Main"
component={DrawerNavigator}
options={{ headerShown: false }}
/>
<RootStack.Screen name="HowToPlayModal" component={HowToPlayModal} />
</RootStack.Navigator>
</NavigationContainer>
);
}
您需要创建一个根堆栈导航器,其中包括模态组件和抽屉导航器
const Drawer = createDrawerNavigator();
const RootStack = createStackNavigator();
const DrawerNavigator = () => {
return (
<Drawer.Navigator>
<Drawer.Screen name="My Porfolio" component={Portfolio} />
<Drawer.Screen name="Account" component={Account} />
<Drawer.Screen name="NBA" component = {NBALobby} />
<Drawer.Screen name="NFL" component = {NFLLobby} />
</Drawer.Navigator>
);
};
const RootStackScreen = () => {
return (
<NavigationContainer>
<RootStack.Navigator mode="modal">
<RootStack.Screen
name="Main"
component={DrawerNavigator}
options={{ headerShown: false }}
/>
<RootStack.Screen name="HowToPlayModal" component={HowToPlayModal} />
</RootStack.Navigator>
</NavigationContainer>
);
}
完整的解释可以在这里找到这是完美的。非常感谢。这太完美了。非常感谢。