https://kotlinlang.org logo
#compose
Title
# compose
g

Gabriel

10/23/2020, 7:09 PM
I'm using one of the snapshots of compose for playing with navigation, but I'm not sure how to pass arguments through, for eg I have a list of images, I click on one and want to be taken through to the next screen but with the id or something of the image passed through
Copy code
sealed class Screen(val route: String) {
	object ImageList : Screen("image/list")
	object ImageItem : Screen("image/item")
}

@ExperimentalCoroutinesApi
@InternalCoroutinesApi
@Composable
fun BasicNav(viewModel: ImageListViewModel) {
	navController = rememberNavController()
	NavHost(navController, startDestination = Screen.ImageList.route) {
		composable(Screen.ImageList.route) { ImageListScreen(viewModel) }
	}
}

fun NavigateTo(screen: Screen) {
	navController.navigate(screen.route)
}
And then I've got a Card with a clickable modifier that calls
NavigateTo(Screen.ImageItem)
but don't know how to pass args through the nav
Think of it like a REST URL -
images/{id}
shows the image at
id
w

wisdom

10/23/2020, 9:17 PM
Thanks 😊 @Ian Lake
g

Gabriel

10/24/2020, 12:55 AM
Right, got yah, thanks!!