react-native-screen-transitions 3.0.0-beta.4 → 3.0.0-beta.5

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 (43) hide show
  1. package/lib/commonjs/shared/components/controllers/screen-lifecycle.js +11 -5
  2. package/lib/commonjs/shared/components/controllers/screen-lifecycle.js.map +1 -1
  3. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js +40 -28
  4. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  5. package/lib/commonjs/shared/hooks/use-derived-value-state.js +33 -0
  6. package/lib/commonjs/shared/hooks/use-derived-value-state.js.map +1 -0
  7. package/lib/commonjs/shared/providers/gestures.js +6 -3
  8. package/lib/commonjs/shared/providers/gestures.js.map +1 -1
  9. package/lib/commonjs/shared/providers/utils/create-provider.js +41 -29
  10. package/lib/commonjs/shared/providers/utils/create-provider.js.map +1 -1
  11. package/lib/module/shared/components/controllers/screen-lifecycle.js +11 -5
  12. package/lib/module/shared/components/controllers/screen-lifecycle.js.map +1 -1
  13. package/lib/module/shared/hooks/gestures/use-build-gestures.js +42 -30
  14. package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  15. package/lib/module/shared/hooks/use-derived-value-state.js +30 -0
  16. package/lib/module/shared/hooks/use-derived-value-state.js.map +1 -0
  17. package/lib/module/shared/providers/gestures.js +6 -3
  18. package/lib/module/shared/providers/gestures.js.map +1 -1
  19. package/lib/module/shared/providers/utils/create-provider.js +40 -27
  20. package/lib/module/shared/providers/utils/create-provider.js.map +1 -1
  21. package/lib/typescript/shared/components/controllers/screen-lifecycle.d.ts.map +1 -1
  22. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts +5 -2
  23. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
  24. package/lib/typescript/shared/hooks/use-derived-value-state.d.ts +9 -0
  25. package/lib/typescript/shared/hooks/use-derived-value-state.d.ts.map +1 -0
  26. package/lib/typescript/shared/providers/gestures.d.ts +4 -2
  27. package/lib/typescript/shared/providers/gestures.d.ts.map +1 -1
  28. package/lib/typescript/shared/providers/utils/create-provider.d.ts +11 -29
  29. package/lib/typescript/shared/providers/utils/create-provider.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/shared/components/controllers/screen-lifecycle.tsx +10 -6
  32. package/src/shared/hooks/gestures/use-build-gestures.tsx +63 -35
  33. package/src/shared/hooks/use-derived-value-state.ts +41 -0
  34. package/src/shared/providers/gestures.tsx +17 -8
  35. package/src/shared/providers/utils/create-provider.tsx +77 -0
  36. package/lib/commonjs/shared/stores/navigator-dismiss-state.js +0 -23
  37. package/lib/commonjs/shared/stores/navigator-dismiss-state.js.map +0 -1
  38. package/lib/module/shared/stores/navigator-dismiss-state.js +0 -19
  39. package/lib/module/shared/stores/navigator-dismiss-state.js.map +0 -1
  40. package/lib/typescript/shared/stores/navigator-dismiss-state.d.ts +0 -7
  41. package/lib/typescript/shared/stores/navigator-dismiss-state.d.ts.map +0 -1
  42. package/src/shared/providers/utils/create-provider.ts +0 -64
  43. package/src/shared/stores/navigator-dismiss-state.ts +0 -17
@@ -1,4 +1,5 @@
1
- import { useMemo } from "react";
1
+ import { StackActions } from "@react-navigation/native";
2
+ import { useCallback, useMemo } from "react";
2
3
  import { useWindowDimensions } from "react-native";
