最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - OnDestinationChangedListener with Typesafe navigation: Jetpack Compose - Stack Overflow

programmeradmin4浏览0评论

I'm using Jetpack Compose navigation with type-safe routes. I have these screens:

sealed class NavRoute {
    @Serializable
    object Home : NavRoute()
    
    @Serializable
    object Login: NavRoute()
    
    @Serializable
    data class OrderDetail(val orderId: Int) : NavRoute()
}

Is there any way to cast navDestination to my TypeSafe NavRoute class?

DisposableEffect(navController) {
    val listener = NavController.OnDestinationChangedListener { _, navDestination, _ ->
        Log.d("ScreenName", "Destination changed to ${navDestination.route}")
    }
    navController.addOnDestinationChangedListener(listener)
    onDispose {
        navController.removeOnDestinationChangedListener(listener)
    }
}
发布评论

评论列表(0)

  1. 暂无评论