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

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

Open
pioLay opened this issue Feb 23, 2024 · 0 comments

Comments

@pioLay
Copy link

pioLay commented Feb 23, 2024

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:

Screen_recording_20240223_123850.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pending
Development

No branches or pull requests

1 participant