Skip to content

Map DPAD_DOWN to TAB in HAWebView#6735

Open
TimoPtr wants to merge 1 commit intomainfrom
dmap_mapping_androidtv
Open

Map DPAD_DOWN to TAB in HAWebView#6735
TimoPtr wants to merge 1 commit intomainfrom
dmap_mapping_androidtv

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented Apr 20, 2026

Summary

DPAD_DOWN to TAB remapping for Android TV

  • Extracted DPAD_DOWN mapping into HAWebView.kt
  • Applied automatically in HAWebView's factory block
  • Removed the dispatchKeyEvent override from WebViewActivity

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Copilot AI review requested due to automatic review settings April 20, 2026 15:06
@dshokouhi
Copy link
Copy Markdown
Member

you know i havent had a chance to recheck this but I wonder this is still necessary? at the time it was used to help android tv users login because they couldnt even switch to the password field using the remote control. This was before the frontend login screen was updated to be more modern. I do recall we have a bug from a keyboard only user getting stuck due to this one too.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR moves the Android TV DPAD_DOWN → TAB navigation workaround from the legacy WebViewActivity key dispatch override into the shared HAWebView composable, so the behavior is applied at the WebView level whenever HAWebView is used.

Changes:

  • Removed dispatchKeyEvent override (and KeyEvent import) from WebViewActivity
  • Added a WebView.remapDpadDownToTab() helper using an OnKeyListener
  • Applied the remapping automatically in HAWebView’s AndroidView.factory block and documented the behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt Removes the Activity-level DPAD_DOWN workaround, relying on WebView-level handling instead
app/src/main/kotlin/io/homeassistant/companion/android/util/compose/webview/HAWebView.kt Adds and applies DPAD_DOWN → TAB remapping via OnKeyListener, with updated KDoc

Comment on lines +137 to +146
private fun WebView.remapDpadDownToTab() {
setOnKeyListener { view, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && event.action == KeyEvent.ACTION_DOWN) {
view.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB))
true
} else {
false
}
}
}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new key-handling behavior (DPAD_DOWN -> TAB) but there is no automated test covering it. Please add a unit/Robolectric or Compose UI test that verifies a DPAD_DOWN key event dispatched to the WebView results in a TAB key event being forwarded, to prevent regressions across Android TV and non-TV devices.

Copilot generated this review using guidance from repository custom instructions.
@TimoPtr
Copy link
Copy Markdown
Member Author

TimoPtr commented Apr 20, 2026

you know i havent had a chance to recheck this but I wonder this is still necessary? at the time it was used to help android tv users login because they couldnt even switch to the password field using the remote control. This was before the frontend login screen was updated to be more modern. I do recall we have a bug from a keyboard only user getting stuck due to this one too.

Thanks for jumping in I remember discussing about it but I didn't remember what was the outcome .... So maybe it is not relevant anymore.

@TimoPtr TimoPtr requested a review from jpelgrom April 22, 2026 07:40
@TimoPtr TimoPtr added the WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav. label Apr 22, 2026
@jpelgrom
Copy link
Copy Markdown
Member

As you clicked the button to request a review: did you end up testing whether tab works/is still necessary with the login screen?

@jpelgrom jpelgrom changed the title Map DPAD_DOWN to TAB in HAWebViewActivity Map DPAD_DOWN to TAB in HAWebView Apr 22, 2026
@TimoPtr
Copy link
Copy Markdown
Member Author

TimoPtr commented Apr 22, 2026

As you clicked the button to request a review: did you end up testing whether tab works/is still necessary with the login screen?

I already did last time and it was working with both. I honestly didn't test again this time. (Know that I remember)

I don't know if we should keep that, but at the same I'm not under the impression that it is going to hurt us.

@jpelgrom
Copy link
Copy Markdown
Member

Maybe it won't hurt but if it is no longer necessary removing it means less code to maintain :)

@jpelgrom
Copy link
Copy Markdown
Member

@dshokouhi Do you still have a TV device with remote and are you willing to test whether onboarding can be completed at all, by any chance? 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants