Commit 257a53c
authored
feat(Tabs): special effects refactor (#3440)
## Description
Refactors special effects on both platforms:
- fixes disabling `popToRoot` on iOS 26,
- fixes special effects running on regular (not repeated) tab change on
Android,
- adds `repeatedSelectionHandledBySpecialEffect` to
`NativeFocusChangeEvent` on both platforms (now the event is sent on
every tab press with appropriate flag value),
- adds support for `specialEffects` on Paper+iOS.
Closes
software-mansion/react-native-screens-labs#579.
Closes
software-mansion/react-native-screens-labs#574.
### Recordings
Pay attention to logs.
#### Android
https://github.com/user-attachments/assets/54887d06-f6fa-4bb9-a9bd-2642a8af31b2
#### iOS
https://github.com/user-attachments/assets/c06505dc-e4e6-44b9-90f3-5d18c3345c01
### Native pop to root on iOS 26
UIKit natively has "pop to root" effect in `UITabBarController` but
prior to iOS 26, it worked only when `UINavigationController` was direct
child of `UITabBarController`. In `screens`, `RNSTabBarController` has
`RNSTabsScreenViewController` children view controllers and
`RNSScreenStack` can be a child VC of `RNSTabsScreenViewController`.
This prevents native effect from working on iOS versions prior to 26.
Starting from iOS 26, `UITabBarController` also detects nested
`UINavigationController`s. This interaction happens when we return
`true` from `tabBarController:shouldSelectViewController:` delegate
method. This would work for natively-driven tabs but for controlled
tabs, we need to return `false` to prevent tab change on the native side
-> that's why we decided to use only our own implementation and disable
native effect by always returning `false` from
`tabBarController:shouldSelectViewController:` on repeated tab
selection.
## Changes
- handle `specialEffects` prop on iOS, Paper,
- add `repeatedSelectionHandledBySpecialEffect` to
`NativeFocusChangeEvent`
- update docs (move special effects and freeze to general section, clean
up)
- return `false` from `tabBarController:(UITabBarController
*)tabBarController
shouldSelectViewController:(UIViewController *)viewController` on
repeated tab selection on iOS (disables native pop to root interaction
which is available starting from iOS 26)
- prevent running `onItemSelectedListener` after menu selection on
Android (it runs on click for the first time and it would run for the
second time after update from JS which would activate special effect
erroneously)
## Test code and steps to reproduce
Run `TestBottomTabs`. Test repeated selection with different special
effects enabled on `Tab4`. Make sure that special effects don't run when
changing from other tab to `Tab4`.
## Checklist
- [x] Included code example that can be used to test this change
- [x] Updated TS types
- [x] Updated documentation
- [x] Ensured that CI passes1 parent 9e8bf52 commit 257a53c
File tree
13 files changed
+171
-98
lines changed- android/src/main/java/com/swmansion/rnscreens/gamma/tabs
- event
- ios/bottom-tabs
- host
- screen
- src
- components/bottom-tabs
- fabric/bottom-tabs
13 files changed
+171
-98
lines changedLines changed: 12 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
259 | 263 | | |
260 | 264 | | |
261 | 265 | | |
| |||
352 | 356 | | |
353 | 357 | | |
354 | 358 | | |
355 | | - | |
| 359 | + | |
356 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
357 | 364 | | |
358 | 365 | | |
359 | 366 | | |
| |||
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
Lines changed: 13 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| 40 | + | |
| 41 | + | |
31 | 42 | | |
32 | 43 | | |
33 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
| 264 | + | |
| 265 | + | |
265 | 266 | | |
266 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
267 | 271 | | |
268 | 272 | | |
269 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
46 | 41 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
52 | 45 | | |
53 | | - | |
54 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
55 | 49 | | |
56 | 50 | | |
57 | 51 | | |
| |||
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
649 | 649 | | |
650 | 650 | | |
651 | 651 | | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
652 | 676 | | |
653 | 677 | | |
654 | 678 | | |
| |||
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
| |||
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
| 47 | + | |
| 48 | + | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
0 commit comments