react-native-screen-transitions 2.1.0 → 2.2.1

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 (78) hide show
  1. package/lib/commonjs/components/bound-capture.js +7 -2
  2. package/lib/commonjs/components/bound-capture.js.map +1 -1
  3. package/lib/commonjs/components/controllers/screen-lifecycle.js +3 -9
  4. package/lib/commonjs/components/controllers/screen-lifecycle.js.map +1 -1
  5. package/lib/commonjs/components/create-transition-aware-component.js +12 -2
  6. package/lib/commonjs/components/create-transition-aware-component.js.map +1 -1
  7. package/lib/commonjs/components/root-transition-aware.js +3 -1
  8. package/lib/commonjs/components/root-transition-aware.js.map +1 -1
  9. package/lib/commonjs/hooks/animation/use-associated-style.js +41 -6
  10. package/lib/commonjs/hooks/animation/use-associated-style.js.map +1 -1
  11. package/lib/commonjs/hooks/bounds/use-bound-registry.js +9 -16
  12. package/lib/commonjs/hooks/bounds/use-bound-registry.js.map +1 -1
  13. package/lib/commonjs/providers/transition-styles.js +5 -1
  14. package/lib/commonjs/providers/transition-styles.js.map +1 -1
  15. package/lib/commonjs/stores/bounds/_utils.js +118 -0
  16. package/lib/commonjs/stores/bounds/_utils.js.map +1 -0
  17. package/lib/commonjs/stores/bounds/index.js +116 -0
  18. package/lib/commonjs/stores/bounds/index.js.map +1 -0
  19. package/lib/commonjs/stores/utils/reset-stores-for-screen.js +1 -4
  20. package/lib/commonjs/stores/utils/reset-stores-for-screen.js.map +1 -1
  21. package/lib/module/components/bound-capture.js +7 -2
  22. package/lib/module/components/bound-capture.js.map +1 -1
  23. package/lib/module/components/controllers/screen-lifecycle.js +3 -9
  24. package/lib/module/components/controllers/screen-lifecycle.js.map +1 -1
  25. package/lib/module/components/create-transition-aware-component.js +12 -2
  26. package/lib/module/components/create-transition-aware-component.js.map +1 -1
  27. package/lib/module/components/root-transition-aware.js +3 -1
  28. package/lib/module/components/root-transition-aware.js.map +1 -1
  29. package/lib/module/hooks/animation/use-associated-style.js +42 -7
  30. package/lib/module/hooks/animation/use-associated-style.js.map +1 -1
  31. package/lib/module/hooks/bounds/use-bound-registry.js +9 -16
  32. package/lib/module/hooks/bounds/use-bound-registry.js.map +1 -1
  33. package/lib/module/providers/transition-styles.js +5 -1
  34. package/lib/module/providers/transition-styles.js.map +1 -1
  35. package/lib/module/stores/bounds/_utils.js +113 -0
  36. package/lib/module/stores/bounds/_utils.js.map +1 -0
  37. package/lib/module/stores/bounds/index.js +112 -0
  38. package/lib/module/stores/bounds/index.js.map +1 -0
  39. package/lib/module/stores/utils/reset-stores-for-screen.js +1 -4
  40. package/lib/module/stores/utils/reset-stores-for-screen.js.map +1 -1
  41. package/lib/typescript/components/bound-capture.d.ts.map +1 -1
  42. package/lib/typescript/components/create-transition-aware-component.d.ts.map +1 -1
  43. package/lib/typescript/hooks/animation/use-associated-style.d.ts +4 -4
  44. package/lib/typescript/hooks/animation/use-associated-style.d.ts.map +1 -1
  45. package/lib/typescript/hooks/bounds/use-bound-registry.d.ts +0 -1
  46. package/lib/typescript/hooks/bounds/use-bound-registry.d.ts.map +1 -1
  47. package/lib/typescript/index.d.ts +4 -0
  48. package/lib/typescript/index.d.ts.map +1 -1
  49. package/lib/typescript/providers/transition-styles.d.ts +4 -1
  50. package/lib/typescript/providers/transition-styles.d.ts.map +1 -1
  51. package/lib/typescript/stores/bounds/_utils.d.ts +24 -0
  52. package/lib/typescript/stores/bounds/_utils.d.ts.map +1 -0
  53. package/lib/typescript/stores/{bounds.d.ts → bounds/index.d.ts} +3 -13
  54. package/lib/typescript/stores/bounds/index.d.ts.map +1 -0
  55. package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts +1 -3
  56. package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts.map +1 -1
  57. package/lib/typescript/types/core.d.ts +8 -0
  58. package/lib/typescript/types/core.d.ts.map +1 -1
  59. package/package.json +3 -3
  60. package/src/__tests__/bounds.store.test.ts +185 -0
  61. package/src/components/bound-capture.tsx +5 -2
  62. package/src/components/controllers/screen-lifecycle.tsx +3 -3
  63. package/src/components/create-transition-aware-component.tsx +19 -3
  64. package/src/components/root-transition-aware.tsx +1 -1
  65. package/src/hooks/animation/use-associated-style.tsx +42 -7
  66. package/src/hooks/bounds/use-bound-registry.tsx +10 -21
  67. package/src/providers/transition-styles.tsx +8 -2
  68. package/src/stores/bounds/_utils.ts +161 -0
  69. package/src/stores/bounds/index.ts +125 -0
  70. package/src/stores/utils/reset-stores-for-screen.ts +1 -7
  71. package/src/types/core.ts +9 -0
  72. package/LICENSE +0 -21
  73. package/lib/commonjs/stores/bounds.js +0 -205
  74. package/lib/commonjs/stores/bounds.js.map +0 -1
  75. package/lib/module/stores/bounds.js +0 -201
  76. package/lib/module/stores/bounds.js.map +0 -1
  77. package/lib/typescript/stores/bounds.d.ts.map +0 -1
  78. package/src/stores/bounds.ts +0 -227
