geepawhill
01/29/2025, 6:46 PMclickable { onClick() }
works? I have two composables. I want one of them to "notice" when the other one is hovered. Had I something like clickable
I could do this by calling a method on the model. I tried using pointerInputs for exit and enter, but they behave very strangely, sending exit/enter pairs for each mouse move within the bounds, and never sending an exit when leaving the bounds.Zach Klippenstein (he/him) [MOD]
01/29/2025, 8:31 PMMutableInteractionSource
yourself, or observe state changes on the state returned by MutableInteractionSource.collectHoveredAsState
Zach Klippenstein (he/him) [MOD]
01/29/2025, 8:37 PM@Composable fun YourComposable() {
val interactionSource1 = remember { MutableInteractionSource() }
val interactionSource2 = remember { MutableInteractionSource() }
val hovered1 by interactionSource1.collectIsHoveredAsState()
LaunchedEffect(Unit) {
snapshotFlow { hovered1 }.collect {
// TODO: Perform action when interactionSource1 changes hovered state
}
} // etc for 2
YourHoverable(interactionSource = interactionSource1)
YourHoverable(interactionSource = interactionSource2)
}
You could collect interactions yourself but it's a little more work since you have to save Enter
interactions to match them with Exit
yourself, which collectIsHoveredAsState
does for you.