Android TV D-Pad Bug Fixed by Swapping onKeyEvent for onPreviewKeyEvent in Compose
A bug on Android TV caused long-pressing the d-pad center button on a channel card to unreliably toggle the favorite action, failing entirely on some devices. The root cause was a conflict between Jetpack Compose's onKeyEvent and onPreviewKeyEvent modifier hooks, which operate at different phases of Android's key-event dispatch chain. The onKeyEvent handler fires during the bubble phase, where the click handler was consuming ACTION_DOWN events before the long-press logic could execute. Switching to onPreviewKeyEvent resolved the issue by intercepting the event during the earlier capture phase, before any click machinery could interfere. Developers are advised to use onPreviewKeyEvent whenever a long-press or secondary key action shares a composable with a click handler to avoid similar race conditions.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in