Hi. Is there a way to use Modifier.transformable(s...
# compose
g
Hi. Is there a way to use Modifier.transformable(state = state) on LazyRow?
Here is the code
Copy code
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        val vm = ZoomViewModel()
        setContent {
            ListZoomTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { padding ->
                    TransformableSample(onZoomChanged = {
                        vm.onZoomChanged(it)
                    })
                }
            }
        }
    }
}

class ZoomViewModel : ViewModel() {

    fun onZoomChanged(zoom: Float) {
        if (zoom == 1f) return
        if (zoom > 1) {
            println("Zoom in")
        } else {
            println("Zoom out")
        }
    }
}

@Composable
private fun TransformableSample(onZoomChanged: (Float) -> Unit = {}) {
    // set up all transformation states
    var scale by remember { mutableStateOf(1f) }
    val state = rememberTransformableState { zoomChange, _, _ ->
        scale *= zoomChange
    }

    LaunchedEffect(state.isTransformInProgress) {
        if (!state.isTransformInProgress) {
            onZoomChanged(scale)
        }
    }

    LazyRow (
        Modifier
            // apply other transformations like rotation and zoom
            // on the pizza slice emoji
            .graphicsLayer(scaleX = scale)
            // add transformable to listen to multitouch transformation events
            // after offset
            .transformable(state = state)
            .fillMaxSize()
    ) {
        items(100) {
            Text("Item $it")
        }
    }
}
I'd like to make zoom in/zoom out functionality
above code works perfectly with a Box, but does not with LazyRow. Any ideas how to make it work?
found a solution with
Copy code
.pointerInput(Unit) {
                awaitEachGesture {
                    awaitFirstDown()
                    do {
                        val event = awaitPointerEvent()
                        scale *= event.calculateZoom()
                    } while (event.changes.any { it.pressed })
onZoomChanged(scale)
                    scale = 1f
                }
            }