Skip to content

Instantly share code, notes, and snippets.

@miguelhincapie
Created April 6, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelhincapie/333cc61ac0d8bc114e4649406401cb6b to your computer and use it in GitHub Desktop.
Save miguelhincapie/333cc61ac0d8bc114e4649406401cb6b to your computer and use it in GitHub Desktop.
Snippet to navigate through recyclerView using accessibility
private fun onDownKeyPressed(currentFocus: View): Boolean = with(currentFocus) {
getNextElementPosition().let { nextElementPosition ->
if (isPositionInbound(nextElementPosition)) {
sendFocusToListItem(nextElementPosition)
} else {
rootView.findViewById<View>(R.id.carouselRV)?.sendAccessibilityFocus()
}
}
return true
}
private fun onUpKeyPressed(currentFocus: View): Boolean = with(currentFocus) {
getPreviousElementPosition().let { previousElementPosition ->
if (isPositionInbound(previousElementPosition)) {
sendFocusToListItem(previousElementPosition)
} else {
rootView.findViewById<View>(R.id.accessibility_state)
?.sendAccessibilityFocus(View.FOCUS_UP)
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment