If I apply `scale(0.5F)` + `pointerInput` then ge...
# compose
a
If I apply
scale(0.5F)
+
pointerInput
then gestures are detected outside of the visible bounds (like
scale
is ignored). Is there any way of handling gestures only inside visible bounds? Code in the thread.
Copy code
Box(
        modifier = Modifier
            .requiredSize(128.dp)
            .scale(0.5F)
            .background(Color.Red)
            .pointerInput(Unit) {
                detectDragGestures { change, dragAmount ->
                    println(change)
                    change.consume()
                }
            },
    )
Tried different order of the modifiers, but it didn't help.
m
For the drag start that's the case, it's detecting drag only inside the scaled Box, but if you want to not detect drag change when you go outside of the visible bounds I think that you need something custom like this.
Copy code
var size by remember { mutableStateOf(Size.Zero) }
var topLeft by remember { mutableStateOf(Offset.Zero) }
Box(
    modifier = Modifier
        .requiredSize(128.dp)
        .scale(0.5F)
        .onGloballyPositioned {
            size = it.size.toSize()
            topLeft = it.localToRoot(Offset.Zero)
        }
        .background(Color.Red)
        .pointerInput(Unit) {
            detectDragGestures { change, dragAmount ->
                if (
                    change.position.x !in topLeft.x..(topLeft.x + size.width) ||
                    change.position.y !in topLeft.y..(topLeft.y + size.height)
                ) return@detectDragGestures

                change.consume()
                text = change.toString()
            }
        },
) {
    Text(text = text)
}
a
a
Oh, thanks! I will try using the workaround above until a stable 1.5.0 release.
a
You can also downgrade to 1.3.*
i
This fix will be included to the
1.4.*
patch, we'll release it soon (there are some issues with it, so no specific date)
a
@Ivan Matkov does this release include the fix for this bug? https://issuetracker.google.com/issues/270656235
i
No
a
Thanks for confirming. Should I file an issue for this on GitHub, or will the fix be eventually propagated?
i
We're merging changes Google repo regularly. In this release 1.4.3 state was merged from androidx repo. Not sure in what particular version this commit is available on Android, but if it's about 1.5 there, you can expect it in 1.5 multiplatform