Created
April 6, 2020 22:44
-
-
Save miguelhincapie/333cc61ac0d8bc114e4649406401cb6b to your computer and use it in GitHub Desktop.
Snippet to navigate through recyclerView using accessibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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