react-native-screen-transitions 3.9.0-alpha.3 → 3.9.0-beta.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 (105) hide show
  1. package/lib/commonjs/shared/components/boundary/portal/components/portal-boundary-host.js +31 -1
  2. package/lib/commonjs/shared/components/boundary/portal/components/portal-boundary-host.js.map +1 -1
  3. package/lib/commonjs/shared/components/boundary/portal/components/portal.js +7 -43
  4. package/lib/commonjs/shared/components/boundary/portal/components/portal.js.map +1 -1
  5. package/lib/commonjs/shared/components/boundary/portal/hooks/use-placeholder-styles.js +57 -0
  6. package/lib/commonjs/shared/components/boundary/portal/hooks/use-placeholder-styles.js.map +1 -0
  7. package/lib/commonjs/shared/components/boundary/portal/utils/offset-style.js +4 -3
  8. package/lib/commonjs/shared/components/boundary/portal/utils/offset-style.js.map +1 -1
  9. package/lib/commonjs/shared/components/masked-view.js +5 -0
  10. package/lib/commonjs/shared/components/masked-view.js.map +1 -1
  11. package/lib/commonjs/shared/components/screen-container/layers/backdrop.js +18 -8
  12. package/lib/commonjs/shared/components/screen-container/layers/backdrop.js.map +1 -1
  13. package/lib/commonjs/shared/components/screen-container/layers/content.js +34 -16
  14. package/lib/commonjs/shared/components/screen-container/layers/content.js.map +1 -1
  15. package/lib/commonjs/shared/components/screen-container/layers/render-component.js +10 -0
  16. package/lib/commonjs/shared/components/screen-container/layers/render-component.js.map +1 -0
  17. package/lib/commonjs/shared/components/screen-container/layers/surface-container.js +5 -3
  18. package/lib/commonjs/shared/components/screen-container/layers/surface-container.js.map +1 -1
  19. package/lib/commonjs/shared/index.js +4 -0
  20. package/lib/commonjs/shared/index.js.map +1 -1
  21. package/lib/commonjs/shared/providers/register-bounds.provider.js +6 -0
  22. package/lib/commonjs/shared/providers/register-bounds.provider.js.map +1 -1
  23. package/lib/commonjs/shared/providers/screen/animation/helpers/read-screen-animation-revisions.js +6 -1
  24. package/lib/commonjs/shared/providers/screen/animation/helpers/read-screen-animation-revisions.js.map +1 -1
  25. package/lib/commonjs/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.js +50 -0
  26. package/lib/commonjs/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.js.map +1 -0
  27. package/lib/commonjs/shared/providers/screen/styles/hooks/use-interpolated-style-maps.js +7 -1
  28. package/lib/commonjs/shared/providers/screen/styles/hooks/use-interpolated-style-maps.js.map +1 -1
  29. package/lib/module/shared/components/boundary/portal/components/portal-boundary-host.js +31 -1
  30. package/lib/module/shared/components/boundary/portal/components/portal-boundary-host.js.map +1 -1
  31. package/lib/module/shared/components/boundary/portal/components/portal.js +8 -44
  32. package/lib/module/shared/components/boundary/portal/components/portal.js.map +1 -1
  33. package/lib/module/shared/components/boundary/portal/hooks/use-placeholder-styles.js +52 -0
  34. package/lib/module/shared/components/boundary/portal/hooks/use-placeholder-styles.js.map +1 -0
  35. package/lib/module/shared/components/boundary/portal/utils/offset-style.js +4 -3
  36. package/lib/module/shared/components/boundary/portal/utils/offset-style.js.map +1 -1
  37. package/lib/module/shared/components/masked-view.js +5 -0
  38. package/lib/module/shared/components/masked-view.js.map +1 -1
  39. package/lib/module/shared/components/screen-container/layers/backdrop.js +19 -9
  40. package/lib/module/shared/components/screen-container/layers/backdrop.js.map +1 -1
  41. package/lib/module/shared/components/screen-container/layers/content.js +35 -17
  42. package/lib/module/shared/components/screen-container/layers/content.js.map +1 -1
  43. package/lib/module/shared/components/screen-container/layers/render-component.js +6 -0
  44. package/lib/module/shared/components/screen-container/layers/render-component.js.map +1 -0
  45. package/lib/module/shared/components/screen-container/layers/surface-container.js +5 -3
  46. package/lib/module/shared/components/screen-container/layers/surface-container.js.map +1 -1
  47. package/lib/module/shared/index.js +4 -0
  48. package/lib/module/shared/index.js.map +1 -1
  49. package/lib/module/shared/providers/register-bounds.provider.js +6 -0
  50. package/lib/module/shared/providers/register-bounds.provider.js.map +1 -1
  51. package/lib/module/shared/providers/screen/animation/helpers/read-screen-animation-revisions.js +6 -1
  52. package/lib/module/shared/providers/screen/animation/helpers/read-screen-animation-revisions.js.map +1 -1
  53. package/lib/module/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.js +45 -0
  54. package/lib/module/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.js.map +1 -0
  55. package/lib/module/shared/providers/screen/styles/hooks/use-interpolated-style-maps.js +7 -1
  56. package/lib/module/shared/providers/screen/styles/hooks/use-interpolated-style-maps.js.map +1 -1
  57. package/lib/typescript/component-stack/types.d.ts +26 -0
  58. package/lib/typescript/component-stack/types.d.ts.map +1 -1
  59. package/lib/typescript/shared/components/boundary/portal/components/portal-boundary-host.d.ts.map +1 -1
  60. package/lib/typescript/shared/components/boundary/portal/components/portal.d.ts.map +1 -1
  61. package/lib/typescript/shared/components/boundary/portal/hooks/use-placeholder-styles.d.ts +17 -0
  62. package/lib/typescript/shared/components/boundary/portal/hooks/use-placeholder-styles.d.ts.map +1 -0
  63. package/lib/typescript/shared/components/boundary/portal/utils/offset-style.d.ts +10 -1
  64. package/lib/typescript/shared/components/boundary/portal/utils/offset-style.d.ts.map +1 -1
  65. package/lib/typescript/shared/components/masked-view.d.ts +4 -0
  66. package/lib/typescript/shared/components/masked-view.d.ts.map +1 -1
  67. package/lib/typescript/shared/components/screen-container/layers/backdrop.d.ts.map +1 -1
  68. package/lib/typescript/shared/components/screen-container/layers/content.d.ts.map +1 -1
  69. package/lib/typescript/shared/components/screen-container/layers/render-component.d.ts +3 -0
  70. package/lib/typescript/shared/components/screen-container/layers/render-component.d.ts.map +1 -0
  71. package/lib/typescript/shared/components/screen-container/layers/surface-container.d.ts.map +1 -1
  72. package/lib/typescript/shared/index.d.ts +37 -33
  73. package/lib/typescript/shared/index.d.ts.map +1 -1
  74. package/lib/typescript/shared/providers/register-bounds.provider.d.ts.map +1 -1
  75. package/lib/typescript/shared/providers/screen/animation/helpers/read-screen-animation-revisions.d.ts +4 -1
  76. package/lib/typescript/shared/providers/screen/animation/helpers/read-screen-animation-revisions.d.ts.map +1 -1
  77. package/lib/typescript/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.d.ts +4 -0
  78. package/lib/typescript/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.d.ts.map +1 -0
  79. package/lib/typescript/shared/providers/screen/styles/hooks/use-interpolated-style-maps.d.ts.map +1 -1
  80. package/lib/typescript/shared/providers/screen/styles/hooks/use-maybe-block-visibility.d.ts +1 -1
  81. package/lib/typescript/shared/types/index.d.ts +1 -1
  82. package/lib/typescript/shared/types/index.d.ts.map +1 -1
  83. package/lib/typescript/shared/types/screen.types.d.ts +99 -4
  84. package/lib/typescript/shared/types/screen.types.d.ts.map +1 -1
  85. package/lib/typescript/shared/utils/bounds/types/options.d.ts +2 -0
  86. package/lib/typescript/shared/utils/bounds/types/options.d.ts.map +1 -1
  87. package/package.json +1 -1
  88. package/src/component-stack/types.ts +26 -0
  89. package/src/shared/components/boundary/portal/components/portal-boundary-host.tsx +51 -0
  90. package/src/shared/components/boundary/portal/components/portal.tsx +7 -39
  91. package/src/shared/components/boundary/portal/hooks/use-placeholder-styles.ts +55 -0
  92. package/src/shared/components/boundary/portal/utils/offset-style.ts +9 -2
  93. package/src/shared/components/masked-view.tsx +4 -0
  94. package/src/shared/components/screen-container/layers/backdrop.tsx +31 -10
  95. package/src/shared/components/screen-container/layers/content.tsx +61 -22
  96. package/src/shared/components/screen-container/layers/render-component.ts +9 -0
  97. package/src/shared/components/screen-container/layers/surface-container.tsx +5 -4
  98. package/src/shared/index.ts +9 -0
  99. package/src/shared/providers/register-bounds.provider.tsx +5 -0
  100. package/src/shared/providers/screen/animation/helpers/read-screen-animation-revisions.ts +14 -0
  101. package/src/shared/providers/screen/styles/helpers/collect-interpolator-shared-values.ts +75 -0
  102. package/src/shared/providers/screen/styles/hooks/use-interpolated-style-maps.tsx +11 -0
  103. package/src/shared/types/index.ts +5 -0
  104. package/src/shared/types/screen.types.ts +111 -4
  105. package/src/shared/utils/bounds/types/options.ts +2 -0
