Background Info
When the user opens the bottomsheet, they are presented with a RecyclerView: The recently-selected item in the RecyclerView is auto-selected and then announced with
lastSelectedView?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED)
that's made possible with (during onCreate)
private fun applyCustomAccessibilityDelegate(view: View?, textToSay: String) {
view?.setAccessibilityDelegate(object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo) {
super.onInitializeAccessibilityNodeInfo(host, info)
info.className = ""
info.contentDescription = textToSay
}
})
}
i.e. applyCustomAccessibilityDelegate(lastSelectedView, "blah blah")
So far so good
Swipe to focus on views experience
Unfortunately, when the user swipes (single finger) left or right in an attempt to select the next item in the list, the accessibility system neither selects the next item in the list nor the RecyclerView itself - it actually focuses (and announces) on some view outside of the bottomsheet.
I've experimented with View.requestFocus() but it makes no difference in any way! Despite requestFocus() returning true
(for focusing on any nearby view), swiping left or right sets focus on a way-off view instead of a neighboring view.
No matter what, it seems the user has to swipe left and right multiple times to get focus back to the recyclerView.
How can this be improved ? Why doesn't Android select the next item in the RecyclerView when the user swipes left or right ?