3
4
  import {
4
5
  Gesture,
@@ -9,11 +10,7 @@ import {
9
10
  type PanGestureHandlerEventPayload,
10
11
  } from "react-native-gesture-handler";
11
12
  import type { GestureStateManagerType } from "react-native-gesture-handler/lib/typescript/handlers/gestures/gestureStateManager";
12
- import {
13
- runOnJS,
14
- type SharedValue,
15
- useSharedValue,
16
- } from "react-native-reanimated";
13
+ import { type SharedValue, useSharedValue } from "react-native-reanimated";
17
14
  import {
18
15
  DEFAULT_GESTURE_ACTIVATION_AREA,
19
16
  DEFAULT_GESTURE_DIRECTION,
@@ -21,11 +18,14 @@ import {
21
18
  DEFAULT_GESTURE_ENABLED,
22
19
  GESTURE_VELOCITY_IMPACT,
23
20
  } from "../../constants";
24
- import type { ScrollConfig } from "../../providers/gestures";
21
+ import type {
22
+ GestureContextType,
23
+ ScrollConfig,
24
+ } from "../../providers/gestures";
25
25
  import { useKeys } from "../../providers/keys";
26
26
  import { AnimationStore } from "../../stores/animation-store";
27
- import { GestureStore } from "../../stores/gesture-store";
28
- import { NavigatorDismissState } from "../../stores/navigator-dismiss-state";
27
+ import { GestureStore, type GestureStoreMap } from "../../stores/gesture-store";
28
+
29
29
  import { type GestureDirection, GestureOffsetState } from "../../types/gesture";
30
30
  import { startScreenTransition } from "../../utils/animation/start-screen-transition";
31
31
  import { applyOffsetRules } from "../../utils/gesture/check-gesture-activation";
@@ -33,18 +33,20 @@ import { determineDismissal } from "../../utils/gesture/determine-dismissal";
33
33
  import { mapGestureToProgress } from "../../utils/gesture/map-gesture-to-progress";
34
34
  import { resetGestureValues } from "../../utils/gesture/reset-gesture-values";
35
35
  import { velocity } from "../../utils/gesture/velocity";
36
- import useStableCallback from "../use-stable-callback";
37
36
  import useStableCallbackValue from "../use-stable-callback-value";
38
37
 
39
38
  interface BuildGesturesHookProps {
40
39
  scrollConfig: SharedValue<ScrollConfig | null>;
40
+ parentContext?: GestureContextType | null;
41
41
  }
42
42
 
43
43
  export const useBuildGestures = ({
44
44
  scrollConfig,
45
+ parentContext,
45
46
  }: BuildGesturesHookProps): {
46
47
  panGesture: GestureType;
47
48
  nativeGesture: GestureType;
49
+ gestureAnimationValues: GestureStoreMap;
48
50
  } => {
49
51
  const dimensions = useWindowDimensions();
50
52
  const { current } = useKeys();
@@ -58,7 +60,9 @@ export const useBuildGestures = ({
58
60
  GestureOffsetState.PENDING,
59
61
  );
60
62
 
61
- const gestures = GestureStore.getRouteGestures(current.route.key);
63
+ const gestureAnimationValues = GestureStore.getRouteGestures(
64
+ current.route.key,
65
+ );
62
66
  const animations = AnimationStore.getAll(current.route.key);
63
67
 
64
68
  const {
@@ -87,17 +91,29 @@ export const useBuildGestures = ({
87
91
  };
88
92
  }, [gestureDirection]);
89
93
 
90
- const setNavigatorDismissal = useStableCallback(() => {
91
- const key = current.navigation.getState().key;
94
+ const handleDismiss = useCallback(() => {
95
+ // If an ancestor navigator is already dismissing, skip this dismiss to
96
+ // avoid racing with the parent
97
+ if (parentContext?.gestureAnimationValues.isDismissing?.value) {
98
+ return;
99
+ }
92
100
 
93
- NavigatorDismissState.set(key, true);
94
- });
101
+ const state = current.navigation.getState();
95
102
 
96
- const handleDismiss = useStableCallback(() => {
97
- const key = current.navigation.getState().key;
98
- current.navigation.goBack();
99
- NavigatorDismissState.remove(key);
100
- });
103
+ const routeStillPresent = state.routes.some(
104
+ (route) => route.key === current.route.key,
105
+ );
106
+
107
+ if (!routeStillPresent) {
108
+ return;
109
+ }
110
+
111
+ current.navigation.dispatch({
112
+ ...StackActions.pop(),
113
+ source: current.route.key,
114
+ target: state.key,
115
+ });
116
+ }, [current, parentContext]);
101
117
 
102
118
  const onTouchesDown = useStableCallbackValue((e: GestureTouchEvent) => {
103
119
  "worklet";
@@ -110,6 +126,13 @@ export const useBuildGestures = ({
110
126
  (e: GestureTouchEvent, manager: GestureStateManagerType) => {
111
127
  "worklet";
112
128
 
129
+ // If an ancestor navigator is already dismissing via gesture, block new gestures here.
130
+ if (parentContext?.gestureAnimationValues.isDismissing?.value) {
131
+ gestureOffsetState.value = GestureOffsetState.FAILED;
132
+ manager.fail();
133
+ return;
134
+ }
135
+
113
136
  const touch = e.changedTouches[0];
114
137
 
115
138
  const { isSwipingDown, isSwipingUp, isSwipingRight, isSwipingLeft } =
@@ -130,7 +153,7 @@ export const useBuildGestures = ({
130
153
  }
131
154
 
132
155
  // Keep pending until thresholds are met; no eager activation.
133
- if (gestures.isDragging?.value) {
156
+ if (gestureAnimationValues.isDragging?.value) {
134
157
  manager.activate();
135
158
  return;
136
159
  }
@@ -178,9 +201,9 @@ export const useBuildGestures = ({
178
201
  if (
179
202
  shouldActivate &&
180
203
  gestureOffsetState.value === GestureOffsetState.PASSED &&
181
- !gestures.isDismissing?.value
204
+ !gestureAnimationValues.isDismissing?.value
182
205
  ) {
183
- gestures.direction.value = activatedDirection;
206
+ gestureAnimationValues.direction.value = activatedDirection;
184
207
  manager.activate();
185
208
  return;
186
209
  }
@@ -189,8 +212,8 @@ export const useBuildGestures = ({
189
212
 
190
213
  const onStart = useStableCallbackValue(() => {
191
214
  "worklet";
192
- gestures.isDragging.value = 1;
193
- gestures.isDismissing.value = 0;
215
+ gestureAnimationValues.isDragging.value = 1;
216
+ gestureAnimationValues.isDismissing.value = 0;
194
217
  });
195
218
 
196
219
  const onUpdate = useStableCallbackValue(
@@ -202,13 +225,13 @@ export const useBuildGestures = ({
202
225
  const { translationX, translationY } = event;
203
226
  const { width, height } = dimensions;
204
227
 
205
- gestures.x.value = translationX;
206
- gestures.y.value = translationY;
207
- gestures.normalizedX.value = Math.max(
228
+ gestureAnimationValues.x.value = translationX;
229
+ gestureAnimationValues.y.value = translationY;
230
+ gestureAnimationValues.normalizedX.value = Math.max(
208
231
  -1,
209
232
  Math.min(1, translationX / width),
210
233
  );
211
- gestures.normalizedY.value = Math.max(
234
+ gestureAnimationValues.normalizedY.value = Math.max(
212
235
  -1,
213
236
  Math.min(1, translationY / height),
214
237
  );
@@ -275,16 +298,12 @@ export const useBuildGestures = ({
275
298
 
276
299
  resetGestureValues({
277
300
  spec,
278
- gestures,
301
+ gestures: gestureAnimationValues,
279
302
  shouldDismiss,
280
303
  event,
281
304
  dimensions,
282
305
  });
283
306
 
284
- if (shouldDismiss) {
285
- runOnJS(setNavigatorDismissal)();
286
- }
287
-
288
307
  const initialVelocity = velocity.calculateProgressVelocity({
289
308
  animations,
290
309
  shouldDismiss,
@@ -319,6 +338,15 @@ export const useBuildGestures = ({
319
338
  return {
320
339
  panGesture,
321
340
  nativeGesture,
341
+ gestureAnimationValues,
322
342
  };
323
- }, [gestureEnabled, onTouchesDown, onTouchesMove, onStart, onUpdate, onEnd]);
343
+ }, [
344
+ gestureEnabled,
345
+ onTouchesDown,
346
+ onTouchesMove,
347
+ onStart,
348
+ onUpdate,
349
+ onEnd,
350
+ gestureAnimationValues,
351
+ ]);
324
352
  };
@@ -0,0 +1,41 @@
1
+ import { useState } from "react";
2
+ import {
3
+ executeOnUIRuntimeSync,
4
+ runOnJS,
5
+ type SharedValue,
6
+ useAnimatedReaction,
7
+ useDerivedValue,
8
+ } from "react-native-reanimated";
9
+
10
+ /**
11
+ * Derives React state from a Reanimated worklet.
12
+ *
13
+ * @param processor - The worklet function that calculates the value
14
+ * @param dependencies - Array of dependencies for the worklet
15
+ * @returns The derived value as React State
16
+ */
17
+ export function useDerivedValueState<T>(
18
+ processor: () => T,
19
+ dependencies: any[] = [],
20
+ ): T {
21
+ const derivedValue = useDerivedValue(processor, dependencies);
22
+
23
+ const [state, setState] = useState<T>(() => {
24
+ const readOnUI = executeOnUIRuntimeSync((sv: SharedValue<T>) => {
25
+ "worklet";
26
+ return sv.value;
27
+ });
28
+ return readOnUI(derivedValue);
29
+ });
30
+
31
+ useAnimatedReaction(
32
+ () => derivedValue.value,
33
+ (curr, prev) => {
34
+ if (curr !== prev) {
35
+ runOnJS(setState)(curr);
36
+ }
37
+ },
38
+ );
39
+
40
+ return state;
41
+ }
@@ -5,6 +5,7 @@ import { GestureDetector } from "react-native-gesture-handler";
5
5
  import type { SharedValue } from "react-native-reanimated";
6
6
  import { useSharedValue } from "react-native-reanimated";
7
7
  import { useBuildGestures } from "../hooks/gestures/use-build-gestures";
8
+ import type { GestureStoreMap } from "../stores/gesture-store";
8
9
 
9
10
  export type ScrollConfig = {
10
11
  x: number;
@@ -19,34 +20,42 @@ export interface GestureContextType {
19
20
  panGesture: GestureType;
20
21
  nativeGesture: GestureType;
21
22
  scrollConfig: SharedValue<ScrollConfig | null>;
23
+ gestureAnimationValues: GestureStoreMap;
22
24
  parentContext: GestureContextType | null;
23
25
  }
24
26
 
25
- type ScreenGestureProviderProps = {
27
+ type GestureProviderProps = {
26
28
  children: React.ReactNode;
27
29
  };
28
30
 
29
31
  const GestureContext = createContext<GestureContextType | undefined>(undefined);
30
32
 
31
- export const ScreenGestureProvider = ({
32
- children,
33
- }: ScreenGestureProviderProps) => {
33
+ export const ScreenGestureProvider = ({ children }: GestureProviderProps) => {
34
34
  const parentContext = useContext(GestureContext);
35
35
 
36
36
  const scrollConfig = useSharedValue<ScrollConfig | null>(null);
37
37
 
38
- const { panGesture, nativeGesture } = useBuildGestures({
39
- scrollConfig,
40
- });
38
+ const { panGesture, nativeGesture, gestureAnimationValues } =
39
+ useBuildGestures({
40
+ scrollConfig,
41
+ parentContext,
42
+ });
41
43
 
42
44
  const value: GestureContextType = useMemo(
43
45
  () => ({
44
46
  panGesture,
45
47
  scrollConfig,
46
48
  nativeGesture,
49
+ gestureAnimationValues,
47
50
  parentContext: parentContext || null,
48
51
  }),
49
- [panGesture, scrollConfig, nativeGesture, parentContext],
52
+ [
53
+ panGesture,
54
+ scrollConfig,
55
+ nativeGesture,
56
+ gestureAnimationValues,
57
+ parentContext,
58
+ ],
50
59
  );
51
60
 
52
61
  return (
@@ -0,0 +1,77 @@
1
+ /**
2
+ * THANK YOU @MatiPl01
3
+ * https://github.com/MatiPl01/react-native-sortables/blob/main/packages/react-native-sortables/src/providers/utils/createProvider.tsx
4
+ * SUPER COOL AMAZING UTILITY
5
+ */
6
+ import {
7
+ createContext,
8
+ type PropsWithChildren,
9
+ type ReactNode,
10
+ useContext,
11
+ useMemo,
12
+ } from "react";
13
+
14
+ export default function createProvider<
15
+ ProviderName extends string,
16
+ Guarded extends boolean = true,
17
+ >(name: ProviderName, options?: { guarded?: Guarded }) {
18
+ return <ProviderProps extends PropsWithChildren<object>, ContextValue>(
19
+ factory: (props: ProviderProps) => {
20
+ value?: ContextValue;
21
+ enabled?: boolean;
22
+ children?: ReactNode;
23
+ },
24
+ ) => {
25
+ const { guarded = true } = options ?? {};
26
+
27
+ const Context = createContext<ContextValue | null>(null);
28
+ Context.displayName = name;
29
+
30
+ const Provider: React.FC<ProviderProps> = (props) => {
31
+ const {
32
+ children = props.children,
33
+ enabled = true,
34
+ value,
35
+ } = factory(props);
36
+
37
+ if (!value) {
38
+ throw new Error(
39
+ `${name}Context value must be provided. You likely forgot to return it from the factory function.`,
40
+ );
41
+ }
42
+
43
+ const memoValue = useMemo(
44
+ () => (enabled ? value : null),
45
+ [enabled, value],
46
+ );
47
+
48
+ return <Context.Provider value={memoValue}>{children}</Context.Provider>;
49
+ };
50
+
51
+ const useEnhancedContext = (): ContextValue | null => {
52
+ const context = useContext(Context);
53
+
54
+ if (guarded && context === null) {
55
+ throw new Error(
56
+ `${name} context must be used within a ${name}Provider`,
57
+ );
58
+ }
59
+
60
+ return context;
61
+ };
62
+
63
+ return {
64
+ [`${name}Context`]: Context,
65
+ [`${name}Provider`]: Provider,
66
+ [`use${name}Context`]: useEnhancedContext,
67
+ } as {
68
+ [P in ProviderName as `${P}Context`]: React.Context<ContextValue>;
69
+ } & {
70
+ [P in ProviderName as `${P}Provider`]: React.FC<ProviderProps>;
71
+ } & {
72
+ [P in ProviderName as `use${P}Context`]: () => Guarded extends true
73
+ ? ContextValue
74
+ : ContextValue | null;
75
+ };
76
+ };
77
+ }
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.NavigatorDismissState = void 0;
7
- const map = new Map();
8
- const NavigatorDismissState = exports.NavigatorDismissState = {
9
- get(id) {
10
- if (!id) return false;
11
- return map.get(id) === true;
12
- },
13
- set(id, val) {
14
- map.set(id, !!val);
15
- },
16
- remove(id) {
17
- map.delete(id);
18
- },
19
- clear() {
20
- map.clear();
21
- }
22
- };
23
- //# sourceMappingURL=navigator-dismiss-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["map","Map","NavigatorDismissState","exports","get","id","set","val","remove","delete","clear"],"sourceRoot":"../../../../src","sources":["shared/stores/navigator-dismiss-state.ts"],"mappings":";;;;;;AAAA,MAAMA,GAAG,GAAG,IAAIC,GAAG,CAAkB,CAAC;AAE/B,MAAMC,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAG;EACpCE,GAAGA,CAACC,EAAsB,EAAW;IACpC,IAAI,CAACA,EAAE,EAAE,OAAO,KAAK;IACrB,OAAOL,GAAG,CAACI,GAAG,CAACC,EAAE,CAAC,KAAK,IAAI;EAC5B,CAAC;EACDC,GAAGA,CAACD,EAAU,EAAEE,GAAY,EAAE;IAC7BP,GAAG,CAACM,GAAG,CAACD,EAAE,EAAE,CAAC,CAACE,GAAG,CAAC;EACnB,CAAC;EACDC,MAAMA,CAACH,EAAU,EAAE;IAClBL,GAAG,CAACS,MAAM,CAACJ,EAAE,CAAC;EACf,CAAC;EACDK,KAAKA,CAAA,EAAG;IACPV,GAAG,CAACU,KAAK,CAAC,CAAC;EACZ;AACD,CAAC","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const map = new Map();
4
- export const NavigatorDismissState = {
5
- get(id) {
6
- if (!id) return false;
7
- return map.get(id) === true;
8
- },
9
- set(id, val) {
10
- map.set(id, !!val);
11
- },
12
- remove(id) {
13
- map.delete(id);
14
- },
15
- clear() {
16
- map.clear();
17
- }
18
- };
19
- //# sourceMappingURL=navigator-dismiss-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["map","Map","NavigatorDismissState","get","id","set","val","remove","delete","clear"],"sourceRoot":"../../../../src","sources":["shared/stores/navigator-dismiss-state.ts"],"mappings":";;AAAA,MAAMA,GAAG,GAAG,IAAIC,GAAG,CAAkB,CAAC;AAEtC,OAAO,MAAMC,qBAAqB,GAAG;EACpCC,GAAGA,CAACC,EAAsB,EAAW;IACpC,IAAI,CAACA,EAAE,EAAE,OAAO,KAAK;IACrB,OAAOJ,GAAG,CAACG,GAAG,CAACC,EAAE,CAAC,KAAK,IAAI;EAC5B,CAAC;EACDC,GAAGA,CAACD,EAAU,EAAEE,GAAY,EAAE;IAC7BN,GAAG,CAACK,GAAG,CAACD,EAAE,EAAE,CAAC,CAACE,GAAG,CAAC;EACnB,CAAC;EACDC,MAAMA,CAACH,EAAU,EAAE;IAClBJ,GAAG,CAACQ,MAAM,CAACJ,EAAE,CAAC;EACf,CAAC;EACDK,KAAKA,CAAA,EAAG;IACPT,GAAG,CAACS,KAAK,CAAC,CAAC;EACZ;AACD,CAAC","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- export declare const NavigatorDismissState: {
2
- get(id: string | undefined): boolean;
3
- set(id: string, val: boolean): void;
4
- remove(id: string): void;
5
- clear(): void;
6
- };
7
- //# sourceMappingURL=navigator-dismiss-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"navigator-dismiss-state.d.ts","sourceRoot":"","sources":["../../../../src/shared/stores/navigator-dismiss-state.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB;YACzB,MAAM,GAAG,SAAS,GAAG,OAAO;YAI5B,MAAM,OAAO,OAAO;eAGjB,MAAM;;CAMjB,CAAC"}
@@ -1,64 +0,0 @@
1
- /**
2
- * Credits to
3
- * https://github.com/heroui-inc/heroui-native/blob/beta/src/helpers/utils/create-context.ts
4
- */
5
- import * as React from "react";
6
-
7
- export interface CreateContextOptions {
8
- /**
9
- * If `true`, React will throw if context is `null` or `undefined`
10
- * In some cases, you might want to support nested context, so you can set it to `false`
11
- */
12
- strict?: boolean;
13
- /**
14
- * Error message to throw if the context is `undefined`
15
- */
16
- errorMessage?: string;
17
- /**
18
- * The display name of the context
19
- */
20
- name?: string;
21
- }
22
-
23
- export type CreateContextReturn<T> = [
24
- React.Provider<T>,
25
- () => T,
26
- React.Context<T>,
27
- ];
28
-
29
- /**
30
- * Creates a named context, provider, and hook.
31
- *
32
- * @param options create context options
33
- */
34
- export function createContext<ContextType>(options: CreateContextOptions = {}) {
35
- const {
36
- strict = true,
37
- errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider",
38
- name,
39
- } = options;
40
-
41
- const Context = React.createContext<ContextType | undefined>(undefined);
42
-
43
- Context.displayName = name;
44
-
45
- function useContext() {
46
- const context = React.useContext(Context);
47
-
48
- if (!context && strict) {
49
- const error = new Error(errorMessage);
50
-
51
- error.name = "ContextError";
52
- Error.captureStackTrace?.(error, useContext);
53
- throw error;
54
- }
55
-
56
- return context;
57
- }
58
-
59
- return [
60
- Context.Provider,
61
- useContext,
62
- Context,
63
- ] as CreateContextReturn<ContextType>;
64
- }
@@ -1,17 +0,0 @@
1
- const map = new Map<string, boolean>();
2
-
3
- export const NavigatorDismissState = {
4
- get(id: string | undefined): boolean {
5
- if (!id) return false;
6
- return map.get(id) === true;
7
- },
8
- set(id: string, val: boolean) {
9
- map.set(id, !!val);
10
- },
11
- remove(id: string) {
12
- map.delete(id);
13
- },
14
- clear() {
15
- map.clear();
16
- },
17
- };