hotwired / hotwired/hotwire-native-android

Document/webview missing browser events after navigation

Open
#124 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
163
Forks
37
PR merge metrics
No merged PRs in 30d

Description

In our application we're using barcode scanners to receive data input and form submission using a single scan. This basically means that we're listening to keyboard events on the document to populate inputs and submit forms.

We noticed that we're missing keydown events on the document after navigation.
When scanning a barcode the listener on the document (keydown@document) doesn't get triggered.
Only after touching the screen all previously expected events are triggered.

It seems like the webview is missing focus after navigation and that it only gets the focus after touching the screen. For normal keyboard input via the onscreen virtual keyboard you don't notice this since you're already touching the screen, setting the focus. Also on desktop browsers the document keeps the focus on navigation.

As a workaround I'm focussing the webview manually by customizing the default fragment:

package nl.greenwms

import dev.hotwire.navigation.fragments.HotwireWebFragment
import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink

import android.util.Log
import dev.hotwire.core.turbo.webview.HotwireWebView

@HotwireDestinationDeepLink(uri = "hotwire://fragment/web")
open class WebFragment : HotwireWebFragment() {
    override fun onWebViewAttached(webView: HotwireWebView) {
        webView.requestFocus();
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at HotwireWebFragment and its onWebViewAttached(webView) entry point, comparing the default attachment behavior with the provided WebFragment workaround using HotwireWebView.requestFocus(). Reproduce navigation followed by barcode keydown events without touching the screen; done means document listeners receive those events after navigation without manual focus.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.