0

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>
    )
}

This is the ToastContainer:

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 dynamic 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()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.