Hey! If anybody finds this useful, I’m using a mod...
# compose-ios
m
Hey! If anybody finds this useful, I’m using a modifier that does on Android nothing and on iOS applies an animated onClick by shrinking and growing the item. I find it useful since it adds a native touch.
Copy code
private const val IOS_BUTTONS_SCALE_WHEN_PRESSED = 0.96f

val BUTTONS_SCALE_WHEN_PRESSED = if (isiOS) IOS_BUTTONS_SCALE_WHEN_PRESSED else 1f

@Composable
fun Modifier.adaptiveClick(onClick: () -> Unit): Modifier {
    if (isiOS) {
        val interactionSource = remember { MutableInteractionSource() }
        val isPressed by interactionSource.collectIsPressedAsState()
        val targetScale = if (isPressed) BUTTONS_SCALE_WHEN_PRESSED else 1f
        val scale by animateFloatAsState(targetValue = targetScale)

        return this
            .clickable(
                interactionSource = interactionSource,
                indication = null,
                onClick = onClick
            )
            .scale(scale)
    } else {
        return this.clickable(onClick = onClick)
    }
}
Usage:
Copy code
modifier = Modifier
            .fillMaxWidth()
            .height(80.dp)
            .adaptiveClick { onSelectReasonClicked() }
👍 8
📱 1
thank you color 1
c
buttons on ios shrink and grow? interesting!
maybe worth being a contributor to this library: https://github.com/alexzhirkevich/compose-cupertino
m
@Colton Idle Some apps do, Slack for example sometimes
👀 1
m
Added to Calf : https://github.com/MohamedRejeb/Calf/pull/99 You can use
graphicsLayer
Modifier instead of
scale
to avoid recompositions.
c
awesome and TIL about calf. thanks!