hrm ... with Navigation, is this the proper way to...
# compose
b
hrm ... with Navigation, is this the proper way to deal with an argument that is an Enum value? I have a sealed class with my routes:
Copy code
sealed class Screen(val route: String, val title: String, val isTopLevel: Boolean = false) {

    object Category: Screen("category/{postType}", "Category") {
        // here I define a NavType.EnumType for my enum that is used for an argument.
        val postTypeArgType = NavType.EnumType(PostType::class.java)
        
        fun buildRoute(postType: PostType): String {
            return "category/${postType.name}"
        }
    }

    // ... more screen routes defined here..
}
Then I use the Category to build the composable() in the NavGraph Builder. And I use the
postTypeArgType
which is a
NavType.EnumType
from the Category object above to get the postType argument. Is this the right approach?
Copy code
composable(Screen.Category.route,
        arguments = listOf(
            navArgument("postType") { type = Screen.Category.postTypeArgType },                            
            navArgument("title") { type = NavType.StringType }
        )
    ) { backStackEntry ->
        val vm: CategoryScreenViewModel = navViewModel()

        // Is this the right way to get the `postType` argument from the backstack entry?
        val postType = Screen.Category.postTypeArgType.get(backStackEntry.arguments?: Bundle(), "postType") ?: PostType.OTHER

        CategoryScreen(vm, postType)
    }
i
Enums are Serializable, so you'd want to use Bundle's
getSerializable()
method