Tlaster / PreCompose

Compose Multiplatform Navigation && State Management
https://tlaster.github.io/PreCompose/
MIT License
849 stars 49 forks source link

[BUG] Navigation功能相同代码在1.6.0及以下正常,1.6.1开始异常 #375

Open xuhuan opened 1 month ago

xuhuan commented 1 month ago

Describe the bug 在不变动代码的情况下,版本1.6.0及以下导航都是正常的,初始化后能正常跳转到默认页。将版本升级到1.6.1或者1.6.2,导航初始化后页面空白,不会进行跳转到默认页。代码显示进行跳转也不会进行。

PreComposeApp {
    val navigator = rememberNavigator()
    NavHost(
        // Assign the navigator to the NavHost
        navigator = navigator,
        // Navigation transition for the scenes in this NavHost, this is optional
        navTransition = NavTransition(),
        // The start destination
        initialRoute = "/home",
    ) {

        打印NavHost日志,所有版本都能打印
        // Define a scene to the navigation graph
        scene(
            // Scene's route path
            route = "/home",
            // Navigation transition for this scene, this is optional
            navTransition = NavTransition(),
        ) {
            打印scene日志,升级到1.6.1及以上这里日志打印不出来
            Text(text = "Hello!")
        }
    }
}

通过日志打印发现1.6.0及以下情况scene里的日志能正常打印,能跳转,内容显示正常。 升级到1.6.1及以上scene里的日志不会打印,且页面空白,不会跳转到默认页。

这种有人碰到过么?大概是什么原因导致的?感谢各位的回复🙏 @Tlaster

Tlaster commented 1 month ago

我没有办法复现这个问题,可以提供完整的复现repo吗?

xuhuan commented 4 weeks ago
    PreComposeApp {
            val navigator = rememberNavigator()
            Scaffold(
                modifier = Modifier.fillMaxSize(),
            ) { contentPadding ->
                Box(
                    modifier = Modifier
                        .padding(contentPadding)
                        .fillMaxSize()
                ) {
                    NavHost(
                        // Assign the navigator to the NavHost
                        navigator = navigator,
                        // Navigation transition for the scenes in this NavHost, this is optional
                        navTransition = NavTransition(),
                        // The start destination
                        initialRoute = "/home",
                    ) {
                        scene(
                            route = "/home",
                        ) {
                            Text(text = "home Hello!")
                        }
                    }
                }
            }
        }

定位出了问题代码所在,NavHost在Scaffold里面的表现在1.6.0及以下和以上版本的表现是不一样的。1.6.1开始NavHost写在Scaffold里面就会出现之前反馈的问题,路由不会进行跳转。切换到1.6.0就没问题。 @Tlaster