Commit 9fbc6c3
feat(Android): Add focused states on page transitions (software-mansion#1894)
## Description
Currently, on Android TV devices when user is switching between views
the last focused child is lost. This seems like an incorrect behavior -
In software-mansion#1706 people are reporting that on Android TV the last focused
element should be stored.
This PR introduces the change to remember last focused element on
previous screen.
For now I've added a statement that the last element should be stored
only for Android TV, but we should discuss if we also should store those
elements for classic Android - I've noticed that it's possible to focus
an element on a normal screen, but I've achieved it only by switching
between elements with arrows on keyboard (so is it possible to focus an
element just by touching a screen? Maybe TalkBack is also focusing the
elements?).
<details><summary>
Focusing elements on Android
</summary>
https://github.com/software-mansion/react-native-screens/assets/23281839/4f62ae66-f411-4c45-b678-1e47c3fa4ff2
</details>
Fixes software-mansion#1706.
## Changes
- Added `isTelevision` method that checks if user is currently using
Android TV.
- Added `lastFocusedChild` variable with an implementation for finding
last focused elements.
## Screenshots / GIFs
Here you can add screenshots / GIFs documenting your change.
You can add before / after section if you're changing some behavior.
### Before
https://github.com/software-mansion/react-native-screens/assets/23281839/0e3e0ad4-a202-43c3-b688-6c66f76a43f8
### After
https://github.com/software-mansion/react-native-screens/assets/23281839/998dfa5c-6def-47f2-b129-425a2257319a
## Test code and steps to reproduce
You can test those changes on `Example` application by switching between
examples with arrows on the keyboard.
## Checklist
- [ ] Ensured that CI passes1 parent 3c2c559 commit 9fbc6c3
File tree
2 files changed
+37
-0
lines changed- android/src/main/java/com/swmansion/rnscreens
- utils
2 files changed
+37
-0
lines changedLines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
| |||
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
126 | 141 | | |
127 | 142 | | |
128 | 143 | | |
| |||
163 | 178 | | |
164 | 179 | | |
165 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
166 | 191 | | |
167 | 192 | | |
168 | 193 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments