react-native-screen-transitions 2.0.6 → 2.1.0
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.
- package/LICENSE +21 -0
- package/README.md +100 -77
- package/lib/commonjs/components/{bounds-activator.js → bound-capture.js} +4 -4
- package/lib/commonjs/components/bound-capture.js.map +1 -0
- package/lib/commonjs/components/controllers/screen-lifecycle.js +18 -4
- package/lib/commonjs/components/controllers/screen-lifecycle.js.map +1 -1
- package/lib/commonjs/components/create-transition-aware-component.js +14 -12
- package/lib/commonjs/components/create-transition-aware-component.js.map +1 -1
- package/lib/commonjs/components/integrations/masked-view.js +52 -0
- package/lib/commonjs/components/integrations/masked-view.js.map +1 -0
- package/lib/commonjs/components/root-transition-aware.js +6 -15
- package/lib/commonjs/components/root-transition-aware.js.map +1 -1
- package/lib/commonjs/configs/index.js +4 -1
- package/lib/commonjs/configs/index.js.map +1 -1
- package/lib/commonjs/configs/presets.js +378 -7
- package/lib/commonjs/configs/presets.js.map +1 -1
- package/lib/commonjs/configs/specs.js +2 -1
- package/lib/commonjs/configs/specs.js.map +1 -1
- package/lib/commonjs/hooks/animation/use-associated-style.js +7 -10
- package/lib/commonjs/hooks/animation/use-associated-style.js.map +1 -1
- package/lib/commonjs/hooks/animation/use-screen-animation.js +37 -37
- package/lib/commonjs/hooks/animation/use-screen-animation.js.map +1 -1
- package/lib/commonjs/hooks/bounds/use-bound-registry.js +73 -0
- package/lib/commonjs/hooks/bounds/use-bound-registry.js.map +1 -0
- package/lib/commonjs/hooks/gestures/use-build-gestures.js +156 -152
- package/lib/commonjs/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/commonjs/hooks/gestures/use-parent-gesture-registry.js +28 -0
- package/lib/commonjs/hooks/gestures/use-parent-gesture-registry.js.map +1 -0
- package/lib/commonjs/hooks/gestures/use-scroll-registry.js +146 -0
- package/lib/commonjs/hooks/gestures/use-scroll-registry.js.map +1 -0
- package/lib/commonjs/index.js +3 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/integrations/native-stack/views/NativeStackView.native.js +7 -4
- package/lib/commonjs/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
- package/lib/commonjs/providers/gestures.js +16 -16
- package/lib/commonjs/providers/gestures.js.map +1 -1
- package/lib/commonjs/providers/transition-styles.js +44 -0
- package/lib/commonjs/providers/transition-styles.js.map +1 -0
- package/lib/commonjs/stores/bounds.js +142 -1
- package/lib/commonjs/stores/bounds.js.map +1 -1
- package/lib/commonjs/stores/utils/reset-stores-for-screen.js +4 -2
- package/lib/commonjs/stores/utils/reset-stores-for-screen.js.map +1 -1
- package/lib/commonjs/types/gesture.js +11 -0
- package/lib/commonjs/types/gesture.js.map +1 -1
- package/lib/commonjs/utils/animation/derivations.js +39 -0
- package/lib/commonjs/utils/animation/derivations.js.map +1 -0
- package/lib/commonjs/utils/animation/run-transition.js +6 -2
- package/lib/commonjs/utils/animation/run-transition.js.map +1 -1
- package/lib/commonjs/utils/bounds/_utils/flatten-styles.js.map +1 -0
- package/lib/commonjs/utils/bounds/_utils/geometry.js +179 -0
- package/lib/commonjs/utils/bounds/_utils/geometry.js.map +1 -0
- package/lib/commonjs/utils/bounds/{get-bounds.js → _utils/get-bounds.js} +7 -9
- package/lib/commonjs/utils/bounds/_utils/get-bounds.js.map +1 -0
- package/lib/commonjs/utils/bounds/_utils/is-bounds-equal.js +19 -0
- package/lib/commonjs/utils/bounds/_utils/is-bounds-equal.js.map +1 -0
- package/lib/commonjs/utils/bounds/_utils/style-composers.js +201 -0
- package/lib/commonjs/utils/bounds/_utils/style-composers.js.map +1 -0
- package/lib/commonjs/utils/bounds/constants.js +14 -3
- package/lib/commonjs/utils/bounds/constants.js.map +1 -1
- package/lib/commonjs/utils/bounds/index.js +210 -17
- package/lib/commonjs/utils/bounds/index.js.map +1 -1
- package/lib/commonjs/utils/gesture/apply-offset-rules.js +233 -0
- package/lib/commonjs/utils/gesture/apply-offset-rules.js.map +1 -0
- package/lib/commonjs/utils/gesture/check-gesture-activation.js +231 -0
- package/lib/commonjs/utils/gesture/check-gesture-activation.js.map +1 -0
- package/lib/commonjs/utils/gesture/determine-dismissal.js +98 -0
- package/lib/commonjs/utils/gesture/determine-dismissal.js.map +1 -0
- package/lib/module/components/{bounds-activator.js → bound-capture.js} +2 -2
- package/lib/module/components/bound-capture.js.map +1 -0
- package/lib/module/components/controllers/screen-lifecycle.js +18 -4
- package/lib/module/components/controllers/screen-lifecycle.js.map +1 -1
- package/lib/module/components/create-transition-aware-component.js +14 -12
- package/lib/module/components/create-transition-aware-component.js.map +1 -1
- package/lib/module/components/integrations/masked-view.js +48 -0
- package/lib/module/components/integrations/masked-view.js.map +1 -0
- package/lib/module/components/root-transition-aware.js +7 -16
- package/lib/module/components/root-transition-aware.js.map +1 -1
- package/lib/module/configs/index.js +6 -3
- package/lib/module/configs/index.js.map +1 -1
- package/lib/module/configs/presets.js +374 -6
- package/lib/module/configs/presets.js.map +1 -1
- package/lib/module/configs/specs.js +2 -1
- package/lib/module/configs/specs.js.map +1 -1
- package/lib/module/hooks/animation/use-associated-style.js +6 -10
- package/lib/module/hooks/animation/use-associated-style.js.map +1 -1
- package/lib/module/hooks/animation/use-screen-animation.js +37 -37
- package/lib/module/hooks/animation/use-screen-animation.js.map +1 -1
- package/lib/module/hooks/bounds/use-bound-registry.js +68 -0
- package/lib/module/hooks/bounds/use-bound-registry.js.map +1 -0
- package/lib/module/hooks/gestures/use-build-gestures.js +156 -153
- package/lib/module/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/module/hooks/gestures/use-parent-gesture-registry.js +23 -0
- package/lib/module/hooks/gestures/use-parent-gesture-registry.js.map +1 -0
- package/lib/module/hooks/gestures/use-scroll-registry.js +140 -0
- package/lib/module/hooks/gestures/use-scroll-registry.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/integrations/native-stack/views/NativeStackView.native.js +7 -4
- package/lib/module/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
- package/lib/module/providers/gestures.js +16 -16
- package/lib/module/providers/gestures.js.map +1 -1
- package/lib/module/providers/transition-styles.js +39 -0
- package/lib/module/providers/transition-styles.js.map +1 -0
- package/lib/module/stores/bounds.js +142 -1
- package/lib/module/stores/bounds.js.map +1 -1
- package/lib/module/stores/utils/reset-stores-for-screen.js +4 -2
- package/lib/module/stores/utils/reset-stores-for-screen.js.map +1 -1
- package/lib/module/types/gesture.js +7 -0
- package/lib/module/types/gesture.js.map +1 -1
- package/lib/module/utils/animation/derivations.js +34 -0
- package/lib/module/utils/animation/derivations.js.map +1 -0
- package/lib/module/utils/animation/run-transition.js +6 -2
- package/lib/module/utils/animation/run-transition.js.map +1 -1
- package/lib/module/utils/bounds/_utils/flatten-styles.js.map +1 -0
- package/lib/module/utils/bounds/_utils/geometry.js +174 -0
- package/lib/module/utils/bounds/_utils/geometry.js.map +1 -0
- package/lib/module/utils/bounds/{get-bounds.js → _utils/get-bounds.js} +7 -9
- package/lib/module/utils/bounds/_utils/get-bounds.js.map +1 -0
- package/lib/module/utils/bounds/_utils/is-bounds-equal.js +14 -0
- package/lib/module/utils/bounds/_utils/is-bounds-equal.js.map +1 -0
- package/lib/module/utils/bounds/_utils/style-composers.js +194 -0
- package/lib/module/utils/bounds/_utils/style-composers.js.map +1 -0
- package/lib/module/utils/bounds/constants.js +14 -3
- package/lib/module/utils/bounds/constants.js.map +1 -1
- package/lib/module/utils/bounds/index.js +208 -15
- package/lib/module/utils/bounds/index.js.map +1 -1
- package/lib/module/utils/gesture/apply-offset-rules.js +228 -0
- package/lib/module/utils/gesture/apply-offset-rules.js.map +1 -0
- package/lib/module/utils/gesture/check-gesture-activation.js +226 -0
- package/lib/module/utils/gesture/check-gesture-activation.js.map +1 -0
- package/lib/module/utils/gesture/determine-dismissal.js +93 -0
- package/lib/module/utils/gesture/determine-dismissal.js.map +1 -0
- package/lib/typescript/components/bound-capture.d.ts +8 -0
- package/lib/typescript/components/bound-capture.d.ts.map +1 -0
- package/lib/typescript/components/controllers/screen-lifecycle.d.ts.map +1 -1
- package/lib/typescript/components/create-transition-aware-component.d.ts.map +1 -1
- package/lib/typescript/components/integrations/masked-view.d.ts +6 -0
- package/lib/typescript/components/integrations/masked-view.d.ts.map +1 -0
- package/lib/typescript/components/root-transition-aware.d.ts +3 -3
- package/lib/typescript/components/root-transition-aware.d.ts.map +1 -1
- package/lib/typescript/configs/index.d.ts +3 -0
- package/lib/typescript/configs/index.d.ts.map +1 -1
- package/lib/typescript/configs/presets.d.ts +3 -0
- package/lib/typescript/configs/presets.d.ts.map +1 -1
- package/lib/typescript/configs/specs.d.ts.map +1 -1
- package/lib/typescript/hooks/animation/use-associated-style.d.ts +6 -4
- package/lib/typescript/hooks/animation/use-associated-style.d.ts.map +1 -1
- package/lib/typescript/hooks/animation/use-screen-animation.d.ts.map +1 -1
- package/lib/typescript/hooks/bounds/{use-bound-measurer.d.ts → use-bound-registry.d.ts} +5 -4
- package/lib/typescript/hooks/bounds/{use-bound-measurer.d.ts.map → use-bound-registry.d.ts.map} +1 -1
- package/lib/typescript/hooks/gestures/use-build-gestures.d.ts +6 -5
- package/lib/typescript/hooks/gestures/use-build-gestures.d.ts.map +1 -1
- package/lib/typescript/hooks/gestures/use-parent-gesture-registry.d.ts +6 -0
- package/lib/typescript/hooks/gestures/use-parent-gesture-registry.d.ts.map +1 -0
- package/lib/typescript/hooks/gestures/{use-scroll-progress.d.ts → use-scroll-registry.d.ts} +2 -2
- package/lib/typescript/hooks/gestures/use-scroll-registry.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +13 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/integrations/native-stack/views/NativeStackView.native.d.ts.map +1 -1
- package/lib/typescript/providers/gestures.d.ts +4 -2
- package/lib/typescript/providers/gestures.d.ts.map +1 -1
- package/lib/typescript/providers/transition-styles.d.ts +8 -0
- package/lib/typescript/providers/transition-styles.d.ts.map +1 -0
- package/lib/typescript/stores/bounds.d.ts +11 -0
- package/lib/typescript/stores/bounds.d.ts.map +1 -1
- package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts +3 -1
- package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts.map +1 -1
- package/lib/typescript/types/bounds.d.ts +5 -1
- package/lib/typescript/types/bounds.d.ts.map +1 -1
- package/lib/typescript/types/gesture.d.ts +14 -0
- package/lib/typescript/types/gesture.d.ts.map +1 -1
- package/lib/typescript/types/navigator.d.ts +5 -1
- package/lib/typescript/types/navigator.d.ts.map +1 -1
- package/lib/typescript/utils/animation/derivations.d.ts +19 -0
- package/lib/typescript/utils/animation/derivations.d.ts.map +1 -0
- package/lib/typescript/utils/animation/run-transition.d.ts +2 -1
- package/lib/typescript/utils/animation/run-transition.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/_types/builder.d.ts +96 -14
- package/lib/typescript/utils/bounds/_types/builder.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/_types/geometry.d.ts +0 -1
- package/lib/typescript/utils/bounds/_types/geometry.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/_utils/flatten-styles.d.ts.map +1 -0
- package/lib/typescript/utils/bounds/{geometry.d.ts → _utils/geometry.d.ts} +8 -5
- package/lib/typescript/utils/bounds/_utils/geometry.d.ts.map +1 -0
- package/lib/typescript/utils/bounds/_utils/get-bounds.d.ts +4 -0
- package/lib/typescript/utils/bounds/_utils/get-bounds.d.ts.map +1 -0
- package/lib/typescript/utils/bounds/_utils/is-bounds-equal.d.ts +7 -0
- package/lib/typescript/utils/bounds/_utils/is-bounds-equal.d.ts.map +1 -0
- package/lib/typescript/utils/bounds/{style-composers.d.ts → _utils/style-composers.d.ts} +7 -10
- package/lib/typescript/utils/bounds/_utils/style-composers.d.ts.map +1 -0
- package/lib/typescript/utils/bounds/constants.d.ts +5 -5
- package/lib/typescript/utils/bounds/constants.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/index.d.ts +2 -4
- package/lib/typescript/utils/bounds/index.d.ts.map +1 -1
- package/lib/typescript/utils/gesture/apply-offset-rules.d.ts +38 -0
- package/lib/typescript/utils/gesture/apply-offset-rules.d.ts.map +1 -0
- package/lib/typescript/utils/gesture/check-gesture-activation.d.ts +38 -0
- package/lib/typescript/utils/gesture/check-gesture-activation.d.ts.map +1 -0
- package/lib/typescript/utils/gesture/determine-dismissal.d.ts +25 -0
- package/lib/typescript/utils/gesture/determine-dismissal.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/geometry.test.ts +15 -12
- package/src/components/{bounds-activator.tsx → bound-capture.tsx} +1 -1
- package/src/components/controllers/screen-lifecycle.tsx +13 -5
- package/src/components/create-transition-aware-component.tsx +17 -11
- package/src/components/integrations/masked-view.tsx +56 -0
- package/src/components/root-transition-aware.tsx +31 -39
- package/src/configs/index.ts +20 -8
- package/src/configs/presets.ts +401 -6
- package/src/configs/specs.ts +1 -0
- package/src/hooks/animation/use-associated-style.tsx +12 -11
- package/src/hooks/animation/use-screen-animation.tsx +48 -49
- package/src/hooks/bounds/{use-bound-measurer.tsx → use-bound-registry.tsx} +32 -20
- package/src/hooks/gestures/use-build-gestures.tsx +193 -228
- package/src/hooks/gestures/use-parent-gesture-registry.tsx +18 -0
- package/src/hooks/gestures/use-scroll-registry.tsx +145 -0
- package/src/index.ts +2 -0
- package/src/integrations/native-stack/views/NativeStackView.native.tsx +8 -5
- package/src/providers/gestures.tsx +19 -22
- package/src/providers/transition-styles.tsx +52 -0
- package/src/stores/bounds.ts +156 -0
- package/src/stores/utils/reset-stores-for-screen.ts +7 -2
- package/src/types/bounds.ts +8 -1
- package/src/types/gesture.ts +19 -0
- package/src/types/navigator.ts +5 -1
- package/src/utils/animation/derivations.ts +38 -0
- package/src/utils/animation/run-transition.ts +4 -1
- package/src/utils/bounds/_types/builder.ts +127 -11
- package/src/utils/bounds/_types/geometry.ts +0 -1
- package/src/utils/bounds/_utils/geometry.ts +166 -0
- package/src/utils/bounds/_utils/get-bounds.ts +54 -0
- package/src/utils/bounds/_utils/is-bounds-equal.ts +24 -0
- package/src/utils/bounds/_utils/style-composers.ts +216 -0
- package/src/utils/bounds/constants.ts +37 -22
- package/src/utils/bounds/index.ts +269 -19
- package/src/utils/gesture/apply-offset-rules.ts +314 -0
- package/src/utils/gesture/check-gesture-activation.ts +310 -0
- package/src/utils/gesture/determine-dismissal.ts +131 -0
- package/lib/commonjs/components/bounds-activator.js.map +0 -1
- package/lib/commonjs/hooks/bounds/use-bound-measurer.js +0 -52
- package/lib/commonjs/hooks/bounds/use-bound-measurer.js.map +0 -1
- package/lib/commonjs/hooks/gestures/use-scroll-progress.js +0 -57
- package/lib/commonjs/hooks/gestures/use-scroll-progress.js.map +0 -1
- package/lib/commonjs/utils/bounds/build-bound-styles.js +0 -145
- package/lib/commonjs/utils/bounds/build-bound-styles.js.map +0 -1
- package/lib/commonjs/utils/bounds/flatten-styles.js.map +0 -1
- package/lib/commonjs/utils/bounds/geometry.js +0 -94
- package/lib/commonjs/utils/bounds/geometry.js.map +0 -1
- package/lib/commonjs/utils/bounds/get-bounds.js.map +0 -1
- package/lib/commonjs/utils/bounds/style-composers.js +0 -199
- package/lib/commonjs/utils/bounds/style-composers.js.map +0 -1
- package/lib/commonjs/utils/gesture/apply-gesture-activation-criteria.js +0 -81
- package/lib/commonjs/utils/gesture/apply-gesture-activation-criteria.js.map +0 -1
- package/lib/commonjs/utils/gesture/normalize-gesture-translation.js +0 -21
- package/lib/commonjs/utils/gesture/normalize-gesture-translation.js.map +0 -1
- package/lib/module/components/bounds-activator.js.map +0 -1
- package/lib/module/hooks/bounds/use-bound-measurer.js +0 -47
- package/lib/module/hooks/bounds/use-bound-measurer.js.map +0 -1
- package/lib/module/hooks/gestures/use-scroll-progress.js +0 -52
- package/lib/module/hooks/gestures/use-scroll-progress.js.map +0 -1
- package/lib/module/utils/bounds/build-bound-styles.js +0 -141
- package/lib/module/utils/bounds/build-bound-styles.js.map +0 -1
- package/lib/module/utils/bounds/flatten-styles.js.map +0 -1
- package/lib/module/utils/bounds/geometry.js +0 -89
- package/lib/module/utils/bounds/geometry.js.map +0 -1
- package/lib/module/utils/bounds/get-bounds.js.map +0 -1
- package/lib/module/utils/bounds/style-composers.js +0 -191
- package/lib/module/utils/bounds/style-composers.js.map +0 -1
- package/lib/module/utils/gesture/apply-gesture-activation-criteria.js +0 -76
- package/lib/module/utils/gesture/apply-gesture-activation-criteria.js.map +0 -1
- package/lib/module/utils/gesture/normalize-gesture-translation.js +0 -16
- package/lib/module/utils/gesture/normalize-gesture-translation.js.map +0 -1
- package/lib/typescript/components/bounds-activator.d.ts +0 -8
- package/lib/typescript/components/bounds-activator.d.ts.map +0 -1
- package/lib/typescript/hooks/gestures/use-scroll-progress.d.ts.map +0 -1
- package/lib/typescript/utils/bounds/build-bound-styles.d.ts +0 -4
- package/lib/typescript/utils/bounds/build-bound-styles.d.ts.map +0 -1
- package/lib/typescript/utils/bounds/flatten-styles.d.ts.map +0 -1
- package/lib/typescript/utils/bounds/geometry.d.ts.map +0 -1
- package/lib/typescript/utils/bounds/get-bounds.d.ts +0 -4
- package/lib/typescript/utils/bounds/get-bounds.d.ts.map +0 -1
- package/lib/typescript/utils/bounds/style-composers.d.ts.map +0 -1
- package/lib/typescript/utils/gesture/apply-gesture-activation-criteria.d.ts +0 -17
- package/lib/typescript/utils/gesture/apply-gesture-activation-criteria.d.ts.map +0 -1
- package/lib/typescript/utils/gesture/normalize-gesture-translation.d.ts +0 -6
- package/lib/typescript/utils/gesture/normalize-gesture-translation.d.ts.map +0 -1
- package/src/hooks/gestures/use-scroll-progress.tsx +0 -60
- package/src/utils/bounds/build-bound-styles.ts +0 -184
- package/src/utils/bounds/geometry.ts +0 -113
- package/src/utils/bounds/get-bounds.ts +0 -56
- package/src/utils/bounds/style-composers.ts +0 -172
- package/src/utils/gesture/apply-gesture-activation-criteria.ts +0 -109
- package/src/utils/gesture/normalize-gesture-translation.ts +0 -20
- /package/lib/commonjs/utils/bounds/{flatten-styles.js → _utils/flatten-styles.js} +0 -0
- /package/lib/module/utils/bounds/{flatten-styles.js → _utils/flatten-styles.js} +0 -0
- /package/lib/typescript/utils/bounds/{flatten-styles.d.ts → _utils/flatten-styles.d.ts} +0 -0
- /package/src/utils/bounds/{flatten-styles.ts → _utils/flatten-styles.ts} +0 -0
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import type { ScaledSize } from "react-native";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MeasuredDimensions } from "react-native-reanimated";
|
|
3
3
|
import type { ScreenTransitionState } from "../../types/animation";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { BoundsAccessor, BoundsBuilder } from "../../types/bounds";
|
|
5
|
+
import type { ScreenPhase } from "../../types/core";
|
|
6
|
+
import type {
|
|
7
|
+
BoundsBuilderInitParams,
|
|
8
|
+
BoundsBuilderOptions,
|
|
9
|
+
} from "./_types/builder";
|
|
10
|
+
import {
|
|
11
|
+
computeContentTransformGeometry,
|
|
12
|
+
computeRelativeGeometry,
|
|
13
|
+
} from "./_utils/geometry";
|
|
14
|
+
import { getBounds } from "./_utils/get-bounds";
|
|
15
|
+
import {
|
|
16
|
+
composeContentStyle,
|
|
17
|
+
composeSizeAbsolute,
|
|
18
|
+
composeSizeRelative,
|
|
19
|
+
composeTransformAbsolute,
|
|
20
|
+
composeTransformRelative,
|
|
21
|
+
type ElementComposeParams,
|
|
22
|
+
} from "./_utils/style-composers";
|
|
23
|
+
import { DEFAULT_BUILDER_OPTIONS, FULLSCREEN_DIMENSIONS } from "./constants";
|
|
6
24
|
|
|
7
25
|
export interface BuildBoundsAccessorParams {
|
|
8
26
|
activeBoundId: string | null;
|
|
@@ -13,34 +31,266 @@ export interface BuildBoundsAccessorParams {
|
|
|
13
31
|
dimensions: ScaledSize;
|
|
14
32
|
}
|
|
15
33
|
|
|
16
|
-
|
|
34
|
+
const EMPTY_STYLE = Object.freeze({});
|
|
35
|
+
const EMPTY_STYLE_RAW = Object.freeze({
|
|
36
|
+
scaleX: 1,
|
|
37
|
+
scaleY: 1,
|
|
38
|
+
scale: 1,
|
|
39
|
+
translateX: 0,
|
|
40
|
+
translateY: 0,
|
|
41
|
+
width: 0,
|
|
42
|
+
height: 0,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const ENTER_RANGE = [0, 1] as const;
|
|
46
|
+
const EXIT_RANGE = [1, 2] as const;
|
|
47
|
+
|
|
48
|
+
const resolveBounds = (props: {
|
|
49
|
+
id: string;
|
|
50
|
+
previous?: ScreenTransitionState;
|
|
51
|
+
current?: ScreenTransitionState;
|
|
52
|
+
next?: ScreenTransitionState;
|
|
53
|
+
toRect?: Partial<MeasuredDimensions>;
|
|
54
|
+
dimensions: ScaledSize;
|
|
55
|
+
computeOptions: BoundsBuilderOptions;
|
|
56
|
+
}) => {
|
|
57
|
+
"worklet";
|
|
58
|
+
const entering = !props.next;
|
|
59
|
+
|
|
60
|
+
const fullscreen = FULLSCREEN_DIMENSIONS(props.dimensions);
|
|
61
|
+
|
|
62
|
+
const startPhase: ScreenPhase = entering ? "previous" : "current";
|
|
63
|
+
const endPhase: ScreenPhase = entering ? "current" : "next";
|
|
64
|
+
|
|
65
|
+
const getPhaseBounds = (phase?: ScreenPhase) => {
|
|
66
|
+
"worklet";
|
|
67
|
+
switch (phase) {
|
|
68
|
+
case "previous":
|
|
69
|
+
return props.previous?.bounds?.[props.id]?.bounds;
|
|
70
|
+
case "current":
|
|
71
|
+
return props.current?.bounds?.[props.id]?.bounds;
|
|
72
|
+
case "next":
|
|
73
|
+
return props.next?.bounds?.[props.id]?.bounds;
|
|
74
|
+
default:
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const start = getPhaseBounds(startPhase);
|
|
80
|
+
let end = getPhaseBounds(endPhase);
|
|
81
|
+
|
|
82
|
+
const isFullscreen =
|
|
83
|
+
props.computeOptions.target === "fullscreen" ||
|
|
84
|
+
props.computeOptions.toFullscreen;
|
|
85
|
+
|
|
86
|
+
if (isFullscreen) {
|
|
87
|
+
end = fullscreen;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const customTarget = props.computeOptions.target;
|
|
91
|
+
|
|
92
|
+
if (typeof customTarget === "object") {
|
|
93
|
+
end = customTarget;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
start,
|
|
98
|
+
end,
|
|
99
|
+
entering,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const computeBoundStyles = (
|
|
104
|
+
{
|
|
105
|
+
id,
|
|
106
|
+
previous,
|
|
107
|
+
current,
|
|
108
|
+
next,
|
|
109
|
+
progress,
|
|
110
|
+
dimensions,
|
|
111
|
+
}: BoundsBuilderInitParams,
|
|
112
|
+
computeOptions: BoundsBuilderOptions = {},
|
|
113
|
+
) => {
|
|
114
|
+
"worklet";
|
|
115
|
+
if (!id) {
|
|
116
|
+
if (computeOptions.raw) {
|
|
117
|
+
return EMPTY_STYLE_RAW;
|
|
118
|
+
}
|
|
119
|
+
return EMPTY_STYLE;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const { start, end, entering } = resolveBounds({
|
|
123
|
+
id,
|
|
124
|
+
previous,
|
|
125
|
+
current,
|
|
126
|
+
next,
|
|
127
|
+
computeOptions,
|
|
128
|
+
dimensions,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (!start || !end) {
|
|
132
|
+
if (computeOptions.raw) {
|
|
133
|
+
return EMPTY_STYLE_RAW;
|
|
134
|
+
}
|
|
135
|
+
return EMPTY_STYLE;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const ranges: readonly [number, number] = entering ? ENTER_RANGE : EXIT_RANGE;
|
|
139
|
+
|
|
140
|
+
if (computeOptions.method === "content") {
|
|
141
|
+
const geometry = computeContentTransformGeometry({
|
|
142
|
+
start,
|
|
143
|
+
end,
|
|
144
|
+
entering,
|
|
145
|
+
dimensions,
|
|
146
|
+
anchor: computeOptions.anchor,
|
|
147
|
+
scaleMode: computeOptions.scaleMode,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return composeContentStyle({
|
|
151
|
+
start,
|
|
152
|
+
progress,
|
|
153
|
+
ranges,
|
|
154
|
+
end,
|
|
155
|
+
geometry,
|
|
156
|
+
computeOptions,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const geometry = computeRelativeGeometry({
|
|
161
|
+
start,
|
|
162
|
+
end,
|
|
163
|
+
entering,
|
|
164
|
+
anchor: computeOptions.anchor,
|
|
165
|
+
scaleMode: computeOptions.scaleMode,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const common: ElementComposeParams = {
|
|
169
|
+
start,
|
|
170
|
+
end,
|
|
171
|
+
progress,
|
|
172
|
+
ranges,
|
|
173
|
+
geometry,
|
|
174
|
+
computeOptions,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const isSize = computeOptions.method === "size";
|
|
178
|
+
const isAbs =
|
|
179
|
+
computeOptions.space === "absolute" || !!computeOptions.absolute;
|
|
180
|
+
|
|
181
|
+
return isSize
|
|
182
|
+
? isAbs
|
|
183
|
+
? composeSizeAbsolute(common)
|
|
184
|
+
: composeSizeRelative(common)
|
|
185
|
+
: isAbs
|
|
186
|
+
? composeTransformAbsolute(common)
|
|
187
|
+
: composeTransformRelative(common);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @deprecated Use `createBounds` instead. We'll avoid using the builder pattern for this type of function.
|
|
192
|
+
*/
|
|
193
|
+
const buildBoundStyles = (params: BoundsBuilderInitParams): BoundsBuilder => {
|
|
194
|
+
"worklet";
|
|
195
|
+
|
|
196
|
+
const cfg: { options: BoundsBuilderOptions } = {
|
|
197
|
+
options: { ...DEFAULT_BUILDER_OPTIONS },
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const builder = (): BoundsBuilder => ({
|
|
201
|
+
gestures: (options) => {
|
|
202
|
+
cfg.options.gestures = options;
|
|
203
|
+
return builder();
|
|
204
|
+
},
|
|
205
|
+
toFullscreen: () => {
|
|
206
|
+
cfg.options.toFullscreen = true;
|
|
207
|
+
return builder();
|
|
208
|
+
},
|
|
209
|
+
absolute: () => {
|
|
210
|
+
cfg.options.absolute = true;
|
|
211
|
+
cfg.options.relative = false;
|
|
212
|
+
return builder();
|
|
213
|
+
},
|
|
214
|
+
relative: () => {
|
|
215
|
+
cfg.options.relative = true;
|
|
216
|
+
cfg.options.absolute = false;
|
|
217
|
+
return builder();
|
|
218
|
+
},
|
|
219
|
+
transform: () => {
|
|
220
|
+
cfg.options.method = "transform";
|
|
221
|
+
return builder();
|
|
222
|
+
},
|
|
223
|
+
size: () => {
|
|
224
|
+
cfg.options.method = "size";
|
|
225
|
+
return builder();
|
|
226
|
+
},
|
|
227
|
+
content: () => {
|
|
228
|
+
cfg.options.method = "content";
|
|
229
|
+
return builder();
|
|
230
|
+
},
|
|
231
|
+
contentFill: () => {
|
|
232
|
+
cfg.options.contentScaleMode = "aspectFill";
|
|
233
|
+
return builder();
|
|
234
|
+
},
|
|
235
|
+
contentFit: () => {
|
|
236
|
+
cfg.options.contentScaleMode = "aspectFit";
|
|
237
|
+
return builder();
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
build: () => {
|
|
241
|
+
return computeBoundStyles(params, cfg.options);
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return builder();
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export const createBounds = ({
|
|
17
249
|
activeBoundId,
|
|
18
250
|
current,
|
|
19
251
|
previous,
|
|
20
252
|
next,
|
|
21
253
|
progress,
|
|
22
254
|
dimensions,
|
|
23
|
-
}: BuildBoundsAccessorParams) => {
|
|
255
|
+
}: BuildBoundsAccessorParams): BoundsAccessor => {
|
|
24
256
|
"worklet";
|
|
25
257
|
|
|
26
|
-
const bounds = (
|
|
27
|
-
|
|
28
|
-
id
|
|
29
|
-
|
|
258
|
+
const bounds: BoundsAccessor = ((params?: string | BoundsBuilderOptions) => {
|
|
259
|
+
if (typeof params === "object") {
|
|
260
|
+
const id = params.id ?? activeBoundId;
|
|
261
|
+
|
|
262
|
+
return computeBoundStyles(
|
|
263
|
+
{
|
|
264
|
+
id,
|
|
265
|
+
current,
|
|
266
|
+
previous,
|
|
267
|
+
next,
|
|
268
|
+
progress,
|
|
269
|
+
dimensions,
|
|
270
|
+
},
|
|
271
|
+
params,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const id = typeof params === "string" ? params : activeBoundId;
|
|
276
|
+
return buildBoundStyles({
|
|
277
|
+
id,
|
|
30
278
|
current,
|
|
279
|
+
previous,
|
|
31
280
|
next,
|
|
32
281
|
progress,
|
|
33
282
|
dimensions,
|
|
34
283
|
});
|
|
284
|
+
}) as BoundsAccessor;
|
|
35
285
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
286
|
+
bounds.get = (id?: string, phase?: ScreenPhase) =>
|
|
287
|
+
getBounds({
|
|
288
|
+
id: id ?? activeBoundId,
|
|
289
|
+
phase,
|
|
290
|
+
current,
|
|
291
|
+
previous,
|
|
292
|
+
next,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
return bounds;
|
|
46
296
|
};
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import type { ScaledSize } from "react-native";
|
|
2
|
+
import type { GestureStateManagerType } from "react-native-gesture-handler/lib/typescript/handlers/gestures/gestureStateManager";
|
|
3
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
4
|
+
import {
|
|
5
|
+
type ActivationArea,
|
|
6
|
+
type GestureActivationArea,
|
|
7
|
+
GestureOffsetState,
|
|
8
|
+
type SideActivation,
|
|
9
|
+
} from "../../types/gesture";
|
|
10
|
+
|
|
11
|
+
type Directions = {
|
|
12
|
+
vertical: boolean;
|
|
13
|
+
verticalInverted: boolean;
|
|
14
|
+
horizontal: boolean;
|
|
15
|
+
horizontalInverted: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface CheckGestureActivationProps {
|
|
19
|
+
initialTouch: { x: number; y: number };
|
|
20
|
+
touch: { x: number; y: number };
|
|
21
|
+
directions: Directions;
|
|
22
|
+
manager?: GestureStateManagerType;
|
|
23
|
+
gestureOffsetState: SharedValue<GestureOffsetState>;
|
|
24
|
+
activationArea?: GestureActivationArea;
|
|
25
|
+
dimensions: ScaledSize;
|
|
26
|
+
responseDistance?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type NormalizedSides = {
|
|
30
|
+
left: ActivationArea;
|
|
31
|
+
right: ActivationArea;
|
|
32
|
+
top: ActivationArea;
|
|
33
|
+
bottom: ActivationArea;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
interface ShouldActivateOrFailProps {
|
|
37
|
+
deltaX: number;
|
|
38
|
+
deltaY: number;
|
|
39
|
+
hasHorizontal: boolean;
|
|
40
|
+
hasVertical: boolean;
|
|
41
|
+
isHorizontalSwipe: boolean;
|
|
42
|
+
isVerticalSwipe: boolean;
|
|
43
|
+
allowedRight: boolean;
|
|
44
|
+
allowedLeft: boolean;
|
|
45
|
+
allowedUp: boolean;
|
|
46
|
+
allowedDown: boolean;
|
|
47
|
+
horizontalGateRight: boolean;
|
|
48
|
+
horizontalGateLeft: boolean;
|
|
49
|
+
verticalGateUp: boolean;
|
|
50
|
+
verticalGateDown: boolean;
|
|
51
|
+
isSwipingRight: boolean;
|
|
52
|
+
isSwipingLeft: boolean;
|
|
53
|
+
isSwipingUp: boolean;
|
|
54
|
+
isSwipingDown: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ReturnValues {
|
|
58
|
+
isSwipingDown: boolean;
|
|
59
|
+
isSwipingUp: boolean;
|
|
60
|
+
isSwipingRight: boolean;
|
|
61
|
+
isSwipingLeft: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 10 seems like the correct threshold for compatability with nested gestures outside of our package.
|
|
66
|
+
*/
|
|
67
|
+
const GESTURE_ACTIVATION_THRESHOLD_X = 10;
|
|
68
|
+
const GESTURE_ACTIVATION_THRESHOLD_Y = 10;
|
|
69
|
+
const GESTURE_FAIL_TOLERANCE_X = 15;
|
|
70
|
+
const GESTURE_FAIL_TOLERANCE_Y = 20;
|
|
71
|
+
const DEFAULT_EDGE_DISTANCE_HORIZONTAL = 50;
|
|
72
|
+
const DEFAULT_EDGE_DISTANCE_VERTICAL = 135;
|
|
73
|
+
const DEFAULT_ACTIVATION_AREA = "screen" as const;
|
|
74
|
+
|
|
75
|
+
function normalizeSides(area?: GestureActivationArea): NormalizedSides {
|
|
76
|
+
"worklet";
|
|
77
|
+
if (!area || typeof area === "string") {
|
|
78
|
+
const mode: ActivationArea = area ?? DEFAULT_ACTIVATION_AREA;
|
|
79
|
+
return { left: mode, right: mode, top: mode, bottom: mode };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const s: SideActivation = area as SideActivation;
|
|
83
|
+
return {
|
|
84
|
+
left: s.left ?? DEFAULT_ACTIVATION_AREA,
|
|
85
|
+
right: s.right ?? DEFAULT_ACTIVATION_AREA,
|
|
86
|
+
top: s.top ?? DEFAULT_ACTIVATION_AREA,
|
|
87
|
+
bottom: s.bottom ?? DEFAULT_ACTIVATION_AREA,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function computeEdgeConstraints(
|
|
92
|
+
initialTouch: { x: number; y: number },
|
|
93
|
+
dimensions: ScaledSize,
|
|
94
|
+
sides: NormalizedSides,
|
|
95
|
+
responseDistance?: number,
|
|
96
|
+
) {
|
|
97
|
+
"worklet";
|
|
98
|
+
const xDist = responseDistance ?? DEFAULT_EDGE_DISTANCE_HORIZONTAL;
|
|
99
|
+
const yDist = responseDistance ?? DEFAULT_EDGE_DISTANCE_VERTICAL;
|
|
100
|
+
|
|
101
|
+
const horizontalRight = sides.left === "screen" || initialTouch.x <= xDist; // right swipe checks left edge
|
|
102
|
+
const horizontalLeft =
|
|
103
|
+
sides.right === "screen" || initialTouch.x >= dimensions.width - xDist; // left swipe checks right edge
|
|
104
|
+
const verticalDown = sides.top === "screen" || initialTouch.y <= yDist; // down swipe checks top edge
|
|
105
|
+
const verticalUp =
|
|
106
|
+
sides.bottom === "screen" || initialTouch.y >= dimensions.height - yDist; // up swipe checks bottom edge
|
|
107
|
+
|
|
108
|
+
return { horizontalRight, horizontalLeft, verticalDown, verticalUp } as const;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function calculateSwipeDirs(deltaX: number, deltaY: number) {
|
|
112
|
+
"worklet";
|
|
113
|
+
|
|
114
|
+
const isVerticalSwipe = Math.abs(deltaY) > Math.abs(deltaX);
|
|
115
|
+
const isHorizontalSwipe = Math.abs(deltaX) > Math.abs(deltaY);
|
|
116
|
+
|
|
117
|
+
const isSwipingDown = isVerticalSwipe && deltaY > 0;
|
|
118
|
+
const isSwipingUp = isVerticalSwipe && deltaY < 0;
|
|
119
|
+
const isSwipingRight = isHorizontalSwipe && deltaX > 0;
|
|
120
|
+
const isSwipingLeft = isHorizontalSwipe && deltaX < 0;
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
isSwipingDown,
|
|
124
|
+
isSwipingUp,
|
|
125
|
+
isSwipingRight,
|
|
126
|
+
isSwipingLeft,
|
|
127
|
+
isVerticalSwipe,
|
|
128
|
+
isHorizontalSwipe,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function shouldActivateOrFail(params: ShouldActivateOrFailProps) {
|
|
133
|
+
"worklet";
|
|
134
|
+
|
|
135
|
+
const {
|
|
136
|
+
deltaX,
|
|
137
|
+
deltaY,
|
|
138
|
+
hasHorizontal,
|
|
139
|
+
hasVertical,
|
|
140
|
+
isHorizontalSwipe,
|
|
141
|
+
isVerticalSwipe,
|
|
142
|
+
allowedRight,
|
|
143
|
+
allowedLeft,
|
|
144
|
+
allowedUp,
|
|
145
|
+
allowedDown,
|
|
146
|
+
horizontalGateRight,
|
|
147
|
+
horizontalGateLeft,
|
|
148
|
+
verticalGateUp,
|
|
149
|
+
verticalGateDown,
|
|
150
|
+
isSwipingRight,
|
|
151
|
+
isSwipingLeft,
|
|
152
|
+
isSwipingUp,
|
|
153
|
+
isSwipingDown,
|
|
154
|
+
} = params;
|
|
155
|
+
|
|
156
|
+
let shouldActivate = false;
|
|
157
|
+
let shouldFail = false;
|
|
158
|
+
|
|
159
|
+
if (hasHorizontal && isHorizontalSwipe) {
|
|
160
|
+
const hasEnoughHorizontalMovement =
|
|
161
|
+
Math.abs(deltaX) >= GESTURE_ACTIVATION_THRESHOLD_X;
|
|
162
|
+
|
|
163
|
+
const hasAcceptableVerticalDeviation =
|
|
164
|
+
Math.abs(deltaY) <= GESTURE_FAIL_TOLERANCE_X;
|
|
165
|
+
|
|
166
|
+
if (hasEnoughHorizontalMovement && hasAcceptableVerticalDeviation) {
|
|
167
|
+
const rightOk = isSwipingRight && allowedRight && horizontalGateRight;
|
|
168
|
+
const leftOk = isSwipingLeft && allowedLeft && horizontalGateLeft;
|
|
169
|
+
if (rightOk || leftOk) {
|
|
170
|
+
shouldActivate = true;
|
|
171
|
+
}
|
|
172
|
+
} else if (!hasAcceptableVerticalDeviation) {
|
|
173
|
+
shouldFail = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (hasVertical && isVerticalSwipe) {
|
|
178
|
+
const hasEnoughVerticalMovement =
|
|
179
|
+
Math.abs(deltaY) >= GESTURE_ACTIVATION_THRESHOLD_Y;
|
|
180
|
+
const hasAcceptableHorizontalDeviation =
|
|
181
|
+
Math.abs(deltaX) <= GESTURE_FAIL_TOLERANCE_Y;
|
|
182
|
+
|
|
183
|
+
if (hasEnoughVerticalMovement && hasAcceptableHorizontalDeviation) {
|
|
184
|
+
const upOk = isSwipingUp && allowedUp && verticalGateUp;
|
|
185
|
+
const downOk = isSwipingDown && allowedDown && verticalGateDown;
|
|
186
|
+
if (upOk || downOk) {
|
|
187
|
+
shouldActivate = true;
|
|
188
|
+
}
|
|
189
|
+
} else if (!hasAcceptableHorizontalDeviation) {
|
|
190
|
+
shouldFail = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (hasHorizontal && isHorizontalSwipe) {
|
|
195
|
+
if ((isSwipingLeft && !allowedLeft) || (isSwipingRight && !allowedRight)) {
|
|
196
|
+
shouldFail = true;
|
|
197
|
+
}
|
|
198
|
+
// If gating prohibits the dominant horizontal swipe, fail early
|
|
199
|
+
if (
|
|
200
|
+
(isSwipingRight && allowedRight && !horizontalGateRight) ||
|
|
201
|
+
(isSwipingLeft && allowedLeft && !horizontalGateLeft)
|
|
202
|
+
) {
|
|
203
|
+
shouldFail = true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (hasVertical && isVerticalSwipe) {
|
|
208
|
+
if ((isSwipingUp && !allowedUp) || (isSwipingDown && !allowedDown)) {
|
|
209
|
+
shouldFail = true;
|
|
210
|
+
}
|
|
211
|
+
// If gating prohibits the dominant vertical swipe, fail early
|
|
212
|
+
if (
|
|
213
|
+
(isSwipingUp && allowedUp && !verticalGateUp) ||
|
|
214
|
+
(isSwipingDown && allowedDown && !verticalGateDown)
|
|
215
|
+
) {
|
|
216
|
+
shouldFail = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return { shouldActivate, shouldFail };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Since we're using onTouchesMove to activate our pan, faillOffset and activateOffset don't actually work. In that case we'll create this function to use in onTouchesMove which acts simarly to the original functionality.
|
|
225
|
+
*/
|
|
226
|
+
export const applyOffsetRules = ({
|
|
227
|
+
initialTouch,
|
|
228
|
+
touch,
|
|
229
|
+
directions,
|
|
230
|
+
manager,
|
|
231
|
+
gestureOffsetState,
|
|
232
|
+
activationArea,
|
|
233
|
+
dimensions,
|
|
234
|
+
responseDistance,
|
|
235
|
+
}: CheckGestureActivationProps): ReturnValues => {
|
|
236
|
+
"worklet";
|
|
237
|
+
|
|
238
|
+
const deltaX = touch.x - initialTouch.x;
|
|
239
|
+
const deltaY = touch.y - initialTouch.y;
|
|
240
|
+
|
|
241
|
+
const allowedDown = directions.vertical;
|
|
242
|
+
const allowedUp = directions.verticalInverted;
|
|
243
|
+
const allowedRight = directions.horizontal;
|
|
244
|
+
const allowedLeft = directions.horizontalInverted;
|
|
245
|
+
|
|
246
|
+
const hasHorizontal = allowedLeft || allowedRight;
|
|
247
|
+
const hasVertical = allowedUp || allowedDown;
|
|
248
|
+
|
|
249
|
+
const {
|
|
250
|
+
isSwipingDown,
|
|
251
|
+
isSwipingUp,
|
|
252
|
+
isSwipingRight,
|
|
253
|
+
isSwipingLeft,
|
|
254
|
+
isVerticalSwipe,
|
|
255
|
+
isHorizontalSwipe,
|
|
256
|
+
} = calculateSwipeDirs(deltaX, deltaY);
|
|
257
|
+
|
|
258
|
+
// avoid re-running the function if the activation state is already set
|
|
259
|
+
if (
|
|
260
|
+
gestureOffsetState.value === GestureOffsetState.PASSED ||
|
|
261
|
+
gestureOffsetState.value === GestureOffsetState.FAILED
|
|
262
|
+
) {
|
|
263
|
+
return {
|
|
264
|
+
isSwipingDown,
|
|
265
|
+
isSwipingUp,
|
|
266
|
+
isSwipingRight,
|
|
267
|
+
isSwipingLeft,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const sides = normalizeSides(activationArea);
|
|
272
|
+
|
|
273
|
+
const {
|
|
274
|
+
horizontalRight: horizontalGateRight,
|
|
275
|
+
horizontalLeft: horizontalGateLeft,
|
|
276
|
+
verticalDown: verticalGateDown,
|
|
277
|
+
verticalUp: verticalGateUp,
|
|
278
|
+
} = computeEdgeConstraints(initialTouch, dimensions, sides, responseDistance);
|
|
279
|
+
|
|
280
|
+
const { shouldActivate, shouldFail } = shouldActivateOrFail({
|
|
281
|
+
deltaX,
|
|
282
|
+
deltaY,
|
|
283
|
+
hasHorizontal,
|
|
284
|
+
hasVertical,
|
|
285
|
+
isHorizontalSwipe,
|
|
286
|
+
isVerticalSwipe,
|
|
287
|
+
allowedRight,
|
|
288
|
+
allowedLeft,
|
|
289
|
+
allowedUp,
|
|
290
|
+
allowedDown,
|
|
291
|
+
horizontalGateRight,
|
|
292
|
+
horizontalGateLeft,
|
|
293
|
+
verticalGateUp,
|
|
294
|
+
verticalGateDown,
|
|
295
|
+
isSwipingRight,
|
|
296
|
+
isSwipingLeft,
|
|
297
|
+
isSwipingUp,
|
|
298
|
+
isSwipingDown,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (shouldActivate) {
|
|
302
|
+
gestureOffsetState.value = GestureOffsetState.PASSED;
|
|
303
|
+
} else if (shouldFail) {
|
|
304
|
+
gestureOffsetState.value = GestureOffsetState.FAILED;
|
|
305
|
+
manager?.fail();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
isSwipingDown,
|
|
310
|
+
isSwipingUp,
|
|
311
|
+
isSwipingRight,
|
|
312
|
+
isSwipingLeft,
|
|
313
|
+
};
|
|
314
|
+
};
|