react-native-screen-transitions 4.0.0-alpha.3 → 4.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/commonjs/components/boundary/hooks/lifecycles/use-initial-destination-measurement.js +14 -10
  2. package/lib/commonjs/components/boundary/hooks/lifecycles/use-initial-destination-measurement.js.map +1 -1
  3. package/lib/commonjs/components/boundary/hooks/lifecycles/use-initial-source-measurement.js +3 -1
  4. package/lib/commonjs/components/boundary/hooks/lifecycles/use-initial-source-measurement.js.map +1 -1
  5. package/lib/commonjs/components/boundary/hooks/lifecycles/use-refresh-boundary.js +3 -5
  6. package/lib/commonjs/components/boundary/hooks/lifecycles/use-refresh-boundary.js.map +1 -1
  7. package/lib/commonjs/components/boundary/hooks/use-boundary-measurement.js +5 -4
  8. package/lib/commonjs/components/boundary/hooks/use-boundary-measurement.js.map +1 -1
  9. package/lib/commonjs/components/boundary/utils/destination-signals.js +1 -3
  10. package/lib/commonjs/components/boundary/utils/destination-signals.js.map +1 -1
  11. package/lib/commonjs/components/boundary/utils/refresh-signals.js +2 -4
  12. package/lib/commonjs/components/boundary/utils/refresh-signals.js.map +1 -1
  13. package/lib/commonjs/providers/screen/descriptors/descriptors.provider.js +3 -7
  14. package/lib/commonjs/providers/screen/descriptors/descriptors.provider.js.map +1 -1
  15. package/lib/commonjs/providers/screen/descriptors/helpers/derive-descriptor-derivations.js +1 -3
  16. package/lib/commonjs/providers/screen/descriptors/helpers/derive-descriptor-derivations.js.map +1 -1
  17. package/lib/commonjs/providers/screen/descriptors/helpers/get-ancestor-keys.js +3 -20
  18. package/lib/commonjs/providers/screen/descriptors/helpers/get-ancestor-keys.js.map +1 -1
  19. package/lib/commonjs/stores/bounds/internals/entries.js +17 -0
  20. package/lib/commonjs/stores/bounds/internals/entries.js.map +1 -1
  21. package/lib/commonjs/stores/bounds/internals/links.js +25 -0
  22. package/lib/commonjs/stores/bounds/internals/links.js.map +1 -1
  23. package/lib/commonjs/stores/bounds/internals/resolver.js +2 -12
  24. package/lib/commonjs/stores/bounds/internals/resolver.js.map +1 -1
  25. package/lib/commonjs/utils/bounds/helpers/create-link-accessor.js +2 -2
  26. package/lib/commonjs/utils/bounds/helpers/create-link-accessor.js.map +1 -1
  27. package/lib/module/components/boundary/hooks/lifecycles/use-initial-destination-measurement.js +16 -12
  28. package/lib/module/components/boundary/hooks/lifecycles/use-initial-destination-measurement.js.map +1 -1
  29. package/lib/module/components/boundary/hooks/lifecycles/use-initial-source-measurement.js +3 -1
  30. package/lib/module/components/boundary/hooks/lifecycles/use-initial-source-measurement.js.map +1 -1
  31. package/lib/module/components/boundary/hooks/lifecycles/use-refresh-boundary.js +3 -5
  32. package/lib/module/components/boundary/hooks/lifecycles/use-refresh-boundary.js.map +1 -1
  33. package/lib/module/components/boundary/hooks/use-boundary-measurement.js +5 -4
  34. package/lib/module/components/boundary/hooks/use-boundary-measurement.js.map +1 -1
  35. package/lib/module/components/boundary/utils/destination-signals.js +1 -3
  36. package/lib/module/components/boundary/utils/destination-signals.js.map +1 -1
  37. package/lib/module/components/boundary/utils/refresh-signals.js +2 -4
  38. package/lib/module/components/boundary/utils/refresh-signals.js.map +1 -1
  39. package/lib/module/providers/screen/descriptors/descriptors.provider.js +4 -8
  40. package/lib/module/providers/screen/descriptors/descriptors.provider.js.map +1 -1
  41. package/lib/module/providers/screen/descriptors/helpers/derive-descriptor-derivations.js +1 -3
  42. package/lib/module/providers/screen/descriptors/helpers/derive-descriptor-derivations.js.map +1 -1
  43. package/lib/module/providers/screen/descriptors/helpers/get-ancestor-keys.js +3 -19
  44. package/lib/module/providers/screen/descriptors/helpers/get-ancestor-keys.js.map +1 -1
  45. package/lib/module/stores/bounds/internals/entries.js +17 -1
  46. package/lib/module/stores/bounds/internals/entries.js.map +1 -1
  47. package/lib/module/stores/bounds/internals/links.js +25 -2
  48. package/lib/module/stores/bounds/internals/links.js.map +1 -1
  49. package/lib/module/stores/bounds/internals/resolver.js +3 -13
  50. package/lib/module/stores/bounds/internals/resolver.js.map +1 -1
  51. package/lib/module/utils/bounds/helpers/create-link-accessor.js +3 -3
  52. package/lib/module/utils/bounds/helpers/create-link-accessor.js.map +1 -1
  53. package/lib/typescript/components/boundary/hooks/lifecycles/use-initial-destination-measurement.d.ts.map +1 -1
  54. package/lib/typescript/components/boundary/hooks/lifecycles/use-initial-source-measurement.d.ts.map +1 -1
  55. package/lib/typescript/components/boundary/hooks/lifecycles/use-refresh-boundary.d.ts.map +1 -1
  56. package/lib/typescript/components/boundary/hooks/use-boundary-measurement.d.ts.map +1 -1
  57. package/lib/typescript/components/boundary/utils/destination-signals.d.ts +1 -2
  58. package/lib/typescript/components/boundary/utils/destination-signals.d.ts.map +1 -1
  59. package/lib/typescript/components/boundary/utils/refresh-signals.d.ts +0 -2
  60. package/lib/typescript/components/boundary/utils/refresh-signals.d.ts.map +1 -1
  61. package/lib/typescript/providers/screen/descriptors/descriptors.provider.d.ts.map +1 -1
  62. package/lib/typescript/providers/screen/descriptors/helpers/derive-descriptor-derivations.d.ts +1 -3
  63. package/lib/typescript/providers/screen/descriptors/helpers/derive-descriptor-derivations.d.ts.map +1 -1
  64. package/lib/typescript/providers/screen/descriptors/helpers/get-ancestor-keys.d.ts +0 -8
  65. package/lib/typescript/providers/screen/descriptors/helpers/get-ancestor-keys.d.ts.map +1 -1
  66. package/lib/typescript/stores/bounds/internals/entries.d.ts +2 -1
  67. package/lib/typescript/stores/bounds/internals/entries.d.ts.map +1 -1
  68. package/lib/typescript/stores/bounds/internals/links.d.ts +3 -1
  69. package/lib/typescript/stores/bounds/internals/links.d.ts.map +1 -1
  70. package/lib/typescript/stores/bounds/internals/resolver.d.ts.map +1 -1
  71. package/lib/typescript/utils/bounds/helpers/create-link-accessor.d.ts.map +1 -1
  72. package/package.json +1 -1
  73. package/src/components/boundary/hooks/lifecycles/use-initial-destination-measurement.ts +43 -21
  74. package/src/components/boundary/hooks/lifecycles/use-initial-source-measurement.ts +6 -1
  75. package/src/components/boundary/hooks/lifecycles/use-refresh-boundary.ts +8 -9
  76. package/src/components/boundary/hooks/use-boundary-measurement.ts +5 -4
  77. package/src/components/boundary/utils/destination-signals.ts +2 -6
  78. package/src/components/boundary/utils/refresh-signals.ts +2 -10
  79. package/src/providers/screen/descriptors/descriptors.provider.tsx +4 -11
  80. package/src/providers/screen/descriptors/helpers/derive-descriptor-derivations.ts +0 -4
  81. package/src/providers/screen/descriptors/helpers/get-ancestor-keys.ts +3 -30
  82. package/src/stores/bounds/internals/entries.ts +27 -1
  83. package/src/stores/bounds/internals/links.ts +36 -0
  84. package/src/stores/bounds/internals/resolver.ts +7 -21
  85. package/src/utils/bounds/helpers/create-link-accessor.ts +9 -3
