Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement temporary workaround for interop view intercepting touches for popups. #835

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ val UIKitViewAndDropDownMenu = Screen.Example("UIKitViewAndDropDownMenu") {
contentAlignment = Alignment.Center
) {
UIKitView(modifier = Modifier.fillMaxSize(), factory = { MKMapView() })
ButtonAndDropDownMenu("Menu not over UIKitView")
ButtonAndDropDownMenu("Menu over UIKitView")
}
Divider()
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,27 @@ class ComposeScene internal constructor(
snapshotChanges.perform()
}

internal fun hitTestInteropView(position: Offset): Boolean {
// TODO:
// Temporary solution copying control flow from [processPress].
// A proper solution is to send touches to scene as black box
// and handle only that ones that were received in interop view
// instead of using [pointInside].
owners.fastForEachReversed { owner ->
if (owner.isInBounds(position)) {
return owner.hitInteropView(
pointerPosition = position,
isTouchEvent = true,
)
} else if (owner == focusedOwner) {
return false
}
}

// We didn't pass isInBounds check for any owner 🤷
return false
}

/**
* Render the current content on [canvas]. Passed [nanoTime] will be used to drive all
* animations in the content (or any other code, which uses [withFrameNanos]
Expand Down Expand Up @@ -954,4 +975,4 @@ internal expect fun createSkiaLayer(): SkiaLayer

internal expect fun NativeKeyEvent.toPointerKeyboardModifiers(): PointerKeyboardModifiers

private val PointerInputEvent.isGestureInProgress get() = pointers.fastAny { it.down }
private val PointerInputEvent.isGestureInProgress get() = pointers.fastAny { it.down }
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,12 @@ internal actual class ComposeWindow : UIViewController {

override fun pointInside(point: CValue<CGPoint>, event: UIEvent?): Boolean =
point.useContents {
val hitsInteropView = attachedComposeContext?.scene?.mainOwner?.hitInteropView(
pointerPosition = Offset(
(x * density.density).toFloat(),
(y * density.density).toFloat()
),
isTouchEvent = true,
) ?: false

!hitsInteropView
val position = Offset(
(x * density.density).toFloat(),
(y * density.density).toFloat()
)

!scene.hitTestInteropView(position)
}

override fun onPointerEvent(event: SkikoPointerEvent) {
Expand Down