Colton Idle
04/07/2023, 8:34 AM@Composable
fun Something(itemClick: (Int) -> Unit){}
I need to send an Int back up with the item click so I know which item was clicked.
So generally, if I find myself passing in a lambda that has a parameter, would that typically mean I need two args defined so I can do this
@Composable
fun Something(itemId: Int, itemClick: (Int) -> Unit){
itemClick(itemId)
}
or should I just be able to do {itemClick}
or something?Colton Idle
04/07/2023, 8:39 AM(itemClick: (Int, String) -> Unit)
and then I'm like "wait do I need two additional args?"ephemient
04/07/2023, 8:54 AMfor (item in items) {
Something(item) {
doSomething(item)
Colton Idle
04/07/2023, 3:05 PMwhy do you need that?well I guess that answers my question I think ive been doing this all wrong. lol 🤦
Hackintoshfive
04/10/2023, 8:22 AMI think ive been doing this all wrong. lol 🤦It's a valid thing to do, but only in specific circumstances. Having the correct parameters passed directly will save you from having to instantiate more lambda objects, and might have a slight impact on performance. But usually it's not worth the effort, and most people wouldn't use it.
Colton Idle
04/13/2023, 2:06 PMOuterCardView(
state = myState.cardStates[index]
) {
onCardClicked(
(myState.cardStates[index] as ConcreteState).uuid,
(myState.cardStates[index] as ConcreteState).isOptedIn == true
)
}
and OuterCardView is defined as such
@Composable
fun OuterCardView(state: MyState, onClicked: (String) -> Unit) {
Card() {
when (state) {
is ConcreteState -> InnerItemView(state, onClicked)
//is whatever...
}
}
}
and
@Composable
private fun InnerItemView(state: MyState, onClicked: (String) -> Unit) {
Row(
Modifier
.clickable {
onClicked(state.uuid)
}
//...
}
like. how does this work/compile. maybe i need sleepCLOVIS
04/13/2023, 2:07 PMColton Idle
04/13/2023, 2:41 PMOuterCardView(
state = myState.cardStates[index]
) {
onCardClicked(
(myState.cardStates[index] as ConcreteState).uuid,
(myState.cardStates[index] as ConcreteState).isOptedIn == true
)
}
and OuterCardView is defined as such
@Composable
fun OuterCardView(state: MyState, onClicked: () -> Unit) {
Card() {
when (state) {
is ConcreteState -> InnerItemView(state, onClicked)
//is whatever...
}
}
}
and
@Composable
private fun InnerItemView(state: MyState, onClicked: () -> Unit) {
Row(
Modifier
.clickable(onClicked)
//...
}