sceneview-android icon indicating copy to clipboard operation
sceneview-android copied to clipboard

Tap event is called multiple times and outside the node area

Open JeromeCHA opened this issue 1 year ago • 2 comments

Currently, with the version 2.2.0, I am facing the issue where hitTest result is returned even if we tapped outside the node.

The behavior can be reproduced with the following simple code.

val engine = rememberEngine()
val modelLoader = rememberModelLoader(engine)
val testNode = SphereNode(
    engine = engine,
    radius = 1f,
).apply {
    position = Position(z = -5f)
}
Scene(
    modifier = Modifier.fillMaxSize(),
    engine = engine,
    modelLoader = modelLoader,
    childNodes = rememberNodes {
        add(testNode)
    },
    onTouchEvent = { _, result ->
        // check if the tapped node is our testNode
        if (result?.node == testNode) {
            Toast.makeText(this, "Tapped on the node", Toast.LENGTH_SHORT).show()
        }
        false
    }
)

or with the gesture listener

onGestureListener = rememberOnGestureListener(
    onSingleTapConfirmed = { _, node ->
        if (node == testNode) {
            Toast.makeText(this, "Tapped on the node", Toast.LENGTH_SHORT)
                .show()
        }
    }
),

Here is the result

tap_bug

Is there something I am doing wrong? or anything I can do to avoid this?

Edit : Still occurs in 2.2.1

JeromeCHA avatar Jun 11 '24 02:06 JeromeCHA