korlibs / korlibs/korge

Views are not working anymore if something got dragged on the scene in Android WebView

Open
#2,157 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
3k
Forks
148
Avg merge
13h 44m
Merged PRs (30d)
1

Description

Views (e.g. uiButton) are not responding to any touch event if we use a onMove() function on any other view.

For example:
We let the user draw some signs on a whiteboard and he has to accept his drawing with a uiButton. This uiButton does not respond to any touch events after the user has drawn something.
The uiButton is working BEFORE the user starts drawing.

This behaviour can also be seen if you use your demo project "Dungeon Explorer" in a Android WebView with this url: `https://show.korge.org/#DungeonScene`.
Your Joystick is not working on an Android WebView.
But there is a workaround (maybe this will help you): You have to tap the display simultaneously with two fingers. then the joystick is working ONCE. after that, you have to double tap again to get it working.

BUT on the mac browser and on every iOS devices everything is working! Also native jvm is working fine. It is just the android WebView and Android browsers like Brave (mobile) or Chrome (mobile).

### **This is very urgent because we have deadlines! Any workaround is appreciated!**

Here is my whiteboard function for drawing:
```
return whiteboardContainer.apply {
uiMaterialLayer().apply {
size = Size(400, 400)
bgColor = Colors.DARKGRAY
radius = RectCorners(16f, 16f, 16f, 16f)

onDown {
canDraw = true
lastMouseInfo = null
}
onOver { bgColor = Colors.DARKGOLDENROD }
onOut { bgColor = Colors.DARKGRAY }
onUp { canDraw = false }

onMove { moveEvent ->
if (canDraw) {
// lastMouseInfo is null when mouse.onUp() is called,
// so we can start the drawing line on the clicked position.
// Otherwise, it would connect to the last position where mouse was going up at last.
lastMouseInfo?.let { lastInfo ->
drawnLines.add(
line(
x0 = moveEvent.currentPosLocal.x,
y0 = moveEvent.currentPosLocal.y,
x1 = lastInfo.x,
y1 = lastInfo.y,
color = Colors.GREEN
)
)
}

lastMouseInfo = Point(moveEvent.currentPosLocal.x, moveEvent.currentPosLocal.y)
renderDrawnLines(whiteboardContainer)
}
}
}
}
}
```

You can use this Android code for testing:

```
@Composable
fun GameView(
gameUrl: String
) {
Column(
modifier = Modifier.fillMaxSize()
) {
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
WebView(context).apply {
settings.apply {
javaScriptEnabled = true
javaScriptCanOpenWindowsAutomatically = true
domStorageEnabled = true
allowContentAccess = true
settings.allowFileAccess = true
}
CookieManager.getInstance().setAcceptCookie(true)
}
},
update = { webView ->
webView.loadUrl(gameUrl)
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
}

override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
println("WebView Error: ${error?.description}")
}
}
}
)
}
}
```

Here is a demo video where the user can draw his signs on a whiteboard. First User is drawing his signs and try to tap "go to memory" button, but that isn't working anymore. On the second try, the user just taps "go to memory" and the button is working as expected:

https://github.com/korlibs/korge/assets/41568761/00022b08-1361-4955-9c9a-d7cf9cfecf5a

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue using the provided GameView Android WebView setup and the Dungeon Explorer URL, then inspect the onMove, onDown, and onUp touch handling used by the whiteboard and joystick. Done means buttons and the joystick still accept touches after drawing or dragging in Android WebView and mobile browsers, without regressing macOS, iOS, or native JVM behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.