fix(Android, Stack v4): fix keyboard navigation focus for form sheet #3245
+59
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes keyboard navigation focus handling for form sheets on Android.
Previously, it was possible to focus elements in the view displayed below the form sheet.
Closes #3188.
focus_before.mp4
focus_after.mp4
Context
In
ScreenStack
, there is already logic to handle accessibility focus viaimportantForAccessibility
prop. I checked that the prop is changed correctly - there were no regressions here.I stumbled upon an issue in
react-native
repo where one of the users explained that Android handles screen readers focus and keyboard navigation focus differently. In order to block keyboard navigation focus, you need to setfocusable
anddescendantFocusability
properties - when implemented inScreenStack
, this started working correctly (after clickingarrow-down
, focus did not leave the formsheet).Another problem that appeared is that the button used to open the form sheet remained focused after form sheet had been already opened. I attempted to use
requestFocus()
on the form sheet's screen but if there is a text input in the form sheet, it started working as if we setautoFocus
on the input field.focus_withRequestFocus.mp4
This also impacted regular touch navigation. I decided to use
clearFocus
on previous screen instead - this works as expected: first button in the screen is focused after opening the form sheet.One thing I noticed is that when you go back from a screen, nothing is focused (I checked with layout inspector) - this is not a regression but we should have a look at it in the future. Native app (settings) on API 36 keeps focus when screen is popped. I created an issue to investigate this: https://github.com/software-mansion/react-native-screens-labs/issues/474.
Changing focusability on Android
Starting from API 26,
focusable
can be set toNOT_FOCUSABLE/FOCUSABLE/FOCUSABLE_AUTO
. Prior to API 26, this was a boolean prop - that's why there is some extra code to handle both cases (changeFocusability
andchangeFocusabilityCompat
functions inScreen.kt
).Changes
Screen
for API <= 25 and API >= 26importantForAccessibility
focusable
tofalse/NOT_FOCUSABLE
forDimmingView
(this caused missing focus after popping apush
screen that was pushed over form sheet)onUpdate
Test code and steps to reproduce
Run
TestFormSheet
and use the keyboard to navigate.Checklist