Created
July 5, 2023 18:48
-
-
Save grumpyshoe/092e3abfebc546e8eaa799f902b96301 to your computer and use it in GitHub Desktop.
Composeable modifier: Pinch-To-Zoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Modifier.pinchToZoom( | |
minZoom: Float? = null, | |
maxZoom: Float? = null, | |
): Modifier = composed { | |
var zoom by remember { mutableStateOf(1f) } | |
val state = rememberTransformableState { scaleChange, _, _ -> | |
val newZoom = (zoom * scaleChange).coerceIn(minZoom ?: MIN_VALUE, maxZoom ?: MAX_VALUE) | |
zoom = newZoom | |
} | |
Modifier.graphicsLayer( | |
scaleX = zoom, | |
scaleY = zoom, | |
).transformable(state) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment