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

value didn't update in NavHost #271

Open
RYXCP opened this issue Feb 18, 2024 · 8 comments
Open

value didn't update in NavHost #271

RYXCP opened this issue Feb 18, 2024 · 8 comments

Comments

@RYXCP
Copy link

RYXCP commented Feb 18, 2024

In 1.5.10, based on the sample app called Reply, I gave it a try. However, I found that the screenType in the scene retains its initial value while the one outside the NavHost is changed correctly.

Should I not have done this?

//This is Reply
val contentType: ReplyContentType = ReplyContentType.SINGLE_PANE
...
@Composable
private fun ReplyNavHost(
    navController: NavHostController,
    contentType: ReplyContentType,
    ...
) {
    NavHost(
        navController = navController,
        startDestination = ReplyRoute.INBOX,
    ) {
        composable(ReplyRoute.INBOX) {
            ReplyInboxScreen(
                contentType = contentType,
                ...
//This is my app
var screenType = ScreenType.MEDIUM
...
@Composable
fun NavGraph(
    navController: Navigator,
    screenType: ScreenType,
){
    Text("${screenType}")
    NavHost(
        navigator = navController,
        initialRoute = Route.CHAT_ROUTE,
    ){
        scene(
            route = Route.SETTING_ROUTE
        ){
            Text("${screenType}")
        }
@Tlaster
Copy link
Owner

Tlaster commented Feb 19, 2024

Can you try 1.6.0-beta02 and check if it's working for you?

@RYXCP
Copy link
Author

RYXCP commented Feb 19, 2024

oh, thanks! It does work

@martinbonnin
Copy link
Contributor

I'm having a similar issue on 1.6.0. Any hint how to debug this?

@RYXCP
Copy link
Author

RYXCP commented Apr 11, 2024

I'm having a similar issue on 1.6.0. Any hint how to debug this?

When i tried the "1.6.0-beta02", i found that it resolved this issue on its own.

@martinbonnin
Copy link
Contributor

Thinking more about it, I think this might be the desired behaviour or else deeplinks might break. All the parameteres should come from the deeplink url. But not 100% sure yet

@polis
Copy link

polis commented Apr 26, 2024

I have a very similar issue in 1.6.0-rc05.
The only difference in my case that I use 2 NavHost components and one is nested into other. And Screen in nested NavHost retains its initial value.

Here is example:

var screenType = ScreenType.MEDIUM
...
@composable
fun NavGraph(
navController: Navigator,
screenType: ScreenType,
) {
Text("${screenType}")
NavHost(
navigator = rememberNavigator(),
initialRoute = Route.CHAT_ROUTE,
) {
scene(
route = Route.SETTING_ROUTE
) {
NavHost(
navigator = rememberNavigator(),
initialRoute = Route.ENOTHER_ROUTE,
) {
scene(
route = Route.ENOTHER_ROUTE
) {
Text("${screenType}")
}
}
}
}
}

@RYXCP
Copy link
Author

RYXCP commented Apr 26, 2024

If you find that the screen always displays the previous value which is outdated, maybe these will help:

In current version, updating the value outside of a NavHost could not trigger the recomposition( I guess) , namely passing values directly into a NavHost is not recommended.

It seems like you want to observe to the window size, perhaps setting up a kotlin object and check it in somewhere or simply delaying the update to NavHost scope, will be better.

@polis
Copy link

polis commented May 21, 2024

If you find that the screen always displays the previous value which is outdated, maybe these will help:

In current version, updating the value outside of a NavHost could not trigger the recomposition( I guess) , namely passing values directly into a NavHost is not recommended.

It seems like you want to observe to the window size, perhaps setting up a kotlin object and check it in somewhere or simply delaying the update to NavHost scope, will be better.

Thank you for suggestion! I moved to Navigation from JetBrains. It still in Alfa but it does not have this problem and my project is not commercial yet.

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

4 participants