Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant recomposition upon navigation. #694

Open
DimitarGR8 opened this issue Oct 23, 2024 · 2 comments
Open

Constant recomposition upon navigation. #694

DimitarGR8 opened this issue Oct 23, 2024 · 2 comments

Comments

@DimitarGR8
Copy link

DimitarGR8 commented Oct 23, 2024

Greetings @raamcosta , I have the following issue that I need assistance of.. So, I have a top level navigation where currently I am solving in the following way:

@composable
private fun ExecuteNavigation(
navController: NavHostController,
direction: Direction,
addToBackstack: Boolean?,
previousDestination: Direction?
) {
val destinationsNavigator = navController.rememberDestinationsNavigator()

destinationsNavigator.navigate(direction) {
    if (addToBackstack != true) {
        previousDestination?.let {
            popUpTo(previousDestination) {
                inclusive = true
            }
        }
    }
}

}

First issue that I meet is that if I pull navController.rememberDestinationsNavigator() outside the composable that I am calling the navigation from, the next screen that I land at keeps on recomposing infinitely. Basically, the only workaround that I found is to call the rememberDestinationsNavigator() locally.. I would have gone for navController.toDestinationsNavigator(), since I do not really need executeNavigation() to be a composable function, but the outcome is the same..

I would rather sort this one out first, after which I guess I would reach to my second question. Any assistance on that matter? What would cause this infinite next screen recomposition? I basically want to call the DestinationsNavigator at a top level.

@DimitarGR8
Copy link
Author

DimitarGR8 commented Oct 23, 2024

Forgot to mention that currently I am using the v.2.x of the lib and material3 ModalNavigationDrawer which seems to be breaking down.

@DimitarGR8
Copy link
Author

DimitarGR8 commented Oct 23, 2024

Made some progress but not sure that this has to be the following way. I moved the destinationsNavigator to a top level and I did fix the recomposition the following way:

executeNavigation = { direction, addToBackStack, previousDestination ->
LaunchedEffect(direction, addToBackStack, previousDestination) {
executeNavigation(destinationsNavigator, direction, addToBackStack, previousDestination)
}
}

I still think that this is incorrect and infinite recomposition after screen navigation should not happen.

This brings me to my second question now, when i navigate back to Screen 1 , after initial navigation , components on the screen react to clicks, however only screen recomposition happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant