Commit 0683933
authored
refactor(tabs): split native nav state into state and update request (#3950)
## Description
> [!NOTE]
> This PR stacks on top of #3949 — please review/land that one first.
The base branch here is `@kkafar/rename-is-native-action`, not `main`.
The native tabs JS-driven nav state update path was using a single type
— `RNSTabsNavigationState` on iOS and `TabsNavState` on Android — to
represent two distinct concepts:
1. **Authoritative state** held by the native container:
`(selectedScreenKey, provenance)`.
2. **A JS request to change that state** delivered via the
`navStateRequest` prop: `(selectedScreenKey, baseProvenance)`.
This conflation was tolerable while we only had one origin
(`ProgrammaticJs` / `PROGRAMMATIC_JS`), but with the new public
`actionOrigin` enum and the need to support more origins in the future
(notably native-programmatic), the request needs to carry its own origin
alongside its base provenance. The state type is the wrong place for
that field — it describes a result, not a request.
This PR introduces a sibling `…UpdateRequest` type on both platforms and
threads it through the JS-driven update path. The architectural
consequence is that the native container becomes **origin-agnostic** on
its success path: instead of hardcoding `actionOrigin = ProgrammaticJs`
when the update succeeds, it forwards whatever the incoming request
carried. The view manager / component view (which knows the origin is
`ProgrammaticJs` for prop-driven updates) is now the place that decides.
The runtime value of `actionOrigin` on the public event is unchanged
today — JS-driven updates still surface `'programmatic-js'`. This is
purely an internal architectural shift.
## Changes
### iOS
- New `RNSTabsNavigationStateUpdateRequest` type in
`RNSTabsNavigationState.h/.mm` with `selectedScreenKey`,
`baseProvenance`, `actionOrigin`. Mirrors `RNSTabsNavigationState`'s
utility surface (designated init, `cloneRequest`, static factory).
- `RNSTabsHostComponentView`:
- `navStateRequest` property retyped to
`RNSTabsNavigationStateUpdateRequest *`.
- `updateProps:oldProps:` constructs the request directly from C++ props
with `actionOrigin = RNSTabsActionOriginProgrammaticJs` and forwards a
`cloneRequest` to the controller.
- The `rejectedStateUpdateTo:` delegate impl reads
`request.selectedScreenKey` / `request.baseProvenance` for the rejection
event payload.
- `RNSTabBarController`:
- `setPendingNavigationStateUpdate:` retyped to take the request.
- Ivar renamed `_pendingOperation` → `_pendingStateUpdate` and retyped.
- Success-path `RNSTabsNavigationStateUpdateContext` now uses
`_pendingStateUpdate.actionOrigin` instead of hardcoded
`ProgrammaticJs`.
- `isNavigationStateUpdateStale:` retyped; reads `.baseProvenance`.
- Delegate `rejectedStateUpdateTo:` parameter retyped to the request.
- `OnTabSelectionRejectedPayload.rejectedNavState` (in
`RNSTabsHostEventEmitter.h`) renamed/retyped to `rejectedRequest:
RNSTabsNavigationStateUpdateRequest *`. The JSI emit reads
`selectedScreenKey` / `baseProvenance` from the request.
### Android
- New `TabsNavStateUpdateRequest` data class in `TabsNavState.kt` with
`selectedScreenKey`, `baseProvenance`, `actionOrigin`.
- `TabsHostViewManager.setNavStateRequest` constructs the request with
`actionOrigin = TabsActionOrigin.PROGRAMMATIC_JS` baked in (instead of
just a `TabsNavState`).
- `TabsHost.jsNavStateRequest` retyped to `TabsNavStateUpdateRequest?`.
`updateJSNavStateRequest` retyped.
- `TabSelectOp` retyped to wrap a `TabsNavStateUpdateRequest` (field
`navState` → `request`).
- `TabsContainer`:
- `onMenuItemSelected` no longer hardcodes `PROGRAMMATIC_JS` in the
external-context branch — it reads `(pendingOperation as
TabSelectOp).request.actionOrigin`. The `isInExternalOperationContext`
flag stays (it still suppresses the prevent-native-selection check and
the `lastUINavState` capture).
- `isNavStateStale` retyped; reads `request.baseProvenance`.
- All `performOperation` reads updated to `tabSelectOp.request.…`.
- `TabsContainerDelegate.onNavStateUpdateRejected` parameter
`rejectedNavState: TabsNavState` retyped to `rejectedRequest:
TabsNavStateUpdateRequest`. `TabsHostEventEmitter` and
`TabsHostTabSelectionRejectedEvent` follow.
- Bundles a `TabsNavState.selectedKey` → `selectedScreenKey` rename for
cross-platform consistency with the JS contract and the new request
type. JS-facing `WritableMap` keys (`selectedScreenKey`,
`rejectedScreenKey`) were already named correctly — only the
Kotlin-internal field name moves.
No JS, codegen-spec, or conversion-helper changes — public contract
untouched.
## Test plan
No new automated tests; this is an internal architectural refactor with
no behavioral change on the user/JS-driven paths. Manual verification
via `FabricExample`:
### iOS
- Tab bar tap → `actionOrigin === 'user'` (unchanged path).
- JS-driven `navStateRequest` update → `actionOrigin ===
'programmatic-js'` (now sourced from the request, not hardcoded in the
controller).
- iPad horizontal size-class transition forcing UIKit reshuffle →
`actionOrigin === 'implicit'` (unchanged path).
- Stale JS update (`rejectStaleNavStateUpdates: true`, mid-flight tap) →
`onTabSelectionRejected` fires with `rejectedScreenKey` and
`rejectedProvenance` matching the request's `selectedScreenKey` and
`baseProvenance`.
### Android
- Tab bar tap → `actionOrigin === 'user'` (unchanged path).
- JS-driven `navStateRequest` update → `actionOrigin ===
'programmatic-js'` (now sourced from the request, not hardcoded in the
container).
- Stale JS update (`rejectStaleNavStateUpdates: true`, mid-flight tap) →
`onTabSelectionRejected` fires with `rejectedScreenKey` and
`rejectedProvenance` matching the request's `selectedScreenKey` and
`baseProvenance`.
Reproduction lives in the `FabricExample` Tabs test screens; log
`e.nativeEvent.actionOrigin` from `onTabSelected` and
`e.nativeEvent.rejectedScreenKey` / `rejectedProvenance` from
`onTabSelectionRejected`.
## Checklist
- [ ] Included code example that can be used to test this change.
- [ ] For visual changes, included screenshots / GIFs / recordings
documenting the change.
- [ ] For API changes, updated relevant public types.
- [ ] Ensured that CI passes1 parent 6f65cc3 commit 0683933
18 files changed
Lines changed: 217 additions & 118 deletions
File tree
- android/src/main/java/com/swmansion/rnscreens/gamma/tabs
- container
- host
- event
- ios
- tabs/host
Lines changed: 21 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
263 | | - | |
| 262 | + | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | | - | |
347 | | - | |
| 346 | + | |
| 347 | + | |
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
380 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
381 | 389 | | |
382 | 390 | | |
383 | 391 | | |
| |||
413 | 421 | | |
414 | 422 | | |
415 | 423 | | |
416 | | - | |
| 424 | + | |
417 | 425 | | |
418 | 426 | | |
419 | 427 | | |
| |||
544 | 552 | | |
545 | 553 | | |
546 | 554 | | |
547 | | - | |
| 555 | + | |
548 | 556 | | |
549 | | - | |
| 557 | + | |
550 | 558 | | |
551 | 559 | | |
552 | 560 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
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: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
27 | 44 | | |
28 | 45 | | |
29 | 46 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
| 114 | + | |
114 | 115 | | |
115 | | - | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
176 | | - | |
| 177 | + | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
181 | | - | |
| 182 | + | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
35 | 36 | | |
36 | | - | |
37 | | - | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| |||
847 | 848 | | |
848 | 849 | | |
849 | 850 | | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
856 | 858 | | |
857 | 859 | | |
858 | 860 | | |
| |||
1129 | 1131 | | |
1130 | 1132 | | |
1131 | 1133 | | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
1148 | 1152 | | |
1149 | 1153 | | |
0 commit comments