在某个路线上,通过反应进行渲染一个组件
我有一个带有React路由器的堆栈导航器,使用@react-navigation/native-stack
。我的主屏幕是一张地图,我有一些菜单组件:
export const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ headerShown: false }}
component={Home}
/>
<Stack.Screen
name="SignIn"
component={SignIn}
/>
</Stack.Navigator>
</NavigationContainer>
)
}
home
是地图组件,signin
以及其他一些组件是菜单组件导航到屏幕上,按预期将HOME
推出。
我希望能够在某个路由上“导航”到另一个组件,将其称为Overlay
。当在此处路由时,我想用覆盖
组件放置在home> home
组件的一部分上,同时仍在与该部分保持交互性,主屏幕未覆盖。但是,如果我这样做:
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ headerShown: false }}
component={Home}
/>
<Stack.Screen
name="Overlay"
component={Overlay}
/>
</Stack.Navigator>
那么home
屏幕移开,并由Overlay
代替。
当用户被路由到某个路由时,如何显示覆盖在我的主页
屏幕顶部的组件?这是对React-Router很容易完成的事情,但是我不确定React-Navigation是否存在相似之处。反应导航不是正确的方法吗?有条件地渲染基于状态/redux变量的覆盖
组件更好吗?
I have a stack navigator with react router, using @react-navigation/native-stack
. My home screen is a map, and I have a few menu components:
export const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ headerShown: false }}
component={Home}
/>
<Stack.Screen
name="SignIn"
component={SignIn}
/>
</Stack.Navigator>
</NavigationContainer>
)
}
Home
is the map component, and SignIn
, as well as some other components, are menu components that take over the screen when navigated to, pushing Home
out of the way, as expected.
I want to be able to 'navigate' to another component at a certain route, call it Overlay
. When routed here, I want to show the home screen, with an Overlay
component laid over the top of part of the Home
component, while still maintaining interactivity with the part of the Home screen that is not covered. However, if I do this:
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ headerShown: false }}
component={Home}
/>
<Stack.Screen
name="Overlay"
component={Overlay}
/>
</Stack.Navigator>
Then the Home
screen moves away, and is replaced by Overlay
.
How can I show a component overlaid over the top of my Home
screen when the user is routed to a certain route? This is something easily done with react-router, but I'm not sure if there is a parallel in react-navigation. Is react-navigation not the right approach for this? Is it better to conditionally render the Overlay
component based on a state/redux variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论