admin管理员组文章数量:1353111
I want to have a Toast (view on top of everything else) that is controlled by a contextual state. In order to do this, I add this at the App level of my basic Static Api navigation:
const RootStack = createNativeStackNavigator({
screens: {
Home: HomeScreen,
Profile: ProfileScreen,
}
}
const RootNavigation = createStaticNavigation(RootStack)
const App = () => {
return (
<SafeAreaProvider>
<GestureHandlerRootView>
<Provider>
<RootNavigation />
<ToastContainer />
</Provider>
</GestureHandlerRootView>
</SafeAreaProvider>
)
}
The ToastContainer is the following:
export function ToastContainer() {
const [toast, setToast] = useAtom(Atom.currentToast)
const navigation = useNavigation()
if (toast) {
return (
<View />
)
} else {
return undefined
}
}
The problem is that useNavigation() doesn't work here, because ToastContainer is not inside a navigation context.
I tried this with no luck (RootNavigation doesn't accept children)
<RootNavigation>
<ToastContainer />
</RootNavigation>
Also, I tried creating a component and wrapping it with NavigationContainer (similar than I was doing with React Navigation 6 with Dinamic Api, that works):
const RootComponent = createComponentForStaticNavigation(RootStack, 'blabla')
<NavigationContainer>
<RootComponent />
<ToastContainer />
</NavigationContainer>
UPDATE
With this last code, the navigation works 99% of the cases. Is working well when using navigation.navigate() but doesn't work when using navigation.popTo()
本文标签: reactjsReact Navigation 7 Toast with Static ApiStack Overflow
版权声明:本文标题:reactjs - React Navigation 7 Toast with Static Api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743893682a2557392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论