JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
14.85k stars 1.08k forks source link

Modifier.pointerInput or clickable not working for UIKitView #4722

Closed paxbun closed 2 weeks ago

paxbun commented 2 weeks ago

Describe the bug A clear and concise description of what the bug is.

Callbacks passed to AndroidView() via Modifier.pointerInput or Modifier.clickable are invoked, while callbacks passed to UIKitView() are not invoked.

Affected platforms

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

// MyView.kt
@Composable
expect fun MyView(modifier: Modifier)

// MyView.android.kt
@Composable
actual fun MyView(modifier: Modifier) {
  AndroidView(
    factory = {
      View(it).apply { background = ColorDrawable(Color.BLUE) }
    },
    modifier = modifier,
  )
}

// MyView.ios.kt
@Composable
actual fun MyView(modifier: Modifier) {
  UIKitView(
    factory = {
      UIView().apply { backgroundColor = UIColor.blueColor }
    },
    modifier = modifier,
  )
}

// App.kt
@Composable
fun App() {
  MyView(
    Modifier
      .fillMaxSize()
      .pointerInput(Unit) {
        detectTapGestures { offset -> println(offset) }
      }
  )
}
  1. Observe a blue background is rendered.
  2. Click anywhere.
  3. On Android, logcat reports the xy coordinates of the touch position. On iOS, nothing is printed in stdout.

Expected behavior UIKitView should also handle touch events like AndroidView.

Screenshots N/A

Additional context N/A

robxyy commented 2 weeks ago

@paxbun You can try setting interactive = false

paxbun commented 2 weeks ago

Hi @robxyy, where can I set that? I didn't notice that there is parameter interactive in UIKitView. This resolves my issue. Thanks for the comment!