@@ -8,7 +8,6 @@ export interface DescriptorDerivations {
8
8
  nextScreenKey?: string;
9
9
  sourcePairKey?: ScreenPairKey;
10
10
  destinationPairKey?: ScreenPairKey;
11
- ancestorDestinationPairKey?: ScreenPairKey;
12
11
  parentScreenKey?: string;
13
12
  isFirstKey: boolean;
14
13
  isTopMostScreen: boolean;
@@ -21,7 +20,6 @@ interface Params {
21
20
  current: BaseStackDescriptor;
22
21
  next?: BaseStackDescriptor;
23
22
  ancestorKeys: string[];
24
- ancestorDestinationPairKey?: ScreenPairKey;
25
23
  }
26
24
 
27
25
  export function deriveDescriptorDerivations({
@@ -29,7 +27,6 @@ export function deriveDescriptorDerivations({
29
27
  current,
30
28
  next,
31
29
  ancestorKeys,
32
- ancestorDestinationPairKey,
33
30
  }: Params): DescriptorDerivations {
34
31
  const previousScreenKey = previous?.route.key;
35
32
  const currentScreenKey = current.route.key;
@@ -56,7 +53,6 @@ export function deriveDescriptorDerivations({
56
53
  nextScreenKey,
57
54
  sourcePairKey,
58
55
  destinationPairKey,
59
- ancestorDestinationPairKey,
60
56
  parentScreenKey: ancestorKeys[0],
61
57
  isFirstKey,
62
58
  isTopMostScreen,
@@ -1,26 +1,14 @@
1
- import { createScreenPairKey } from "../../../../stores/bounds/helpers/link-pairs.helpers";
2
- import type { ScreenPairKey } from "../../../../stores/bounds/types";
3
1
  import type { BaseStackDescriptor } from "../../../../types/stack.types";
4
2
 
5
- export interface AncestorKeyState {
6
- ancestorKeys: string[];
7
- ancestorDestinationPairKey?: ScreenPairKey;
8
- }
9
-
10
3
  /**
11
4
  * Builds nested navigator ancestor keys from immediate parent to root.
12
- * The nearest ancestor destination pair lets child routes attach measurements
13
- * to the transition owned by the parent stack.
14
5
  */
15
- export function getAncestorKeyState(
16
- current: BaseStackDescriptor,
17
- ): AncestorKeyState {
6
+ export function getAncestorKeys(current: BaseStackDescriptor): string[] {
18
7
  const ancestors: string[] = [];
19
- let ancestorDestinationPairKey: ScreenPairKey | undefined;
20
8
  const nav = current.navigation as any;
21
9
 
22
10
  if (typeof nav?.getParent !== "function") {
23
- return { ancestorKeys: ancestors };
11
+ return ancestors;
24
12
  }
25
13
 
26
14
  let parent = nav.getParent();
@@ -31,25 +19,10 @@ export function getAncestorKeyState(
31
19
  const focusedRoute = state.routes[state.index];
32
20
  if (focusedRoute?.key) {
33
21
  ancestors.push(focusedRoute.key);
34
-
35
- const previousRoute = state.routes[state.index - 1];
36
- if (!ancestorDestinationPairKey && previousRoute?.key) {
37
- ancestorDestinationPairKey = createScreenPairKey(
38
- previousRoute.key,
39
- focusedRoute.key,
40
- );
41
- }
42
22
  }
43
23
  }
44
24
  parent = parent.getParent();
45
25
  }
46
26
 
47
- return {
48
- ancestorKeys: ancestors,
49
- ancestorDestinationPairKey,
50
- };
51
- }
52
-
53
- export function getAncestorKeys(current: BaseStackDescriptor): string[] {
54
- return getAncestorKeyState(current).ancestorKeys;
27
+ return ancestors;
55
28
  }
@@ -62,6 +62,32 @@ function getEntry(tag: TagID, key: ScreenKey): Entry | null {
62
62
  return boundaryRegistry.get()[tag]?.screens[key] ?? null;
63
63
  }
64
64
 
65
+ function getMatchingSourceScreenKey(
66
+ tag: TagID,
67
+ destinationScreenKey: ScreenKey,
68
+ preferredScreenKey?: ScreenKey,
69
+ ): ScreenKey | null {
70
+ "worklet";
71
+ const screens = boundaryRegistry.get()[tag]?.screens;
72
+ if (!screens) return null;
73
+ if (
74
+ preferredScreenKey &&
75
+ preferredScreenKey !== destinationScreenKey &&
76
+ screens[preferredScreenKey]
77
+ ) {
78
+ return preferredScreenKey;
79
+ }
80
+
81
+ let latestScreenKey: ScreenKey | null = null;
82
+ for (const screenKey in screens) {
83
+ if (screenKey !== destinationScreenKey) {
84
+ latestScreenKey = screenKey;
85
+ }
86
+ }
87
+
88
+ return latestScreenKey;
89
+ }
90
+
65
91
  function setEntry(tag: TagID, screenKey: ScreenKey, patch: EntryPatch) {
66
92
  "worklet";
67
93
  boundaryRegistry.modify(<T extends BoundaryEntriesState>(state: T): T => {
@@ -90,4 +116,4 @@ function removeEntry(tag: TagID, screenKey: ScreenKey) {
90
116
  });
91
117
  }
92
118
 
93
- export { getEntry, removeEntry, setEntry };
119
+ export { getEntry, getMatchingSourceScreenKey, removeEntry, setEntry };
@@ -4,12 +4,14 @@ import {
4
4
  ensurePairGroups,
5
5
  ensurePairLinks,
6
6
  ensurePairSourceRequests,
7
+ getDestinationScreenKeyFromPairKey,
7
8
  getGroupKeyFromTag,
8
9
  getLinkKeyFromTag,
9
10
  getActiveGroupId as getPairActiveGroupId,
10
11
  getDestination as getPairDestination,
11
12
  getLink as getPairLink,
12
13
  getSource as getPairSource,
14
+ getSourceScreenKeyFromPairKey,
13
15
  } from "../helpers/link-pairs.helpers";
14
16
  import type {
15
17
  BoundaryRuntimeFlags,
@@ -402,6 +404,38 @@ function getResolvedLink(
402
404
  };
403
405
  }
404
406
 
407
+ function getPairKeyForSource(
408
+ tag: TagID,
409
+ screenKey: ScreenKey,
410
+ ): ScreenPairKey | null {
411
+ "worklet";
412
+ const state = pairs.get();
413
+ const linkKey = getLinkKeyFromTag(tag);
414
+ for (const pairKey in state) {
415
+ if (getSourceScreenKeyFromPairKey(pairKey) !== screenKey) continue;
416
+ if (
417
+ getResolvedLink(pairKey, tag).link?.destination ||
418
+ state[pairKey]?.sourceRequests?.[linkKey]
419
+ ) {
420
+ return pairKey;
421
+ }
422
+ }
423
+ return null;
424
+ }
425
+
426
+ function getPairKeyForDestination(
427
+ tag: TagID,
428
+ screenKey: ScreenKey,
429
+ ): ScreenPairKey | null {
430
+ "worklet";
431
+ const state = pairs.get();
432
+ for (const pairKey in state) {
433
+ if (getDestinationScreenKeyFromPairKey(pairKey) !== screenKey) continue;
434
+ if (getResolvedLink(pairKey, tag).link) return pairKey;
435
+ }
436
+ return null;
437
+ }
438
+
405
439
  function getSource(
406
440
  pairKey: ScreenPairKey,
407
441
  tag: TagID,
@@ -422,6 +456,8 @@ export {
422
456
  getActiveGroupId,
423
457
  getDestination,
424
458
  getLink,
459
+ getPairKeyForDestination,
460
+ getPairKeyForSource,
425
461
  getResolvedLink,
426
462
  getSource,
427
463
  requestSourceMeasure,
@@ -1,35 +1,21 @@
1
- import { createScreenPairKey } from "../helpers/link-pairs.helpers";
2
1
  import type {
3
2
  ResolvedTransitionPair,
4
3
  ResolveTransitionContext,
5
- ScreenPairKey,
6
4
  TagID,
7
5
  } from "../types";
8
- import { getResolvedLink } from "./links";
9
-
10
- function resolvePairKey(
11
- context: ResolveTransitionContext,
12
- ): ScreenPairKey | null {
13
- "worklet";
14
-
15
- if (context.entering) {
16
- if (!context.previousScreenKey || !context.currentScreenKey) return null;
17
- return createScreenPairKey(
18
- context.previousScreenKey,
19
- context.currentScreenKey,
20
- );
21
- }
22
-
23
- if (!context.currentScreenKey || !context.nextScreenKey) return null;
24
- return createScreenPairKey(context.currentScreenKey, context.nextScreenKey);
25
- }
6
+ import { getPairKeyForDestination, getResolvedLink } from "./links";
26
7
 
27
8
  function resolveTransitionPair(
28
9
  tag: TagID,
29
10
  context: ResolveTransitionContext,
30
11
  ): ResolvedTransitionPair {
31
12
  "worklet";
32
- const pairKey = resolvePairKey(context);
13
+ const destinationScreenKey = context.entering
14
+ ? context.currentScreenKey
15
+ : context.nextScreenKey;
16
+ const pairKey = destinationScreenKey
17
+ ? getPairKeyForDestination(tag, destinationScreenKey)
18
+ : null;
33
19
  const matchedLink = pairKey ? getResolvedLink(pairKey, tag).link : null;
34
20
 
35
21
  return {
@@ -1,10 +1,12 @@
1
- import { getResolvedLink } from "../../../stores/bounds/internals/links";
1
+ import {
2
+ getPairKeyForDestination,
3
+ getResolvedLink,
4
+ } from "../../../stores/bounds/internals/links";
2
5
  import type {
3
6
  BoundsInterpolationProps,
4
7
  BoundsLink,
5
8
  } from "../../../types/bounds.types";
6
9
  import type { BoundId } from "../types/options";
7
- import { resolveBoundsPairKey } from "./resolve-bounds-pair-key";
8
10
 
9
11
  type GetProps = () => BoundsInterpolationProps;
10
12
 
@@ -19,7 +21,11 @@ export const createLinkAccessor = (getProps: GetProps): LinkAccessor => {
19
21
  "worklet";
20
22
  const props = getProps();
21
23
  const stringTag = String(tag);
22
- const pairKey = resolveBoundsPairKey(props);
24
+ const destinationScreenKey =
25
+ props.next?.route.key ?? props.current?.route.key;
26
+ const pairKey = destinationScreenKey
27
+ ? getPairKeyForDestination(stringTag, destinationScreenKey)
28
+ : null;
23
29
  if (!pairKey) return null;
24
30
 
25
31
  const resolved = getResolvedLink(pairKey, stringTag);