@@ -10,7 +10,6 @@ import { useKeys } from "../../providers/keys";
10
10
  import { Bounds } from "../../stores/bounds";
11
11
  import { flattenStyle } from "../../utils/bounds/_utils/flatten-styles";
12
12
  import { isBoundsEqual } from "../../utils/bounds/_utils/is-bounds-equal";
13
- import { useScreenAnimation } from "../animation/use-screen-animation";
14
13
 
15
14
  interface BoundMeasurerHookProps {
16
15
  sharedBoundTag: string;
@@ -26,7 +25,7 @@ export const useBoundsRegistry = ({
26
25
  style,
27
26
  }: BoundMeasurerHookProps) => {
28
27
  const { previous } = useKeys();
29
- const interpolatorProps = useScreenAnimation();
28
+
30
29
  const isMeasured = useSharedValue(false);
31
30
 
32
31
  const measureBounds = useCallback(() => {
@@ -36,18 +35,23 @@ export const useBoundsRegistry = ({
36
35
  if (measured) {
37
36
  const key = current.route.key;
38
37
  if (isBoundsEqual({ measured, key, sharedBoundTag })) {
39
- Bounds.setRouteActive(key, sharedBoundTag);
38
+ if (Bounds.getRouteActive(key) === sharedBoundTag) {
39
+ Bounds.setRouteActive(key, sharedBoundTag);
40
+ }
40
41
  return;
41
42
  }
42
43
 
43
44
  Bounds.setBounds(key, sharedBoundTag, measured, flattenStyle(style));
44
- Bounds.setRouteActive(key, sharedBoundTag);
45
+ if (Bounds.getRouteActive(key) === sharedBoundTag) {
46
+ Bounds.setRouteActive(key, sharedBoundTag);
47
+ }
45
48
  }
46
49
  }, [sharedBoundTag, animatedRef, current.route.key, style]);
47
50
 
48
51
  const handleLayout = useCallback(() => {
49
52
  "worklet";
50
53
  const previousRouteKey = previous?.route.key;
54
+
51
55
  if (!sharedBoundTag || isMeasured.value || !previousRouteKey) {
52
56
  return;
53
57
  }
@@ -55,29 +59,14 @@ export const useBoundsRegistry = ({
55
59
  const previousBounds = Bounds.getBounds(previousRouteKey);
56
60
  const hasPreviousBoundForTag = previousBounds[sharedBoundTag];
57
61
 
58
- if (interpolatorProps.value.current.animating && hasPreviousBoundForTag) {
62
+ if (hasPreviousBoundForTag) {
59
63
  measureBounds();
60
64
  isMeasured.value = true;
61
65
  }
62
- }, [
63
- measureBounds,
64
- interpolatorProps,
65
- sharedBoundTag,
66
- previous?.route.key,
67
- isMeasured,
68
- ]);
69
-
70
- const measureOnTouchStart = useCallback(() => {
71
- "worklet";
72
- if (sharedBoundTag) {
73
- Bounds.setActiveBoundId(sharedBoundTag);
74
- measure(animatedRef);
75
- }
76
- }, [sharedBoundTag, animatedRef]);
66
+ }, [measureBounds, sharedBoundTag, previous?.route.key, isMeasured]);
77
67
 
78
68
  return {
79
69
  measureBounds,
80
70
  handleLayout,
81
- measureOnTouchStart,
82
71
  };
83
72
  };
@@ -10,7 +10,9 @@ type Props = {
10
10
  const EMPTY_MAP = Object.freeze({});
11
11
 
12
12
  const TransitionStylesContext = createContext<ReturnType<
13
- typeof useDerivedValue<TransitionInterpolatedStyle>
13
+ typeof useMemo<{
14
+ stylesMap: ReturnType<typeof useDerivedValue<TransitionInterpolatedStyle>>;
15
+ }>
14
16
  > | null>(null);
15
17
 
16
18
  export function TransitionStylesProvider({ children }: Props) {
@@ -32,7 +34,11 @@ export function TransitionStylesProvider({ children }: Props) {
32
34
  : EMPTY_MAP;
33
35
  });
34
36
 
35
- const value = useMemo(() => stylesMap, [stylesMap]);
37
+ const value = useMemo(() => {
38
+ return {
39
+ stylesMap,
40
+ };
41
+ }, [stylesMap]);
36
42
 
37
43
  return (
38
44
  <TransitionStylesContext.Provider value={value}>
@@ -0,0 +1,161 @@
1
+ import type { ScreenTransitionState } from "../../types/animation";
2
+
3
+ type GetCache = (fromKey: string, toKey: string) => string | null;
4
+ type SetCache = (fromKey: string, toKey: string, id: string) => void;
5
+ type GetRouteActive = (routeKey: string) => string | null;
6
+
7
+ interface ResolveActiveBoundParams {
8
+ current: ScreenTransitionState;
9
+ next?: ScreenTransitionState;
10
+ previous?: ScreenTransitionState;
11
+ getPairCache: GetCache;
12
+ setPairCache: SetCache;
13
+ getRouteActive: GetRouteActive;
14
+ }
15
+
16
+ export function pairKey(fromKey?: string, toKey?: string) {
17
+ "worklet";
18
+ return fromKey && toKey ? `${fromKey}|${toKey}` : "";
19
+ }
20
+
21
+ const hasBound = (s: ScreenTransitionState | undefined, id?: string | null) => {
22
+ "worklet";
23
+ return !!id && !!s && !!s.bounds && !!s.bounds[id];
24
+ };
25
+
26
+ const getRoutePair = (
27
+ current: ScreenTransitionState,
28
+ next: ScreenTransitionState | undefined,
29
+ previous: ScreenTransitionState | undefined,
30
+ ) => {
31
+ "worklet";
32
+ const isClosing = !!next;
33
+ const fromKey = isClosing ? current.route.key : previous?.route.key;
34
+ const toKey = isClosing ? next?.route.key : current.route.key;
35
+ const other = next ?? previous;
36
+ return { fromKey, toKey, other } as const;
37
+ };
38
+
39
+ const resolveFromPairCache = (
40
+ fromKey: string | undefined,
41
+ toKey: string | undefined,
42
+ other: ScreenTransitionState | undefined,
43
+ getPairCache: GetCache,
44
+ ) => {
45
+ "worklet";
46
+ if (fromKey && toKey) {
47
+ const cached = getPairCache(fromKey, toKey);
48
+ if (hasBound(other, cached)) return cached as string;
49
+ }
50
+ return "";
51
+ };
52
+
53
+ const resolveFromRequested = (
54
+ reqId: string | null,
55
+ current: ScreenTransitionState,
56
+ other: ScreenTransitionState | undefined,
57
+ ) => {
58
+ "worklet";
59
+ if (hasBound(other, reqId)) return reqId as string;
60
+ if (hasBound(current, reqId)) return reqId as string;
61
+ return "";
62
+ };
63
+
64
+ const resolveFromInteresection = (
65
+ current: ScreenTransitionState,
66
+ other: ScreenTransitionState | undefined,
67
+ fromKey: string | undefined,
68
+ getRouteActive: GetRouteActive,
69
+ ) => {
70
+ "worklet";
71
+ if (!other) return "";
72
+ const a = Object.keys(current.bounds);
73
+ const b = Object.keys(other.bounds);
74
+ const inter = a.filter((k) => b.includes(k));
75
+ const otherHasAny = b.length > 0;
76
+ const routeActive = fromKey ? getRouteActive(fromKey) : null;
77
+
78
+ if (inter.length > 0) {
79
+ if (routeActive && inter.includes(routeActive)) return routeActive;
80
+ return inter[0];
81
+ }
82
+
83
+ if (routeActive && hasBound(other, routeActive)) return routeActive;
84
+ if (b.length === 1) return b[0];
85
+
86
+ if (!otherHasAny) {
87
+ if (routeActive && hasBound(current, routeActive)) return routeActive;
88
+ if (a.length === 1) return a[0];
89
+ }
90
+
91
+ return "";
92
+ };
93
+
94
+ /**
95
+ * Util function to get the active bound id for a given transition state.
96
+ *
97
+ * It will check by ( priority from highest to lowest ):
98
+ * 1. Requested id
99
+ * 2. Cache
100
+ * 3. Intersection
101
+ */
102
+ export function resolveActiveBound({
103
+ current,
104
+ next,
105
+ previous,
106
+ getPairCache,
107
+ setPairCache,
108
+ getRouteActive,
109
+ }: ResolveActiveBoundParams) {
110
+ "worklet";
111
+ const { fromKey, toKey, other } = getRoutePair(current, next, previous);
112
+
113
+ // Resolve requested from per-route most recently used (last active bound by route)
114
+ const requestedId = fromKey ? getRouteActive(fromKey) : null;
115
+ const byRequested = resolveFromRequested(requestedId, current, other);
116
+ if (byRequested) {
117
+ if (
118
+ fromKey &&
119
+ toKey &&
120
+ hasBound(current, byRequested) &&
121
+ hasBound(other, byRequested)
122
+ ) {
123
+ setPairCache(fromKey, toKey, byRequested);
124
+ }
125
+ return byRequested;
126
+ }
127
+
128
+ const byPairCache = resolveFromPairCache(fromKey, toKey, other, getPairCache);
129
+ if (byPairCache) {
130
+ if (
131
+ fromKey &&
132
+ toKey &&
133
+ hasBound(current, byPairCache) &&
134
+ hasBound(other, byPairCache)
135
+ ) {
136
+ setPairCache(fromKey, toKey, byPairCache);
137
+ }
138
+ return byPairCache;
139
+ }
140
+
141
+ const byIntersection = resolveFromInteresection(
142
+ current,
143
+ other,
144
+ fromKey,
145
+ getRouteActive,
146
+ );
147
+
148
+ if (byIntersection) {
149
+ if (
150
+ fromKey &&
151
+ toKey &&
152
+ hasBound(current, byIntersection) &&
153
+ hasBound(other, byIntersection)
154
+ ) {
155
+ setPairCache(fromKey, toKey, byIntersection);
156
+ }
157
+ return byIntersection;
158
+ }
159
+
160
+ return "";
161
+ }
@@ -0,0 +1,125 @@
1
+ import {
2
+ type MeasuredDimensions,
3
+ makeMutable,
4
+ type StyleProps,
5
+ } from "react-native-reanimated";
6
+ import type { ScreenTransitionState } from "../../types/animation";
7
+ import type { ScreenKey } from "../../types/navigator";
8
+ import type { Any } from "../../types/utils";
9
+ import { pairKey, resolveActiveBound } from "./_utils";
10
+
11
+ type BoundsDict = Record<
12
+ string,
13
+ Record<string, { bounds: MeasuredDimensions; styles: StyleProps }>
14
+ >;
15
+
16
+ const registry = makeMutable<BoundsDict>({});
17
+ const pairCache = makeMutable<Record<string, string>>({});
18
+ const lastActiveByRoute = makeMutable<Record<string, string>>({});
19
+
20
+ function setBounds(
21
+ screenId: string,
22
+ boundId: string,
23
+ bounds: MeasuredDimensions | null = null,
24
+ styles: StyleProps = {},
25
+ ) {
26
+ "worklet";
27
+ registry.modify((state: Any) => {
28
+ "worklet";
29
+ if (!state[screenId]) {
30
+ state[screenId] = {};
31
+ }
32
+ state[screenId][boundId] = { bounds, styles };
33
+
34
+ return state;
35
+ });
36
+ }
37
+
38
+ function getBounds(screenId: string) {
39
+ "worklet";
40
+ return registry.value[screenId] ?? {};
41
+ }
42
+
43
+ function setRouteActive(routeKey: string, boundId: string) {
44
+ "worklet";
45
+ lastActiveByRoute.modify((state: Any) => {
46
+ "worklet";
47
+ state[routeKey] = boundId;
48
+ return state;
49
+ });
50
+ }
51
+
52
+ function getRouteActive(routeKey: string) {
53
+ "worklet";
54
+ return lastActiveByRoute.value[routeKey] ?? null;
55
+ }
56
+
57
+ function setPairCache(fromKey: string, toKey: string, boundId: string) {
58
+ "worklet";
59
+ const key = pairKey(fromKey, toKey);
60
+ if (!key) return;
61
+ pairCache.modify((state: Any) => {
62
+ "worklet";
63
+ state[key] = boundId;
64
+ return state;
65
+ });
66
+ }
67
+
68
+ function getPairCache(fromKey: string, toKey: string) {
69
+ "worklet";
70
+ const key = pairKey(fromKey, toKey);
71
+ if (!key) return null;
72
+ return pairCache.value[key] ?? null;
73
+ }
74
+
75
+ function clear(routeKey: ScreenKey) {
76
+ "worklet";
77
+ registry.modify((state) => {
78
+ "worklet";
79
+ delete state[routeKey];
80
+ return state;
81
+ });
82
+ lastActiveByRoute.modify((state) => {
83
+ "worklet";
84
+ if (state[routeKey]) delete state[routeKey];
85
+ return state;
86
+ });
87
+
88
+ pairCache.modify((state) => {
89
+ "worklet";
90
+ const keys = Object.keys(state);
91
+ for (let i = 0; i < keys.length; i++) {
92
+ const k = keys[i];
93
+ const [from, to] = k.split("|");
94
+ if (from === routeKey || to === routeKey) {
95
+ delete state[k];
96
+ }
97
+ }
98
+ return state;
99
+ });
100
+ }
101
+
102
+ function getActiveBound(
103
+ current: ScreenTransitionState,
104
+ next: ScreenTransitionState | undefined,
105
+ previous: ScreenTransitionState | undefined,
106
+ ) {
107
+ "worklet";
108
+ return resolveActiveBound({
109
+ current,
110
+ next,
111
+ previous,
112
+ getPairCache,
113
+ setPairCache,
114
+ getRouteActive,
115
+ });
116
+ }
117
+
118
+ export const Bounds = {
119
+ setBounds,
120
+ getBounds,
121
+ setRouteActive,
122
+ getRouteActive,
123
+ clear,
124
+ getActiveBound,
125
+ };
@@ -6,14 +6,8 @@ import { Gestures } from "../gestures";
6
6
  /**
7
7
  * Reset all stores for a given screen
8
8
  */
9
- export const resetStoresForScreen = (
10
- current: NativeStackDescriptor,
11
- options: { clearActive?: boolean } = {},
12
- ) => {
9
+ export const resetStoresForScreen = (current: NativeStackDescriptor) => {
13
10
  Animations.clear(current.route.key);
14
11
  Gestures.clear(current.route.key);
15
12
  Bounds.clear(current.route.key);
16
- if (options.clearActive) {
17
- Bounds.clearActive();
18
- }
19
13
  };
package/src/types/core.ts CHANGED
@@ -42,6 +42,15 @@ export type TransitionAwareProps<T extends object> = AnimatedProps<T> & {
42
42
  * </Transition.View>
43
43
  */
44
44
  sharedBoundTag?: string;
45
+
46
+ /**
47
+ * Eagerly measure this component on layout and store the result in the
48
+ * Bounds registry. Useful for nested shared elements that may not receive
49
+ * the press event but still need up-to-date measurements at navigation time.
50
+ *
51
+ * Only has an effect when used together with `sharedBoundTag`.
52
+ */
53
+ measureOnLayout?: boolean;
45
54
  };
46
55
 
47
56
  export type TransitionConfig = {
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Ed
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,205 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Bounds = void 0;
7
- var _reactNativeReanimated = require("react-native-reanimated");
8
- const registry = (0, _reactNativeReanimated.makeMutable)({});
9
- const activeBoundId = (0, _reactNativeReanimated.makeMutable)(null);
10
- const lastActiveByRoute = (0, _reactNativeReanimated.makeMutable)({});
11
- const pairHints = (0, _reactNativeReanimated.makeMutable)({});
12
- function pairKey(fromKey, toKey) {
13
- "worklet";
14
-
15
- return fromKey && toKey ? `${fromKey}|${toKey}` : "";
16
- }
17
- function setBounds(screenId, boundId, bounds = null, styles = {}) {
18
- "worklet";
19
-
20
- registry.modify(state => {
21
- "worklet";
22
-
23
- if (!state[screenId]) {
24
- state[screenId] = {};
25
- }
26
- state[screenId][boundId] = {
27
- bounds,
28
- styles
29
- };
30
- return state;
31
- });
32
- }
33
- function getBounds(screenId) {
34
- "worklet";
35
-
36
- return registry.value[screenId] ?? {};
37
- }
38
- function setActiveBoundId(boundId) {
39
- "worklet";
40
-
41
- activeBoundId.value = boundId;
42
- }
43
- function getActiveBoundId() {
44
- "worklet";
45
-
46
- return activeBoundId.value;
47
- }
48
- function setRouteActive(routeKey, boundId) {
49
- "worklet";
50
-
51
- lastActiveByRoute.modify(state => {
52
- "worklet";
53
-
54
- state[routeKey] = boundId;
55
- return state;
56
- });
57
- }
58
- function getRouteActive(routeKey) {
59
- "worklet";
60
-
61
- return lastActiveByRoute.value[routeKey] ?? null;
62
- }
63
- function setTransitionHint(fromKey, toKey, boundId) {
64
- "worklet";
65
-
66
- const key = pairKey(fromKey, toKey);
67
- if (!key) return;
68
- pairHints.modify(state => {
69
- "worklet";
70
-
71
- state[key] = boundId;
72
- return state;
73
- });
74
- }
75
- function getTransitionHint(fromKey, toKey) {
76
- "worklet";
77
-
78
- const key = pairKey(fromKey, toKey);
79
- if (!key) return null;
80
- return pairHints.value[key] ?? null;
81
- }
82
- function clear(routeKey) {
83
- "worklet";
84
-
85
- registry.modify(state => {
86
- "worklet";
87
-
88
- delete state[routeKey];
89
- return state;
90
- });
91
- }
92
- function clearActive() {
93
- "worklet";
94
-
95
- activeBoundId.value = null;
96
- }
97
-
98
- // Helpers for readability
99
- function hasBound(s, id) {
100
- "worklet";
101
-
102
- return !!id && !!s && !!s.bounds && !!s.bounds[id];
103
- }
104
- function keysOf(s) {
105
- "worklet";
106
-
107
- return Object.keys(s?.bounds || {});
108
- }
109
- function getRoutePair(current, next, previous) {
110
- "worklet";
111
-
112
- const isClosing = !!next;
113
- const fromKey = isClosing ? current.route.key : previous?.route.key;
114
- const toKey = isClosing ? next?.route.key : current.route.key;
115
- const other = next ?? previous;
116
- return {
117
- fromKey,
118
- toKey,
119
- other
120
- };
121
- }
122
- function resolveFromHints(fromKey, toKey, other) {
123
- "worklet";
124
-
125
- if (fromKey && toKey) {
126
- const hinted = getTransitionHint(fromKey, toKey);
127
- if (hasBound(other, hinted)) return hinted;
128
- }
129
- return "";
130
- }
131
- function resolveFromRequested(reqId, current, other) {
132
- "worklet";
133
-
134
- const otherHasAny = !!other && keysOf(other).length > 0;
135
- if (hasBound(other, reqId)) return reqId;
136
- if (!otherHasAny && hasBound(current, reqId)) return reqId;
137
- return "";
138
- }
139
- function resolveFromSets(current, other, fromKey) {
140
- "worklet";
141
-
142
- if (!other) return "";
143
- const a = keysOf(current);
144
- const b = keysOf(other);
145
- const inter = a.filter(k => b.includes(k));
146
- const otherHasAny = b.length > 0;
147
- const routeActive = fromKey ? getRouteActive(fromKey) : null;
148
- if (inter.length > 0) {
149
- if (routeActive && inter.includes(routeActive)) return routeActive;
150
- return inter[0];
151
- }
152
- if (routeActive && hasBound(other, routeActive)) return routeActive;
153
- if (b.length === 1) return b[0];
154
- if (!otherHasAny) {
155
- if (routeActive && hasBound(current, routeActive)) return routeActive;
156
- if (a.length === 1) return a[0];
157
- }
158
- return "";
159
- }
160
- function getActiveBound(current, next, previous) {
161
- "worklet";
162
-
163
- const requestedId = activeBoundId.value;
164
- const {
165
- fromKey,
166
- toKey,
167
- other
168
- } = getRoutePair(current, next, previous);
169
-
170
- // check last remembered hint
171
- const byHint = resolveFromHints(fromKey, toKey, other);
172
- if (byHint) {
173
- if (fromKey && toKey) setTransitionHint(fromKey, toKey, byHint);
174
- return byHint;
175
- }
176
-
177
- // check the active id
178
- const byRequested = resolveFromRequested(requestedId, current, other);
179
- if (byRequested) {
180
- if (fromKey && toKey) setTransitionHint(fromKey, toKey, byRequested);
181
- return byRequested;
182
- }
183
-
184
- // check the sets (intersection/MRU/fallbacks)
185
- const bySets = resolveFromSets(current, other, fromKey);
186
- if (bySets) {
187
- if (fromKey && toKey) setTransitionHint(fromKey, toKey, bySets);
188
- return bySets;
189
- }
190
- return "";
191
- }
192
- const Bounds = exports.Bounds = {
193
- setBounds,
194
- getBounds,
195
- setActiveBoundId,
196
- getActiveBoundId,
197
- setRouteActive,
198
- getRouteActive,
199
- setTransitionHint,
200
- getTransitionHint,
201
- clear,
202
- clearActive,
203
- getActiveBound
204
- };
205
- //# sourceMappingURL=bounds.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNativeReanimated","require","registry","makeMutable","activeBoundId","lastActiveByRoute","pairHints","pairKey","fromKey","toKey","setBounds","screenId","boundId","bounds","styles","modify","state","getBounds","value","setActiveBoundId","getActiveBoundId","setRouteActive","routeKey","getRouteActive","setTransitionHint","key","getTransitionHint","clear","clearActive","hasBound","s","id","keysOf","Object","keys","getRoutePair","current","next","previous","isClosing","route","other","resolveFromHints","hinted","resolveFromRequested","reqId","otherHasAny","length","resolveFromSets","a","b","inter","filter","k","includes","routeActive","getActiveBound","requestedId","byHint","byRequested","bySets","Bounds","exports"],"sourceRoot":"../../../src","sources":["stores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