How to pass a custom Parcelable object in Jetpack Compose Type-Safe Navigation (Navigation 2.8.0+)?

13 hours ago 1
ARTICLE AD BOX

With the release of Jetpack Compose Navigation 2.8.0, we can now navigate using type-safe objects (@Serializable data classes) instead of route strings. However, if my route data class contains a custom Parcelable object, the navigation component doesn't know how to handle it by default. For example, I have a sealed class for my routes:

@Serializable sealed class Route { @Serializable data class DetailsScreen(val userData: UserData) : Route() }

Where UserData is a @Parcelize class. How do I define and register a custom NavType for this Parcelable object so I can pass it safely in the new Compose navigation graph?

Read Entire Article