Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Attachment actions
Unintended behavior
View staffing
Description
Component used: ViewPager2
Version used: 1.0.0
Devices/Android versions reproduced on: Multiple/Emulator (Android TV) API 29
Context
Dpad navigation on Android TV.
The
ViewPager2
is expected to changecurrentItem
only on programmatic events.Summary
A
ViewPager2
withisUserInputEnabled = false
,focusable="false"
andfocusableInTouchMode="false"
does not stop dpad navigation from focusing items in other pages/fragments that are off-screen. This causes dpad navigation within a page displayed in aViewPager2
to misbehave, e.g. on Android TV.Steps to reproduce
(See also attached example project)
ViewPager2
)Expected
Pages outside the screen should not be focusable. The last focused item in the current page should remain focused (navigation to focusables outside the viewpager itself should be supported!).
Actual
Focus moves to a focusable
View
in a page off-screen. Sometimes this causes dpad navigation to stop working completely inside the app.Workaround
Override
onBindViewHolder
in yourFragmentStateAdapter
and explicitly setisFocusable = false
anddescendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
on theFragmentViewHolder.itemView
. Then, whenViewPager2.currentItem
is modified, reset these values for theFragmentViewHolder.itemView
at positioncurrentItem
.Note that still causes the
ViewPager2
to load more pages in the pressed direction until all pages in that direction has been loaded (this happens in the background and is invisible to the user).