Erlan Amanatov
12/20/2022, 6:53 AMmutableInteractionSource's
pressed state.
So simplified version of my composable looks like this
@Composable
fun Sbn(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
) {
val pressed by interactionSource.collectIsPressedAsState()
val target by rememberUpdatedState(newValue = if (pressed) Color.Red else Color.Green)
Box(
modifier = Modifier
.padding(24.dp)
.size(64.dp)
.background(color = target)
.clickable(
interactionSource = interactionSource,
indication = null,
onClick = {}
),
)
}
It works fine, but if I put it in a scrollable column, the pressed state works with some kind of delay. Any workarounds?
Video in threadErlan Amanatov
12/20/2022, 6:53 AMColton Idle
12/20/2022, 7:47 AMCicero
12/20/2022, 7:50 AMAlbert Chang
12/20/2022, 9:01 AMViewConfiguration.getTapTimeout()
, which defaults to 100ms in AOSP.Erlan Amanatov
12/20/2022, 9:03 AMLouis Pullen-Freilich [G]
12/20/2022, 2:57 PMval target by rememberUpdatedState(newValue = if (pressed) Color.Red else Color.Green)
If the press is short, pressed
will go from false to true and back to false so quickly that it will never be reflected on screen, because the change will happen within one frameLouis Pullen-Freilich [G]
12/20/2022, 2:57 PMLouis Pullen-Freilich [G]
12/20/2022, 2:58 PMErlan Amanatov
12/20/2022, 2:58 PMLouis Pullen-Freilich [G]
12/20/2022, 2:59 PMLouis Pullen-Freilich [G]
12/20/2022, 2:59 PMErlan Amanatov
12/20/2022, 3:00 PMLouis Pullen-Freilich [G]
12/20/2022, 3:01 PM