Commit 0d88498
authored
fix(iOS, Stack): Fix for reattaching Screens when swiping back quickly (#3584)
## Description
This PR introduces logic to collect only active (non-dismissed) screen
controllers coming from JS state.
When a screen gets dismissed on the native side, its state is sent
asynchronously to the JS. In scenarios where multiple screens are
dismissed quickly, this can result in stale updates being sent from JS
to native. These outdated updates may reference screens that are no
longer part of the native view hierarchy.
Since view recycling is disabled, we do not expect the `RNSScreenView`
that was dismissed to be reattached; a new instance should be created
when we push an update from JS. Then the new controller instance will be
initialized, so these associated with detached screens won't be reused
again. Therefore, we can safely filter them out from JS state on the
native side. On the JS side, the state will stabilize at some point and
align with native, once we receive all asynchronous events.
```objective-c
@implementation RNSScreenView {
...
- (void)initCommonProps
{
_controller = [[RNSScreen alloc] initWithView:self];
```
To address this, we now filter out any dismissed controllers from the
list received from JS.
> [!NOTE]
> I'm leaving the previous behavior as the default, and I'm adding
`iosPreventReattachmentOfDismissedScreens` flag that can enable this
fix. We're right before a very important release, and this PR is
touching the very basic logic; therefore, we don't want to have this fix
enabled by default for now. You can opt-in by setting
`featureFlags.experiment.iosPreventReattachmentOfDismissedScreens =
true`. Any feedback would be valuable here.
Closes:
#2559
## Changes
- Added an attribute to mark controllers that were dismissed.
- Added logic for filtering out screens dismissed natively from JS
state.
## Before & after - visual documentation
| Before | After |
| --- | --- |
| <video
src="https://github.com/user-attachments/assets/684a5b6d-4a1a-4da5-9bbb-3973f2cc342f"
/> | <video
src="https://github.com/user-attachments/assets/839debc5-7b8c-43b8-8fa6-6ec9595e708c"
/> |
## Test plan
Added Test 2559.
## Checklist
- [x] Included code example that can be used to test this change.
- [ ] Updated / created local changelog entries in relevant test files.
- [x] For visual changes, included screenshots / GIFs / recordings
documenting the change.
- [ ] For API changes, updated relevant public types.
- [ ] Ensured that CI passes1 parent ba52d2f commit 0d88498
13 files changed
Lines changed: 193 additions & 2 deletions
File tree
- FabricExample
- android/src
- main/java/com/swmansion/rnscreens
- paper/java/com/facebook/react/viewmanagers
- apps/src/tests/issue-tests
- ios
- src
- components
- fabric
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1620 | 1620 | | |
1621 | 1621 | | |
1622 | 1622 | | |
| 1623 | + | |
1623 | 1624 | | |
1624 | 1625 | | |
1625 | 1626 | | |
| |||
1630 | 1631 | | |
1631 | 1632 | | |
1632 | 1633 | | |
| 1634 | + | |
1633 | 1635 | | |
1634 | 1636 | | |
1635 | 1637 | | |
| |||
1887 | 1889 | | |
1888 | 1890 | | |
1889 | 1891 | | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
1890 | 1905 | | |
1891 | 1906 | | |
1892 | 1907 | | |
| |||
1901 | 1916 | | |
1902 | 1917 | | |
1903 | 1918 | | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
1904 | 1926 | | |
1905 | 1927 | | |
1906 | 1928 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
774 | 774 | | |
775 | 775 | | |
776 | 776 | | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
777 | 787 | | |
778 | 788 | | |
779 | 789 | | |
| |||
1363 | 1373 | | |
1364 | 1374 | | |
1365 | 1375 | | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
1366 | 1390 | | |
1367 | 1391 | | |
1368 | 1392 | | |
| |||
0 commit comments