@@ -0,0 +1,75 @@
1
+ import type { SharedValue } from "react-native-reanimated";
2
+ import type { ScreenStyleInterpolator } from "../../../../types/animation.types";
3
+
4
+ type WorkletClosure = Record<string, unknown>;
5
+
6
+ type ClosureCarrier = {
7
+ __closure?: WorkletClosure;
8
+ };
9
+
10
+ type SharedValueLike = SharedValue<unknown> & {
11
+ _isReanimatedSharedValue: true;
12
+ };
13
+
14
+ const isSharedValueLike = (value: unknown): value is SharedValueLike =>
15
+ (value as Partial<SharedValueLike> | null)?._isReanimatedSharedValue === true;
16
+
17
+ const getWorkletClosure = (value: unknown): WorkletClosure | undefined => {
18
+ if (
19
+ value === null ||
20
+ (typeof value !== "object" && typeof value !== "function")
21
+ ) {
22
+ return undefined;
23
+ }
24
+
25
+ const closure = (value as Partial<ClosureCarrier>).__closure;
26
+ return closure && typeof closure === "object" ? closure : undefined;
27
+ };
28
+
29
+ const isPlainObject = (value: unknown): value is Record<string, unknown> =>
30
+ value !== null &&
31
+ typeof value === "object" &&
32
+ Object.getPrototypeOf(value) === Object.prototype;
33
+
34
+ export const collectInterpolatorSharedValues = (
35
+ interpolators: Array<ScreenStyleInterpolator | undefined>,
36
+ ): SharedValue<unknown>[] => {
37
+ const sharedValues: SharedValue<unknown>[] = [];
38
+ const seen = new Set<unknown>();
39
+
40
+ const visit = (value: unknown) => {
41
+ if (value === null || value === undefined || seen.has(value)) {
42
+ return;
43
+ }
44
+ seen.add(value);
45
+
46
+ if (isSharedValueLike(value)) {
47
+ sharedValues.push(value);
48
+ return;
49
+ }
50
+
51
+ if (typeof value === "function") {
52
+ visit(getWorkletClosure(value));
53
+ return;
54
+ }
55
+
56
+ if (Array.isArray(value)) {
57
+ for (let index = 0; index < value.length; index++) {
58
+ visit(value[index]);
59
+ }
60
+ return;
61
+ }
62
+
63
+ if (isPlainObject(value)) {
64
+ for (const item of Object.values(value)) {
65
+ visit(item);
66
+ }
67
+ }
68
+ };
69
+
70
+ for (let index = 0; index < interpolators.length; index++) {
71
+ visit(getWorkletClosure(interpolators[index]));
72
+ }
73
+
74
+ return sharedValues;
75
+ };
@@ -1,3 +1,4 @@
1
+ import { useMemo } from "react";
1
2
  import { useDerivedValue, useSharedValue } from "react-native-reanimated";
