Skip to content

Jetpack Compose Support: Unable to Press Two Pads Simultaneously in Android View Integration #28

Description

@tanphuccgl

I am developing an Android application using Jetpack Compose, and in one part of my app, I use XML components to create control pads (RadialGamePads). While I have successfully integrated these pads within Compose, I am facing a problem:

Situation Description: I have created a RadialGamePadScreen in Compose, where I use AndroidView to embed a Fragment (FragmentGB) containing the pads. However, when using Compose, I am unable to press both pads at the same time, whereas this functionality works perfectly in XML.

Code Example:

@Composable
fun RadialGamePadScreen() {
    val context = LocalContext.current
    var leftPad by remember {
        mutableStateOf<RadialGamePad>(
            RadialGamePad(
                SamplePadConfigs.GB_LEFT,
                8f,
                context
            )
        )
    }
    var rightPad by remember {
        mutableStateOf<RadialGamePad>(
            RadialGamePad(
                SamplePadConfigs.GB_RIGHT,
                8f,
                context
            )
        )
    }
    val lifecycleOwner = LocalLifecycleOwner.current
    val lifecycle = lifecycleOwner.lifecycle
    LaunchedEffect(Unit) {
        merge(leftPad.events(), rightPad.events())
            .flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED)
            .collect {
                handleEvent(it)
            }
    }
    Column(modifier = Modifier.fillMaxSize()) {
        AndroidView(
            factory = { context ->
                leftPad.apply {
                    gravityX = -1f
                    gravityY = 1f
                    leftPad = this
                }
            },
            modifier = Modifier.weight(1f)
        )

        AndroidView(
            factory = { context ->
                rightPad.apply {
                    gravityX = 1f
                    gravityY = 1f
                    rightPad = this
                }
            },
            modifier = Modifier.weight(1f)
        )
    }

}

Reason for Support: The inability to press both pads simultaneously might be due to how Jetpack Compose handles input events differently from XML. I would like to know if there is a way to resolve this issue in Compose or if this is a current limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions