I hope you all are doing very well.
I'm very new to Kotlin so please be patient with me.
I created a single page in jetpack compose, as you can see in the image below, it needs decorations but at least I want to implement the functionality. Simple app interface with lazy column at the left and data display at the right.
at the left is a lazy column that display the a list of items from an arraylist. the lazy column has cards within that is clickable.
What I need is that once the use click on an item from the column the rest of the item details are displayed in the second composable at the right side.
the code looks like this
@Composable
fun Greeting() {
Row(
modifier = Modifier.fillMaxSize()
) {
LazyColumn(
modifier = Modifier
.fillMaxHeight()
.width(150.dp)
.background(color = Color.LightGray)
) {
items(photoList) { item ->
ProfileCard(photo = item) { <--- i need the item into the other composable.
// photoContent(
// id = item.id,
// owner = item.owner,
// secret = item.secret,
// server = item.server,
// farm = item.farm,
// title = item.title,
// ispublic = item.ispublic,
// isfriend = item.isfriend,
// isfamily = item.isfamily,
// url_s = item.url_s,
// height_s = item.height_s,
// width_s = item.width_s
// )
}
}
}
photoContent(
id = "",
owner = "",
secret = "",
server = "",
farm = 0,
title = "",
ispublic = 0,
isfamily = 0,
isfriend = 0,
url_s = "",
height_s = 0,
width_s = 0
)
}
}
this click function is from the displayed card
@Composable
fun ProfileCard(photo: photo, clickAction: () -> Unit) {
Card( //We changed the default shape of Card to make a cut in the corner.
modifier = Modifier
.padding(top = 4.dp, bottom = 4.dp, start = 16.dp, end = 16.dp)
.fillMaxWidth()
.wrapContentHeight(
align = Alignment.Top
)
.clickable { clickAction.invoke() }, //<-- moving the action to main composable.
elevation = 8.dp,
backgroundColor = Color.White // Uses Surface color by default, so we have to override it.
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start
) {
ProfileContent(photo, Alignment.Start)
}
}
}
I tried several ways to pass the data into the other composable but I always get the error:
@composable invocations can only happen from the context of an @composable function
and I can't remove the @Composable
annotation because it has composable contents...
How can I pass the data this way? or it is not possible without Navigation? but that requires the user to open another page not the current one...