react-native-screen-transitions 3.2.0 → 3.3.0-beta.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/README.md +1 -1
- package/lib/commonjs/shared/components/create-transition-aware-component.js +8 -2
- package/lib/commonjs/shared/components/create-transition-aware-component.js.map +1 -1
- package/lib/commonjs/shared/components/{root-transition-aware.js → screen-container.js} +28 -12
- package/lib/commonjs/shared/components/screen-container.js.map +1 -0
- package/lib/commonjs/shared/configs/presets.js +3 -3
- package/lib/commonjs/shared/configs/presets.js.map +1 -1
- package/lib/commonjs/shared/configs/specs.js +6 -1
- package/lib/commonjs/shared/configs/specs.js.map +1 -1
- package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js +36 -188
- package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js +334 -0
- package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -0
- package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js +47 -4
- package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
- package/lib/commonjs/shared/hooks/lifecycle/use-close-transition.js +3 -3
- package/lib/commonjs/shared/hooks/lifecycle/use-close-transition.js.map +1 -1
- package/lib/commonjs/shared/hooks/lifecycle/use-open-transition.js +25 -3
- package/lib/commonjs/shared/hooks/lifecycle/use-open-transition.js.map +1 -1
- package/lib/commonjs/shared/hooks/navigation/use-screen-state.js +61 -2
- package/lib/commonjs/shared/hooks/navigation/use-screen-state.js.map +1 -1
- package/lib/commonjs/shared/hooks/use-backdrop-pointer-events.js +32 -0
- package/lib/commonjs/shared/hooks/use-backdrop-pointer-events.js.map +1 -0
- package/lib/commonjs/shared/providers/gestures.provider.js +4 -2
- package/lib/commonjs/shared/providers/gestures.provider.js.map +1 -1
- package/lib/commonjs/shared/providers/screen/screen-composer.js +2 -2
- package/lib/commonjs/shared/providers/screen/screen-composer.js.map +1 -1
- package/lib/commonjs/shared/providers/screen/styles.provider.js +41 -32
- package/lib/commonjs/shared/providers/screen/styles.provider.js.map +1 -1
- package/lib/commonjs/shared/utils/animation/{start-screen-transition.js → animate-to-progress.js} +11 -7
- package/lib/commonjs/shared/utils/animation/animate-to-progress.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js +71 -0
- package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js.map +1 -1
- package/lib/commonjs/shared/utils/gesture/determine-snap-target.js +56 -0
- package/lib/commonjs/shared/utils/gesture/determine-snap-target.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/validate-snap-points.js +31 -0
- package/lib/commonjs/shared/utils/gesture/validate-snap-points.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/velocity.js +11 -0
- package/lib/commonjs/shared/utils/gesture/velocity.js.map +1 -1
- package/lib/module/shared/components/create-transition-aware-component.js +8 -2
- package/lib/module/shared/components/create-transition-aware-component.js.map +1 -1
- package/lib/module/shared/components/screen-container.js +64 -0
- package/lib/module/shared/components/screen-container.js.map +1 -0
- package/lib/module/shared/configs/presets.js +3 -3
- package/lib/module/shared/configs/presets.js.map +1 -1
- package/lib/module/shared/configs/specs.js +5 -0
- package/lib/module/shared/configs/specs.js.map +1 -1
- package/lib/module/shared/hooks/gestures/use-build-gestures.js +36 -187
- package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js +328 -0
- package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -0
- package/lib/module/shared/hooks/gestures/use-scroll-registry.js +47 -4
- package/lib/module/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
- package/lib/module/shared/hooks/lifecycle/use-close-transition.js +3 -3
- package/lib/module/shared/hooks/lifecycle/use-close-transition.js.map +1 -1
- package/lib/module/shared/hooks/lifecycle/use-open-transition.js +25 -3
- package/lib/module/shared/hooks/lifecycle/use-open-transition.js.map +1 -1
- package/lib/module/shared/hooks/navigation/use-screen-state.js +63 -4
- package/lib/module/shared/hooks/navigation/use-screen-state.js.map +1 -1
- package/lib/module/shared/hooks/use-backdrop-pointer-events.js +28 -0
- package/lib/module/shared/hooks/use-backdrop-pointer-events.js.map +1 -0
- package/lib/module/shared/providers/gestures.provider.js +4 -2
- package/lib/module/shared/providers/gestures.provider.js.map +1 -1
- package/lib/module/shared/providers/screen/screen-composer.js +2 -2
- package/lib/module/shared/providers/screen/screen-composer.js.map +1 -1
- package/lib/module/shared/providers/screen/styles.provider.js +41 -32
- package/lib/module/shared/providers/screen/styles.provider.js.map +1 -1
- package/lib/module/shared/utils/animation/{start-screen-transition.js → animate-to-progress.js} +9 -5
- package/lib/module/shared/utils/animation/animate-to-progress.js.map +1 -0
- package/lib/module/shared/utils/gesture/check-gesture-activation.js +70 -0
- package/lib/module/shared/utils/gesture/check-gesture-activation.js.map +1 -1
- package/lib/module/shared/utils/gesture/determine-snap-target.js +52 -0
- package/lib/module/shared/utils/gesture/determine-snap-target.js.map +1 -0
- package/lib/module/shared/utils/gesture/validate-snap-points.js +26 -0
- package/lib/module/shared/utils/gesture/validate-snap-points.js.map +1 -0
- package/lib/module/shared/utils/gesture/velocity.js +11 -0
- package/lib/module/shared/utils/gesture/velocity.js.map +1 -1
- package/lib/typescript/shared/components/create-transition-aware-component.d.ts.map +1 -1
- package/lib/typescript/shared/components/screen-container.d.ts +6 -0
- package/lib/typescript/shared/components/screen-container.d.ts.map +1 -0
- package/lib/typescript/shared/configs/specs.d.ts +1 -0
- package/lib/typescript/shared/configs/specs.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts +1 -1
- package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts +34 -0
- package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts.map +1 -0
- package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts +5 -1
- package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/lifecycle/use-open-transition.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/navigation/use-screen-state.d.ts +14 -0
- package/lib/typescript/shared/hooks/navigation/use-screen-state.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts +15 -0
- package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts.map +1 -0
- package/lib/typescript/shared/providers/gestures.provider.d.ts +1 -0
- package/lib/typescript/shared/providers/gestures.provider.d.ts.map +1 -1
- package/lib/typescript/shared/providers/screen/styles.provider.d.ts.map +1 -1
- package/lib/typescript/shared/types/animation.types.d.ts +28 -2
- package/lib/typescript/shared/types/animation.types.d.ts.map +1 -1
- package/lib/typescript/shared/types/screen.types.d.ts +26 -0
- package/lib/typescript/shared/types/screen.types.d.ts.map +1 -1
- package/lib/typescript/shared/utils/animation/animate-to-progress.d.ts +19 -0
- package/lib/typescript/shared/utils/animation/animate-to-progress.d.ts.map +1 -0
- package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts +24 -0
- package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts.map +1 -1
- package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts +26 -0
- package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts.map +1 -0
- package/lib/typescript/shared/utils/gesture/validate-snap-points.d.ts +13 -0
- package/lib/typescript/shared/utils/gesture/validate-snap-points.d.ts.map +1 -0
- package/lib/typescript/shared/utils/gesture/velocity.d.ts +1 -0
- package/lib/typescript/shared/utils/gesture/velocity.d.ts.map +1 -1
- package/package.json +29 -2
- package/src/shared/__tests__/determine-snap-target.test.ts +268 -0
- package/src/shared/__tests__/gesture-activation.test.ts +247 -0
- package/src/shared/__tests__/validate-snap-points.test.ts +125 -0
- package/src/shared/components/create-transition-aware-component.tsx +11 -1
- package/src/shared/components/screen-container.tsx +65 -0
- package/src/shared/configs/presets.ts +3 -3
- package/src/shared/configs/specs.ts +6 -0
- package/src/shared/hooks/gestures/use-build-gestures.tsx +33 -253
- package/src/shared/hooks/gestures/use-screen-gesture-handlers.ts +436 -0
- package/src/shared/hooks/gestures/use-scroll-registry.tsx +52 -1
- package/src/shared/hooks/lifecycle/use-close-transition.ts +3 -3
- package/src/shared/hooks/lifecycle/use-open-transition.ts +27 -3
- package/src/shared/hooks/navigation/use-screen-state.tsx +106 -2
- package/src/shared/hooks/use-backdrop-pointer-events.ts +32 -0
- package/src/shared/providers/gestures.provider.tsx +3 -2
- package/src/shared/providers/screen/screen-composer.tsx +2 -2
- package/src/shared/providers/screen/styles.provider.tsx +40 -34
- package/src/shared/types/animation.types.ts +29 -2
- package/src/shared/types/screen.types.ts +29 -0
- package/src/shared/utils/animation/{start-screen-transition.ts → animate-to-progress.ts} +19 -7
- package/src/shared/utils/gesture/check-gesture-activation.ts +78 -0
- package/src/shared/utils/gesture/determine-snap-target.ts +75 -0
- package/src/shared/utils/gesture/validate-snap-points.ts +37 -0
- package/src/shared/utils/gesture/velocity.ts +10 -0
- package/lib/commonjs/shared/components/root-transition-aware.js.map +0 -1
- package/lib/commonjs/shared/hooks/use-stack-pointer-events.js +0 -23
- package/lib/commonjs/shared/hooks/use-stack-pointer-events.js.map +0 -1
- package/lib/commonjs/shared/utils/animation/start-screen-transition.js.map +0 -1
- package/lib/module/shared/components/root-transition-aware.js +0 -48
- package/lib/module/shared/components/root-transition-aware.js.map +0 -1
- package/lib/module/shared/hooks/use-stack-pointer-events.js +0 -20
- package/lib/module/shared/hooks/use-stack-pointer-events.js.map +0 -1
- package/lib/module/shared/utils/animation/start-screen-transition.js.map +0 -1
- package/lib/typescript/shared/components/root-transition-aware.d.ts +0 -6
- package/lib/typescript/shared/components/root-transition-aware.d.ts.map +0 -1
- package/lib/typescript/shared/hooks/use-stack-pointer-events.d.ts +0 -10
- package/lib/typescript/shared/hooks/use-stack-pointer-events.d.ts.map +0 -1
- package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts +0 -13
- package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts.map +0 -1
- package/src/shared/components/root-transition-aware.tsx +0 -49
- package/src/shared/hooks/use-stack-pointer-events.ts +0 -15
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { determineSnapTarget } from "../utils/gesture/determine-snap-target";
|
|
3
|
+
|
|
4
|
+
describe("determineSnapTarget", () => {
|
|
5
|
+
const dimension = 800; // screen height
|
|
6
|
+
const snapPoints = [0.3, 0.6, 1]; // 3 snap points
|
|
7
|
+
|
|
8
|
+
describe("basic snapping without velocity", () => {
|
|
9
|
+
it("snaps to nearest snap point when exactly at a snap point", () => {
|
|
10
|
+
const result = determineSnapTarget({
|
|
11
|
+
currentProgress: 0.6,
|
|
12
|
+
snapPoints,
|
|
13
|
+
velocity: 0,
|
|
14
|
+
dimension,
|
|
15
|
+
});
|
|
16
|
+
expect(result.targetProgress).toBe(0.6);
|
|
17
|
+
expect(result.shouldDismiss).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("snaps to lower snap point when below midpoint", () => {
|
|
21
|
+
// Midpoint between 0.3 and 0.6 is 0.45
|
|
22
|
+
const result = determineSnapTarget({
|
|
23
|
+
currentProgress: 0.4,
|
|
24
|
+
snapPoints,
|
|
25
|
+
velocity: 0,
|
|
26
|
+
dimension,
|
|
27
|
+
});
|
|
28
|
+
expect(result.targetProgress).toBe(0.3);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("snaps to higher snap point when above midpoint", () => {
|
|
32
|
+
// Midpoint between 0.3 and 0.6 is 0.45
|
|
33
|
+
const result = determineSnapTarget({
|
|
34
|
+
currentProgress: 0.5,
|
|
35
|
+
snapPoints,
|
|
36
|
+
velocity: 0,
|
|
37
|
+
dimension,
|
|
38
|
+
});
|
|
39
|
+
expect(result.targetProgress).toBe(0.6);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("snaps to highest point when above all snap points", () => {
|
|
43
|
+
const result = determineSnapTarget({
|
|
44
|
+
currentProgress: 1.2,
|
|
45
|
+
snapPoints,
|
|
46
|
+
velocity: 0,
|
|
47
|
+
dimension,
|
|
48
|
+
});
|
|
49
|
+
expect(result.targetProgress).toBe(1);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("velocity influence", () => {
|
|
54
|
+
it("velocity toward dismiss pushes toward lower snap point", () => {
|
|
55
|
+
// At 0.5 (above midpoint 0.45), normally would snap to 0.6
|
|
56
|
+
// But positive velocity (toward dismiss) should push toward 0.3
|
|
57
|
+
const result = determineSnapTarget({
|
|
58
|
+
currentProgress: 0.5,
|
|
59
|
+
snapPoints,
|
|
60
|
+
velocity: 800, // Strong velocity toward dismiss
|
|
61
|
+
dimension,
|
|
62
|
+
velocityFactor: 0.15,
|
|
63
|
+
});
|
|
64
|
+
expect(result.targetProgress).toBe(0.3);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("velocity toward expand pushes toward higher snap point", () => {
|
|
68
|
+
// At 0.4 (below midpoint 0.45), normally would snap to 0.3
|
|
69
|
+
// But negative velocity (toward expand) should push toward 0.6
|
|
70
|
+
const result = determineSnapTarget({
|
|
71
|
+
currentProgress: 0.4,
|
|
72
|
+
snapPoints,
|
|
73
|
+
velocity: -800, // Strong velocity toward expand
|
|
74
|
+
dimension,
|
|
75
|
+
velocityFactor: 0.15,
|
|
76
|
+
});
|
|
77
|
+
expect(result.targetProgress).toBe(0.6);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("weak velocity does not override position", () => {
|
|
81
|
+
// At 0.55 (above midpoint), weak velocity shouldn't change target
|
|
82
|
+
const result = determineSnapTarget({
|
|
83
|
+
currentProgress: 0.55,
|
|
84
|
+
snapPoints,
|
|
85
|
+
velocity: 100, // Weak velocity
|
|
86
|
+
dimension,
|
|
87
|
+
velocityFactor: 0.15,
|
|
88
|
+
});
|
|
89
|
+
expect(result.targetProgress).toBe(0.6);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("respects custom velocityFactor", () => {
|
|
93
|
+
// Higher velocityFactor = velocity has more influence
|
|
94
|
+
const result = determineSnapTarget({
|
|
95
|
+
currentProgress: 0.5,
|
|
96
|
+
snapPoints,
|
|
97
|
+
velocity: 400,
|
|
98
|
+
dimension,
|
|
99
|
+
velocityFactor: 0.5, // High factor
|
|
100
|
+
});
|
|
101
|
+
expect(result.targetProgress).toBe(0.3);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("dismiss behavior", () => {
|
|
106
|
+
it("allows dismiss when canDismiss is true and near 0", () => {
|
|
107
|
+
const result = determineSnapTarget({
|
|
108
|
+
currentProgress: 0.1,
|
|
109
|
+
snapPoints,
|
|
110
|
+
velocity: 500,
|
|
111
|
+
dimension,
|
|
112
|
+
canDismiss: true,
|
|
113
|
+
});
|
|
114
|
+
expect(result.targetProgress).toBe(0);
|
|
115
|
+
expect(result.shouldDismiss).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("prevents dismiss when canDismiss is false", () => {
|
|
119
|
+
const result = determineSnapTarget({
|
|
120
|
+
currentProgress: 0.1,
|
|
121
|
+
snapPoints,
|
|
122
|
+
velocity: 1000, // Strong dismiss velocity
|
|
123
|
+
dimension,
|
|
124
|
+
canDismiss: false,
|
|
125
|
+
});
|
|
126
|
+
expect(result.targetProgress).toBe(0.3); // First snap point
|
|
127
|
+
expect(result.shouldDismiss).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("defaults canDismiss to true", () => {
|
|
131
|
+
const result = determineSnapTarget({
|
|
132
|
+
currentProgress: 0.1,
|
|
133
|
+
snapPoints,
|
|
134
|
+
velocity: 500,
|
|
135
|
+
dimension,
|
|
136
|
+
});
|
|
137
|
+
expect(result.shouldDismiss).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("shouldDismiss is false when snapping to any snap point", () => {
|
|
141
|
+
const result = determineSnapTarget({
|
|
142
|
+
currentProgress: 0.5,
|
|
143
|
+
snapPoints,
|
|
144
|
+
velocity: 0,
|
|
145
|
+
dimension,
|
|
146
|
+
});
|
|
147
|
+
expect(result.shouldDismiss).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("edge cases", () => {
|
|
152
|
+
it("handles single snap point", () => {
|
|
153
|
+
const result = determineSnapTarget({
|
|
154
|
+
currentProgress: 0.3,
|
|
155
|
+
snapPoints: [0.5],
|
|
156
|
+
velocity: 0,
|
|
157
|
+
dimension,
|
|
158
|
+
});
|
|
159
|
+
expect(result.targetProgress).toBe(0.5);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("handles unsorted snap points", () => {
|
|
163
|
+
const result = determineSnapTarget({
|
|
164
|
+
currentProgress: 0.5,
|
|
165
|
+
snapPoints: [1, 0.3, 0.6], // Unsorted
|
|
166
|
+
velocity: 0,
|
|
167
|
+
dimension,
|
|
168
|
+
});
|
|
169
|
+
// After sorting: [0.3, 0.6, 1], midpoint 0.3-0.6 is 0.45
|
|
170
|
+
expect(result.targetProgress).toBe(0.6);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("handles progress at exactly 0", () => {
|
|
174
|
+
const result = determineSnapTarget({
|
|
175
|
+
currentProgress: 0,
|
|
176
|
+
snapPoints,
|
|
177
|
+
velocity: 0,
|
|
178
|
+
dimension,
|
|
179
|
+
canDismiss: true,
|
|
180
|
+
});
|
|
181
|
+
expect(result.targetProgress).toBe(0);
|
|
182
|
+
expect(result.shouldDismiss).toBe(true);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("handles negative progress", () => {
|
|
186
|
+
const result = determineSnapTarget({
|
|
187
|
+
currentProgress: -0.1,
|
|
188
|
+
snapPoints,
|
|
189
|
+
velocity: 0,
|
|
190
|
+
dimension,
|
|
191
|
+
canDismiss: true,
|
|
192
|
+
});
|
|
193
|
+
expect(result.targetProgress).toBe(0);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("handles very high velocity", () => {
|
|
197
|
+
const result = determineSnapTarget({
|
|
198
|
+
currentProgress: 0.9,
|
|
199
|
+
snapPoints,
|
|
200
|
+
velocity: 5000, // Very high velocity
|
|
201
|
+
dimension,
|
|
202
|
+
canDismiss: true,
|
|
203
|
+
});
|
|
204
|
+
expect(result.targetProgress).toBe(0);
|
|
205
|
+
expect(result.shouldDismiss).toBe(true);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("handles snap points not starting at typical values", () => {
|
|
209
|
+
const result = determineSnapTarget({
|
|
210
|
+
currentProgress: 0.7,
|
|
211
|
+
snapPoints: [0.5, 0.75, 1],
|
|
212
|
+
velocity: 0,
|
|
213
|
+
dimension,
|
|
214
|
+
});
|
|
215
|
+
// Midpoint between 0.5 and 0.75 is 0.625
|
|
216
|
+
// 0.7 is above 0.625, so should snap to 0.75
|
|
217
|
+
expect(result.targetProgress).toBe(0.75);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("handles two snap points", () => {
|
|
221
|
+
const result = determineSnapTarget({
|
|
222
|
+
currentProgress: 0.4,
|
|
223
|
+
snapPoints: [0.3, 1],
|
|
224
|
+
velocity: 0,
|
|
225
|
+
dimension,
|
|
226
|
+
});
|
|
227
|
+
// Midpoint is 0.65, 0.4 is below, so snap to 0.3
|
|
228
|
+
expect(result.targetProgress).toBe(0.3);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe("zone boundaries", () => {
|
|
233
|
+
it("snaps to higher at exact midpoint (uses < not <=)", () => {
|
|
234
|
+
// Midpoint between 0 and 0.3 is 0.15
|
|
235
|
+
// The algorithm uses `<` so at exact midpoint, it snaps to higher
|
|
236
|
+
const result = determineSnapTarget({
|
|
237
|
+
currentProgress: 0.15,
|
|
238
|
+
snapPoints,
|
|
239
|
+
velocity: 0,
|
|
240
|
+
dimension,
|
|
241
|
+
canDismiss: true,
|
|
242
|
+
});
|
|
243
|
+
expect(result.targetProgress).toBe(0.3);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("snaps to lower just below midpoint", () => {
|
|
247
|
+
const result = determineSnapTarget({
|
|
248
|
+
currentProgress: 0.149,
|
|
249
|
+
snapPoints,
|
|
250
|
+
velocity: 0,
|
|
251
|
+
dimension,
|
|
252
|
+
canDismiss: true,
|
|
253
|
+
});
|
|
254
|
+
expect(result.targetProgress).toBe(0);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("snaps to higher just above midpoint", () => {
|
|
258
|
+
const result = determineSnapTarget({
|
|
259
|
+
currentProgress: 0.151,
|
|
260
|
+
snapPoints,
|
|
261
|
+
velocity: 0,
|
|
262
|
+
dimension,
|
|
263
|
+
canDismiss: true,
|
|
264
|
+
});
|
|
265
|
+
expect(result.targetProgress).toBe(0.3);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
computeEdgeConstraints,
|
|
5
5
|
calculateSwipeDirs,
|
|
6
6
|
shouldActivateOrFail,
|
|
7
|
+
checkScrollAwareActivation,
|
|
7
8
|
} from "../utils/gesture/check-gesture-activation";
|
|
8
9
|
|
|
9
10
|
describe("normalizeSides", () => {
|
|
@@ -249,3 +250,249 @@ describe("shouldActivateOrFail", () => {
|
|
|
249
250
|
expect(result.shouldActivate).toBe(true);
|
|
250
251
|
});
|
|
251
252
|
});
|
|
253
|
+
|
|
254
|
+
describe("checkScrollAwareActivation", () => {
|
|
255
|
+
const baseDirections = {
|
|
256
|
+
vertical: true,
|
|
257
|
+
verticalInverted: false,
|
|
258
|
+
horizontal: false,
|
|
259
|
+
horizontalInverted: false,
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const noSwipe = {
|
|
263
|
+
isSwipingDown: false,
|
|
264
|
+
isSwipingUp: false,
|
|
265
|
+
isSwipingRight: false,
|
|
266
|
+
isSwipingLeft: false,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
describe("vertical sheet (dismiss down)", () => {
|
|
270
|
+
it("activates when swiping down at scroll top", () => {
|
|
271
|
+
const result = checkScrollAwareActivation({
|
|
272
|
+
swipeInfo: { ...noSwipe, isSwipingDown: true },
|
|
273
|
+
directions: baseDirections,
|
|
274
|
+
scrollX: 0,
|
|
275
|
+
scrollY: 0,
|
|
276
|
+
maxScrollX: 0,
|
|
277
|
+
maxScrollY: 500,
|
|
278
|
+
});
|
|
279
|
+
expect(result.shouldActivate).toBe(true);
|
|
280
|
+
expect(result.direction).toBe("vertical");
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("does not activate when swiping down but scroll is not at top", () => {
|
|
284
|
+
const result = checkScrollAwareActivation({
|
|
285
|
+
swipeInfo: { ...noSwipe, isSwipingDown: true },
|
|
286
|
+
directions: baseDirections,
|
|
287
|
+
scrollX: 0,
|
|
288
|
+
scrollY: 100,
|
|
289
|
+
maxScrollX: 0,
|
|
290
|
+
maxScrollY: 500,
|
|
291
|
+
});
|
|
292
|
+
expect(result.shouldActivate).toBe(false);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("does not activate when swiping up without snap points", () => {
|
|
296
|
+
const result = checkScrollAwareActivation({
|
|
297
|
+
swipeInfo: { ...noSwipe, isSwipingUp: true },
|
|
298
|
+
directions: baseDirections,
|
|
299
|
+
scrollX: 0,
|
|
300
|
+
scrollY: 0,
|
|
301
|
+
maxScrollX: 0,
|
|
302
|
+
maxScrollY: 500,
|
|
303
|
+
});
|
|
304
|
+
expect(result.shouldActivate).toBe(false);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe("vertical inverted sheet (dismiss up)", () => {
|
|
309
|
+
const invertedDirections = {
|
|
310
|
+
vertical: false,
|
|
311
|
+
verticalInverted: true,
|
|
312
|
+
horizontal: false,
|
|
313
|
+
horizontalInverted: false,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
it("activates when swiping up at scroll bottom", () => {
|
|
317
|
+
const result = checkScrollAwareActivation({
|
|
318
|
+
swipeInfo: { ...noSwipe, isSwipingUp: true },
|
|
319
|
+
directions: invertedDirections,
|
|
320
|
+
scrollX: 0,
|
|
321
|
+
scrollY: 500,
|
|
322
|
+
maxScrollX: 0,
|
|
323
|
+
maxScrollY: 500,
|
|
324
|
+
});
|
|
325
|
+
expect(result.shouldActivate).toBe(true);
|
|
326
|
+
expect(result.direction).toBe("vertical-inverted");
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("does not activate when swiping up but scroll is not at bottom", () => {
|
|
330
|
+
const result = checkScrollAwareActivation({
|
|
331
|
+
swipeInfo: { ...noSwipe, isSwipingUp: true },
|
|
332
|
+
directions: invertedDirections,
|
|
333
|
+
scrollX: 0,
|
|
334
|
+
scrollY: 200,
|
|
335
|
+
maxScrollX: 0,
|
|
336
|
+
maxScrollY: 500,
|
|
337
|
+
});
|
|
338
|
+
expect(result.shouldActivate).toBe(false);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe("horizontal sheet (dismiss right)", () => {
|
|
343
|
+
const horizontalDirections = {
|
|
344
|
+
vertical: false,
|
|
345
|
+
verticalInverted: false,
|
|
346
|
+
horizontal: true,
|
|
347
|
+
horizontalInverted: false,
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
it("activates when swiping right at scroll left edge", () => {
|
|
351
|
+
const result = checkScrollAwareActivation({
|
|
352
|
+
swipeInfo: { ...noSwipe, isSwipingRight: true },
|
|
353
|
+
directions: horizontalDirections,
|
|
354
|
+
scrollX: 0,
|
|
355
|
+
scrollY: 0,
|
|
356
|
+
maxScrollX: 500,
|
|
357
|
+
maxScrollY: 0,
|
|
358
|
+
});
|
|
359
|
+
expect(result.shouldActivate).toBe(true);
|
|
360
|
+
expect(result.direction).toBe("horizontal");
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("does not activate when scroll is not at left edge", () => {
|
|
364
|
+
const result = checkScrollAwareActivation({
|
|
365
|
+
swipeInfo: { ...noSwipe, isSwipingRight: true },
|
|
366
|
+
directions: horizontalDirections,
|
|
367
|
+
scrollX: 100,
|
|
368
|
+
scrollY: 0,
|
|
369
|
+
maxScrollX: 500,
|
|
370
|
+
maxScrollY: 0,
|
|
371
|
+
});
|
|
372
|
+
expect(result.shouldActivate).toBe(false);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe("horizontal inverted sheet (dismiss left)", () => {
|
|
377
|
+
const invertedHorizontalDirections = {
|
|
378
|
+
vertical: false,
|
|
379
|
+
verticalInverted: false,
|
|
380
|
+
horizontal: false,
|
|
381
|
+
horizontalInverted: true,
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
it("activates when swiping left at scroll right edge", () => {
|
|
385
|
+
const result = checkScrollAwareActivation({
|
|
386
|
+
swipeInfo: { ...noSwipe, isSwipingLeft: true },
|
|
387
|
+
directions: invertedHorizontalDirections,
|
|
388
|
+
scrollX: 500,
|
|
389
|
+
scrollY: 0,
|
|
390
|
+
maxScrollX: 500,
|
|
391
|
+
maxScrollY: 0,
|
|
392
|
+
});
|
|
393
|
+
expect(result.shouldActivate).toBe(true);
|
|
394
|
+
expect(result.direction).toBe("horizontal-inverted");
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
describe("snap points behavior", () => {
|
|
399
|
+
it("activates for swipe up (expand) at scroll top when hasSnapPoints and canExpandMore", () => {
|
|
400
|
+
const result = checkScrollAwareActivation({
|
|
401
|
+
swipeInfo: { ...noSwipe, isSwipingUp: true },
|
|
402
|
+
directions: baseDirections,
|
|
403
|
+
scrollX: 0,
|
|
404
|
+
scrollY: 0,
|
|
405
|
+
maxScrollX: 0,
|
|
406
|
+
maxScrollY: 500,
|
|
407
|
+
hasSnapPoints: true,
|
|
408
|
+
canExpandMore: true,
|
|
409
|
+
});
|
|
410
|
+
expect(result.shouldActivate).toBe(true);
|
|
411
|
+
expect(result.direction).toBe("vertical-inverted");
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("does not activate for swipe up when canExpandMore is false", () => {
|
|
415
|
+
const result = checkScrollAwareActivation({
|
|
416
|
+
swipeInfo: { ...noSwipe, isSwipingUp: true },
|
|
417
|
+
directions: baseDirections,
|
|
418
|
+
scrollX: 0,
|
|
419
|
+
scrollY: 0,
|
|
420
|
+
maxScrollX: 0,
|
|
421
|
+
maxScrollY: 500,
|
|
422
|
+
hasSnapPoints: true,
|
|
423
|
+
canExpandMore: false,
|
|
424
|
+
});
|
|
425
|
+
expect(result.shouldActivate).toBe(false);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("does not activate for swipe up when scroll is not at top", () => {
|
|
429
|
+
const result = checkScrollAwareActivation({
|
|
430
|
+
swipeInfo: { ...noSwipe, isSwipingUp: true },
|
|
431
|
+
directions: baseDirections,
|
|
432
|
+
scrollX: 0,
|
|
433
|
+
scrollY: 100,
|
|
434
|
+
maxScrollX: 0,
|
|
435
|
+
maxScrollY: 500,
|
|
436
|
+
hasSnapPoints: true,
|
|
437
|
+
canExpandMore: true,
|
|
438
|
+
});
|
|
439
|
+
expect(result.shouldActivate).toBe(false);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("activates for swipe left (expand) on horizontal sheet with snap points", () => {
|
|
443
|
+
const horizontalDirections = {
|
|
444
|
+
vertical: false,
|
|
445
|
+
verticalInverted: false,
|
|
446
|
+
horizontal: true,
|
|
447
|
+
horizontalInverted: false,
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const result = checkScrollAwareActivation({
|
|
451
|
+
swipeInfo: { ...noSwipe, isSwipingLeft: true },
|
|
452
|
+
directions: horizontalDirections,
|
|
453
|
+
scrollX: 0,
|
|
454
|
+
scrollY: 0,
|
|
455
|
+
maxScrollX: 500,
|
|
456
|
+
maxScrollY: 0,
|
|
457
|
+
hasSnapPoints: true,
|
|
458
|
+
canExpandMore: true,
|
|
459
|
+
});
|
|
460
|
+
expect(result.shouldActivate).toBe(true);
|
|
461
|
+
expect(result.direction).toBe("horizontal-inverted");
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
describe("no activation cases", () => {
|
|
466
|
+
it("returns false when no swipe is detected", () => {
|
|
467
|
+
const result = checkScrollAwareActivation({
|
|
468
|
+
swipeInfo: noSwipe,
|
|
469
|
+
directions: baseDirections,
|
|
470
|
+
scrollX: 0,
|
|
471
|
+
scrollY: 0,
|
|
472
|
+
maxScrollX: 0,
|
|
473
|
+
maxScrollY: 500,
|
|
474
|
+
});
|
|
475
|
+
expect(result.shouldActivate).toBe(false);
|
|
476
|
+
expect(result.direction).toBe(null);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it("returns false when direction is disabled", () => {
|
|
480
|
+
const disabledDirections = {
|
|
481
|
+
vertical: false,
|
|
482
|
+
verticalInverted: false,
|
|
483
|
+
horizontal: false,
|
|
484
|
+
horizontalInverted: false,
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const result = checkScrollAwareActivation({
|
|
488
|
+
swipeInfo: { ...noSwipe, isSwipingDown: true },
|
|
489
|
+
directions: disabledDirections,
|
|
490
|
+
scrollX: 0,
|
|
491
|
+
scrollY: 0,
|
|
492
|
+
maxScrollX: 0,
|
|
493
|
+
maxScrollY: 500,
|
|
494
|
+
});
|
|
495
|
+
expect(result.shouldActivate).toBe(false);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { validateSnapPoints } from "../utils/gesture/validate-snap-points";
|
|
3
|
+
|
|
4
|
+
describe("validateSnapPoints", () => {
|
|
5
|
+
describe("when no snap points provided", () => {
|
|
6
|
+
it("returns hasSnapPoints false", () => {
|
|
7
|
+
const result = validateSnapPoints({});
|
|
8
|
+
expect(result.hasSnapPoints).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("returns empty snapPoints array", () => {
|
|
12
|
+
const result = validateSnapPoints({});
|
|
13
|
+
expect(result.snapPoints).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("returns -1 for min and max", () => {
|
|
17
|
+
const result = validateSnapPoints({});
|
|
18
|
+
expect(result.minSnapPoint).toBe(-1);
|
|
19
|
+
expect(result.maxSnapPoint).toBe(-1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("handles undefined snapPoints", () => {
|
|
23
|
+
const result = validateSnapPoints({ snapPoints: undefined });
|
|
24
|
+
expect(result.hasSnapPoints).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("when snap points provided", () => {
|
|
29
|
+
it("returns hasSnapPoints true", () => {
|
|
30
|
+
const result = validateSnapPoints({ snapPoints: [0.3, 0.6, 1] });
|
|
31
|
+
expect(result.hasSnapPoints).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("sorts snap points in ascending order", () => {
|
|
35
|
+
const result = validateSnapPoints({ snapPoints: [1, 0.3, 0.6] });
|
|
36
|
+
expect(result.snapPoints).toEqual([0.3, 0.6, 1]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns correct max snap point", () => {
|
|
40
|
+
const result = validateSnapPoints({ snapPoints: [0.3, 0.6, 1] });
|
|
41
|
+
expect(result.maxSnapPoint).toBe(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("handles single snap point", () => {
|
|
45
|
+
const result = validateSnapPoints({ snapPoints: [0.5] });
|
|
46
|
+
expect(result.hasSnapPoints).toBe(true);
|
|
47
|
+
expect(result.snapPoints).toEqual([0.5]);
|
|
48
|
+
expect(result.minSnapPoint).toBe(0.5);
|
|
49
|
+
expect(result.maxSnapPoint).toBe(0.5);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("does not mutate original array", () => {
|
|
53
|
+
const original = [1, 0.3, 0.6];
|
|
54
|
+
validateSnapPoints({ snapPoints: original });
|
|
55
|
+
expect(original).toEqual([1, 0.3, 0.6]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("canDismiss behavior", () => {
|
|
60
|
+
it("sets minSnapPoint to 0 when canDismiss is true", () => {
|
|
61
|
+
const result = validateSnapPoints({
|
|
62
|
+
snapPoints: [0.3, 0.6, 1],
|
|
63
|
+
canDismiss: true,
|
|
64
|
+
});
|
|
65
|
+
expect(result.minSnapPoint).toBe(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("sets minSnapPoint to first snap point when canDismiss is false", () => {
|
|
69
|
+
const result = validateSnapPoints({
|
|
70
|
+
snapPoints: [0.3, 0.6, 1],
|
|
71
|
+
canDismiss: false,
|
|
72
|
+
});
|
|
73
|
+
expect(result.minSnapPoint).toBe(0.3);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("defaults canDismiss to falsy (minSnapPoint = first snap)", () => {
|
|
77
|
+
const result = validateSnapPoints({ snapPoints: [0.3, 0.6, 1] });
|
|
78
|
+
expect(result.minSnapPoint).toBe(0.3);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("handles canDismiss with unsorted snap points", () => {
|
|
82
|
+
const result = validateSnapPoints({
|
|
83
|
+
snapPoints: [1, 0.5, 0.25],
|
|
84
|
+
canDismiss: false,
|
|
85
|
+
});
|
|
86
|
+
// After sorting: [0.25, 0.5, 1]
|
|
87
|
+
expect(result.minSnapPoint).toBe(0.25);
|
|
88
|
+
expect(result.maxSnapPoint).toBe(1);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("edge cases", () => {
|
|
93
|
+
it("handles empty array", () => {
|
|
94
|
+
const result = validateSnapPoints({ snapPoints: [] });
|
|
95
|
+
// Empty array is falsy for snap points
|
|
96
|
+
expect(result.hasSnapPoints).toBe(true); // Array exists but is empty
|
|
97
|
+
expect(result.snapPoints).toEqual([]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("handles snap points at 0", () => {
|
|
101
|
+
const result = validateSnapPoints({
|
|
102
|
+
snapPoints: [0, 0.5, 1],
|
|
103
|
+
canDismiss: true,
|
|
104
|
+
});
|
|
105
|
+
expect(result.minSnapPoint).toBe(0);
|
|
106
|
+
expect(result.snapPoints).toEqual([0, 0.5, 1]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("handles duplicate snap points", () => {
|
|
110
|
+
const result = validateSnapPoints({ snapPoints: [0.5, 0.5, 1] });
|
|
111
|
+
expect(result.snapPoints).toEqual([0.5, 0.5, 1]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("handles very small snap point values", () => {
|
|
115
|
+
const result = validateSnapPoints({ snapPoints: [0.01, 0.1, 0.5] });
|
|
116
|
+
expect(result.minSnapPoint).toBe(0.01);
|
|
117
|
+
expect(result.maxSnapPoint).toBe(0.5);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("handles snap points greater than 1", () => {
|
|
121
|
+
const result = validateSnapPoints({ snapPoints: [0.5, 1, 1.5] });
|
|
122
|
+
expect(result.maxSnapPoint).toBe(1.5);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -27,10 +27,18 @@ export function createTransitionAwareComponent<P extends object>(
|
|
|
27
27
|
TransitionAwareProps<P>
|
|
28
28
|
>((props: any, ref) => {
|
|
29
29
|
const { nativeGesture } = useGestureContext()!;
|
|
30
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
scrollHandler,
|
|
32
|
+
onContentSizeChange,
|
|
33
|
+
onLayout,
|
|
34
|
+
onTouchStart,
|
|
35
|
+
onTouchEnd,
|
|
36
|
+
} = useScrollRegistry({
|
|
31
37
|
onScroll: props.onScroll,
|
|
32
38
|
onContentSizeChange: props.onContentSizeChange,
|
|
33
39
|
onLayout: props.onLayout,
|
|
40
|
+
onTouchStart: props.onTouchStart,
|
|
41
|
+
onTouchEnd: props.onTouchEnd,
|
|
34
42
|
});
|
|
35
43
|
|
|
36
44
|
return (
|
|
@@ -41,6 +49,8 @@ export function createTransitionAwareComponent<P extends object>(
|
|
|
41
49
|
onScroll={scrollHandler}
|
|
42
50
|
onContentSizeChange={onContentSizeChange}
|
|
43
51
|
onLayout={onLayout}
|
|
52
|
+
onTouchStart={onTouchStart}
|
|
53
|
+
onTouchEnd={onTouchEnd}
|
|
44
54
|
scrollEventThrottle={props.scrollEventThrottle || 16}
|
|
45
55
|
/>
|
|
46
56
|
</GestureDetector>
|