2
3
  import { NO_STYLES } from "../../../../constants";
3
4
  import { AnimationStore } from "../../../../stores/animation.store";
@@ -22,6 +23,7 @@ import {
22
23
  syncScreenOptionsOverrides,
23
24
  useScreenOptionsContext,
24
25
  } from "../../options";
26
+ import { collectInterpolatorSharedValues } from "../helpers/collect-interpolator-shared-values";
25
27
  import { normalizeSlots } from "../helpers/normalize-slots";
26
28
  import { isOpeningBeforeStart } from "../helpers/opening-phase";
27
29
  import type { LocalStyleLayers } from "../helpers/resolve-slot-styles";
@@ -146,6 +148,14 @@ export const useInterpolatedStylesMap = () => {
146
148
  const transition = useBuildTransitionAccessor();
147
149
  const nextInterpolatorReady = useSharedValue(0);
148
150
 
151
+ // In some cases, a user may want to use external shared values to drive animations in the interpoaltor.
152
+ // We can now support this by collecting those shared values and reading them here to trigger an update.
153
+ const interpolatorSharedValues = useMemo(
154
+ () =>
155
+ collectInterpolatorSharedValues([currentInterpolator, nextInterpolator]),
156
+ [currentInterpolator, nextInterpolator],
157
+ );
158
+
149
159
  const activeScreenKey = nextScreenKey ?? currentScreenKey;
150
160
  const {
151
161
  entering: activeEntering,
@@ -162,6 +172,7 @@ export const useInterpolatedStylesMap = () => {
162
172
  screenInterpolatorPropsRevision,
163
173
  ancestorScreenAnimationSources,
164
174
  descendantScreenAnimationSources,
175
+ interpolatorSharedValues,
165
176
  );
166
177
  const props = screenInterpolatorProps.get();
167
178
 
@@ -54,7 +54,12 @@ export type {
54
54
  GestureTracking,
55
55
  InactiveBehavior,
56
56
  Layout,
57
+ ScreenBackdropComponent,
58
+ ScreenBackdropComponentProps,
59
+ ScreenContentComponent,
60
+ ScreenContentComponentProps,
57
61
  ScreenKey,
62
+ ScreenLayerComponentProps,
58
63
  ScreenTransitionConfig,
59
64
  TransitionAwareProps,
60
65
  } from "./screen.types";
@@ -1,3 +1,5 @@
1
+ import type { ComponentType, ReactNode } from "react";
2
+ import type { ViewProps } from "react-native";
1
3
  import type { AnimatedProps } from "react-native-reanimated";
2
4
  import type {
3
5
  ScreenStyleInterpolator,
@@ -51,6 +53,71 @@ export type SnapPoint = number | "auto";
51
53
 
52
54
  export type BackdropBehavior = "block" | "passthrough" | "dismiss" | "collapse";
53
55
 
56
+ /**
57
+ * Props passed to custom screen layer component renderers such as
58
+ * {@linkcode ScreenTransitionConfig.backdropComponent}.
59
+ */
60
+ export type ScreenLayerComponentProps = {
61
+ /**
62
+ * Animated styles for the target layer, including the library-owned base
63
+ * layout style for that layer.
64
+ */
65
+ styles: AnimatedProps<ViewProps>["style"];
66
+
67
+ /**
68
+ * Animated props resolved from the matching `screenStyleInterpolator` slot.
69
+ */
70
+ props: AnimatedProps<Record<string, unknown>>["animatedProps"];
71
+
72
+ /**
73
+ * Pointer-event behavior resolved for the current layer state.
74
+ */
75
+ pointerEvents: ViewProps["pointerEvents"];
76
+ };
77
+
78
+ /**
79
+ * Props passed to {@linkcode ScreenTransitionConfig.backdropComponent} when it
80
+ * is provided as a render-style component.
81
+ */
82
+ export type ScreenBackdropComponentProps = ScreenLayerComponentProps;
83
+
84
+ /**
85
+ * Props passed to {@linkcode ScreenTransitionConfig.contentComponent} when it
86
+ * is provided as a render-style component.
87
+ */
88
+ export type ScreenContentComponentProps = ScreenLayerComponentProps & {
89
+ /**
90
+ * The screen subtree rendered inside the content layer.
91
+ */
92
+ children: ReactNode;
93
+ };
94
+
95
+ /**
96
+ * Custom renderer for the backdrop layer.
97
+ *
98
+ * Component types such as `BlurView` are still accepted for compatibility.
99
+ * Function components can also receive {@linkcode ScreenBackdropComponentProps}
100
+ * to render the animated styles and props manually.
101
+ *
102
+ * @see {@linkcode ScreenTransitionConfig.backdropComponent}
103
+ */
104
+ export type ScreenBackdropComponent =
105
+ | ComponentType<any>
106
+ | ComponentType<ScreenBackdropComponentProps>;
107
+
108
+ /**
109
+ * Custom renderer for the screen content layer.
110
+ *
111
+ * Component types such as a custom native view are accepted directly. Function
112
+ * components can also receive {@linkcode ScreenContentComponentProps} to render
113
+ * the animated styles, props, pointer-events, and children manually.
114
+ *
115
+ * @see {@linkcode ScreenTransitionConfig.contentComponent}
116
+ */
117
+ export type ScreenContentComponent =
118
+ | ComponentType<any>
119
+ | ComponentType<ScreenContentComponentProps>;
120
+
54
121
  /**
55
122
  * Controls how an inactive screen is retained after it is no longer active.
56
123
  *
@@ -117,6 +184,8 @@ export type TransitionAwareProps<T extends object> = AnimatedProps<T> & {
117
184
  * <Transition.View sharedBoundTag="profile-avatar">
118
185
  * <Avatar size="large" />
119
186
  * </Transition.View>
187
+ *
188
+ * @deprecated Use `Transition.Boundary` with `id` instead.
120
189
  */
121
190
  sharedBoundTag?: string;
122
191
 
@@ -127,6 +196,8 @@ export type TransitionAwareProps<T extends object> = AnimatedProps<T> & {
127
196
  * Useful when layout can change while unfocused (for example, programmatic
128
197
  * ScrollView/FlatList scrolling triggered from another screen).
129
198
  *
199
+ * @deprecated Legacy `sharedBoundTag` refresh option. The boundary
200
+ * measurement pipeline refreshes layout through `Transition.Boundary`.
130
201
  * @default false
131
202
  */
132
203
  remeasureOnFocus?: boolean;
@@ -209,6 +280,8 @@ export type ScreenTransitionConfig = {
209
280
  /**
210
281
  * How much velocity affects snap point targeting. Lower values make snapping
211
282
  * feel more deliberate (iOS-like), higher values make it more responsive to flicks.
283
+ *
284
+ * @deprecated Use `gestureSnapVelocityImpact` instead.
212
285
  * @default 0.1
213
286
  */
214
287
  snapVelocityImpact?: number;
@@ -400,13 +473,21 @@ export type ScreenTransitionConfig = {
400
473
  /**
401
474
  * Custom component to render as the backdrop layer (between screens).
402
475
  *
403
- * The library wraps this component with `Animated.createAnimatedComponent` internally.
404
- * Animated styles and props are driven by the `backdrop` slot in the interpolator return value.
476
+ * Direct component types are wrapped with `Animated.createAnimatedComponent`
477
+ * internally. Function components can receive `{ styles, props, pointerEvents }`
478
+ * and decide how to render the layer. Animated styles and props are driven by
479
+ * the `backdrop` slot in the interpolator return value.
405
480
  *
406
481
  * `backdropBehavior` still controls the wrapping Pressable for dismiss/collapse handling.
407
482
  *
408
483
  * @example
409
- * backdropComponent: BlurView,
484
+ * backdropComponent: ({ styles, props, pointerEvents }) => (
485
+ * <AnimatedBlurView
486
+ * style={styles}
487
+ * animatedProps={props}
488
+ * pointerEvents={pointerEvents}
489
+ * />
490
+ * ),
410
491
  * screenStyleInterpolator: ({ progress }) => {
411
492
  * "worklet";
412
493
  * return {
@@ -419,7 +500,32 @@ export type ScreenTransitionConfig = {
419
500
  *
420
501
  * @default undefined
421
502
  */
422
- backdropComponent?: React.ComponentType<any>;
503
+ backdropComponent?: ScreenBackdropComponent;
504
+
505
+ /**
506
+ * Custom component to render as the screen's content layer.
507
+ *
508
+ * The component receives the `content` slot's animated styles and props. A
509
+ * direct component type is wrapped with `Animated.createAnimatedComponent`;
510
+ * a function component can receive `{ styles, props, pointerEvents, children }`
511
+ * and decide how to render the layer.
512
+ *
513
+ * `contentComponent` replaces `surfaceComponent` for custom screen shells.
514
+ *
515
+ * @example
516
+ * contentComponent: ({ styles, props, pointerEvents, children }) => (
517
+ * <AnimatedSquircleView
518
+ * style={styles}
519
+ * animatedProps={props}
520
+ * pointerEvents={pointerEvents}
521
+ * >
522
+ * {children}
523
+ * </AnimatedSquircleView>
524
+ * )
525
+ *
526
+ * @default undefined
527
+ */
528
+ contentComponent?: ScreenContentComponent;
423
529
 
424
530
  /**
425
531
  * Custom component to render as the screen's surface layer.
@@ -443,6 +549,7 @@ export type ScreenTransitionConfig = {
443
549
  * }
444
550
  *
445
551
  * @default undefined
552
+ * @deprecated Use `contentComponent` instead.
446
553
  */
447
554
  surfaceComponent?: React.ComponentType<any>;
448
555
  };
@@ -237,6 +237,8 @@ export type BoundsOptions = {
237
237
 
238
238
  /**
239
239
  * If true, the raw values will be returned instead of the computed values.
240
+ *
241
+ * @deprecated Use `bounds(id).math(options)` instead of passing `raw`.
240
242
  * @default false
241
243
  */
242
244
  raw?: boolean;