Commit 0893e0d
authored
feat(Android, Stack v5): make Transition API work (#3629)
## Description
> [!note]
> To support predictive back gesture on Android, we need to either use
`Animator API`
> or `Transition API` for screen animations. The [`Animation API` is not
compatible with predictive back
gesture](https://developer.android.com/guide/navigation/custom-back/support-animations#fragments).
> In stack v4, with small exception for formsheets we've heavily relied
on `Animation API` and we can
> not reuse that code, unfortunately.
This PR intends to make Transition API work on Android for us.
Currently, when
attempting to use it we have problems with:
1. disappearing shadows,
2. jumping content,
3. non-continuous animations (e.g. predictive back gesture),
4. native-pop missing animation.
| Most of the bugs described above |
| --- |
| <video
src="https://github.com/user-attachments/assets/7f5cf2e8-5b6a-41ec-8dc4-43e8e40578a0"
alt="before" /> |
| This video does not showcase issues no. 3 & 4, but trust be bro, they
are there |
This identifies root causes for each of those problems and introduces
changes to
fix them.
It also adds an appropriate feature test and sets some Slide animation,
so we
can observe anything when testing. This is not meant to be the default
animation
or something. Just a placeholder animation.
## Changes
I encourage reading through particular commits, as I tried to give each
of them
a meaningful message.
Here I list most important changes:
* CAUTION: bump native android library dependencies & add depencency on
`transition`
I've decided to bump appcompat, fragment deps.
This is done mostly in hope to get rid of as many problems
as possible with animations.
Dependency on `transition` is added because `transition@1.5.0`
is required for compatibility with predictive back gesture, so I want
to have that version under control.
`fragment` dependency is required to at least 1.7.0 by predictive back
gesture.
I've bumped other deps to ensure that they do not force lower version
for `fragment` or `transition`.
See:
<https://developer.android.com/guide/navigation/custom-back/support-animations#use_existing_apis>
* Set `isTransitionGroup` for `StackScreen` to enable Transition API
usage
This is crucial. This assures that whole StackScreen subtree (including
the StackScreen itself) is animated together. W/o this the animation is
glitchy - some of the views can disappear, some views can jump to
different location mid-transition, **shadows are lost**. Setting this
option fixes things.
I wonder what will be impact of using this on SET & Reanimated
integration. Hopefully it'll be possible to animate some views anyway.
* Merge AddOp & SetPrimaryNavFragmentOp + add OnCommitCallbackFragmentOp
This is kinda complex change.
First, this commit removes `SetPrimaryNavFragmentOp` and merges it to
`AddOp` creating new `AddAndSetAsPrimaryOp`. This is done, because
previously, we've executed a `AddOp` that has been saved to back stack
with e.g. some fragment A, and then we executed another transaction
impacting fragment A by executing `SetPrimaryNavFragmentOp` & it has
not been saved to back stack. This led to situation, where later popping
A would not be interpreted as `pop` operation (explained below) by
fragment manager and in consequence this would break predictive back
gesture & native pop operation - after touch release animation would be
completed immediately & not by smoothly animating to completion.
Fragment manager interprets a batch of fragment transactions as "pop"
only when last operation in a batch is "pop". Setting primary navigation
fragment is not a "pop" operation. I haven't tested that in runtime, but
by reading the code of fragment manager I've figured that we can not
queue the `SetPrimaryNavFragmentOp` before other operations, because
it'll trigger an exception that we try to make not-yet-attached fragment
primary navigation fragment. However, maybe it's worth trying.
Currently, I've gone with different approach. Now, I batch every add
operation with
set-primary-nav-fragment & add them to back stack together. *Thanks to
that,
we no longer manually manage the primary fragment. Fragment manager does
that for us, when reverting stack transactions.*
We still have a need to run a callback on transaction commit to update
the top fragment (prevent native dismiss requirement), therefore
exactly due to reasons explained above, I've added
`OnCommitCallbackFragmentOp` and scheduled it before any other
operations. It can not be batched with other operations, because a
transaction with `runOnCommit` configured can NOT be added to back stack
(callback can not be serialized).
* Fix transitions in nested stacks
Component views on new architecture receive their first layout after the
view hierarchy is
assembled and attached to window. Note, that in case of screen views &
their sub-trees
(including nested containers) this does not hold. The container is
updated later, after React
mounting transaction ends, therefore the views are attached to the
window much later, hence
their `isLaidOut` returns false, breaking transitions & animations.
NOTE: Currently, screens attached even to the "top" (non-nested)
container return false from `isLaidOut`! Exactly due to mechanism
described above. I do not know whether it causes any problems, but
potentially - yes. We should be aware of that.
The fix here is to lay out the container. I need to do that
synchronously, before we schedule the transitions. I'm not aware of
API that allows me to achieve that, so I've introduced
`StackContainerParent` interface.
## Visual documentation
https://github.com/user-attachments/assets/39069381-4a99-445d-98be-9c2fa7a2c608
## Checklist
* [x] Included code example that can be used to test this change.
* [x] Updated / created local changelog entries in relevant test files.
* [x] For visual changes, included screenshots / GIFs / recordings
documenting the change.
* [x] For API changes, updated relevant public types.
* [x] Ensured that CI passes1 parent 3d45292 commit 0893e0d
16 files changed
Lines changed: 342 additions & 109 deletions
File tree
- FabricExample/android/app
- android
- src/main/java/com/swmansion/rnscreens
- ext
- gamma/stack
- host
- screen
- apps/src/tests
- single-feature-tests/stack-v5
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
220 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
224 | | - | |
| 225 | + | |
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
Lines changed: 13 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | | - | |
| 61 | + | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
63 | 64 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
Lines changed: 73 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
51 | 67 | | |
52 | 68 | | |
53 | 69 | | |
| |||
89 | 105 | | |
90 | 106 | | |
91 | 107 | | |
92 | | - | |
| 108 | + | |
93 | 109 | | |
94 | 110 | | |
95 | 111 | | |
96 | 112 | | |
97 | 113 | | |
98 | | - | |
99 | | - | |
| 114 | + | |
| 115 | + | |
100 | 116 | | |
101 | 117 | | |
102 | 118 | | |
103 | 119 | | |
104 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
105 | 141 | | |
106 | 142 | | |
107 | 143 | | |
| |||
121 | 157 | | |
122 | 158 | | |
123 | 159 | | |
| 160 | + | |
124 | 161 | | |
125 | | - | |
| 162 | + | |
126 | 163 | | |
127 | 164 | | |
128 | 165 | | |
| |||
133 | 170 | | |
134 | 171 | | |
135 | 172 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | 173 | | |
145 | 174 | | |
146 | | - | |
147 | | - | |
148 | 175 | | |
149 | 176 | | |
150 | 177 | | |
151 | | - | |
152 | 178 | | |
153 | 179 | | |
154 | 180 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
167 | 187 | | |
168 | 188 | | |
169 | 189 | | |
| |||
180 | 200 | | |
181 | 201 | | |
182 | 202 | | |
183 | | - | |
| 203 | + | |
| 204 | + | |
184 | 205 | | |
185 | 206 | | |
186 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
187 | 224 | | |
188 | 225 | | |
189 | 226 | | |
| |||
200 | 237 | | |
201 | 238 | | |
202 | 239 | | |
203 | | - | |
204 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
205 | 248 | | |
206 | 249 | | |
207 | 250 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
Lines changed: 13 additions & 2 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 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
115 | 126 | | |
116 | 127 | | |
117 | 128 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
0 commit comments