How Screen and NavDestinationScope work
mainA Screen is an entity defined using navDestination<Args>. The Args generic type defines the input parameters accepted by the screen during navigation.
Inside the screen's content block, you have access to NavDestinationScope<Args>, which provides several useful composable functions:
navController(): Provides the currentNavControllerto perform navigation.navArgs(): Retrieves the arguments passed to this screen vianavigate(screen, args).navArgsOrNull(): Same asnavArgs, but returnsnullif no data was passed or if data was lost.freeArgs<T>(): Accesses free type arguments (useful for metadata or deep-link info).clearFreeArgs(): Clears the free type arguments.navResult: Provides data passed back viaNavController.back(screen, navResult).clearNavResult(): Clears the passed navigation result.rememberViewModel(): Creates or provides a ViewModel scoped to the current screen.
data class DataScreenArgs(val t: Int)
// Screen receiving arguments
val DataScreen by navDestination<DataScreenArgs> {
val args = navArgs()
// Use args.t
}
// Screen navigating with arguments
val RootScreen by navDestination<Unit> {
val nc = navController()
nc.navigate(DataScreen, DataScreenArgs(1))
}