https://kotlinlang.org logo
#compose
Title
# compose
i

Ink

02/22/2022, 8:18 PM
How Can I detect when user stopped zooming Image and released fingers from the screen?
Copy code
var scale by remember { mutableStateOf(1f) }
var rotation by remember { mutableStateOf(0f) }
var offset by remember { mutableStateOf(Offset.Zero) }

val state = rememberTransformableState { zoomChange, offsetChange, rotationChange ->
    scale *= zoomChange
    rotation += rotationChange
    offset += offsetChange
}
Image(
    painter = painter,
    modifier = Modifier
        .pointerInput(Unit){
            detectDragGestures { change, dragAmount ->
                if(change.pressed){
                    scale = 1f
                    rotation = 0f
                    offset = Offset.Zero
                }
            }
        }
        .graphicsLayer(
            scaleX = scale,
            scaleY = scale
        )
        .transformable(state = state)
        .padding(vertical = 100.dp, horizontal = 150.dp)
        .fillMaxSize(),
    contentScale = ContentScale.Fit,
    contentDescription = ""
)