@abhivarde/svelte-drawer 1.0.7 → 1.0.8
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.
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
let startPos = 0;
|
|
29
29
|
let startDragPos = 0;
|
|
30
30
|
let dragging = false;
|
|
31
|
+
let lastPointerPos = 0;
|
|
32
|
+
let lastPointerTime = 0;
|
|
33
|
+
let velocity = 0;
|
|
31
34
|
|
|
32
35
|
function snapPointToPosition(snapPoint: number): number {
|
|
33
36
|
return (1 - snapPoint) * 100;
|
|
@@ -115,6 +118,13 @@
|
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
drawer.drawerPosition.set(newPos, { duration: 0 });
|
|
121
|
+
|
|
122
|
+
const now = Date.now();
|
|
123
|
+
if (lastPointerTime > 0) {
|
|
124
|
+
velocity = (current - lastPointerPos) / (now - lastPointerTime);
|
|
125
|
+
}
|
|
126
|
+
lastPointerPos = current;
|
|
127
|
+
lastPointerTime = now;
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
function onPointerUp() {
|
|
@@ -123,7 +133,12 @@
|
|
|
123
133
|
dragging = false;
|
|
124
134
|
|
|
125
135
|
const pos = drawer.drawerPosition.current;
|
|
126
|
-
|
|
136
|
+
|
|
137
|
+
const isFlick =
|
|
138
|
+
(drawer.direction === "bottom" && velocity > 0.5) ||
|
|
139
|
+
(drawer.direction === "top" && velocity < -0.5) ||
|
|
140
|
+
(drawer.direction === "left" && velocity < -0.5) ||
|
|
141
|
+
(drawer.direction === "right" && velocity > 0.5);
|
|
127
142
|
|
|
128
143
|
if (drawer.snapPoints && drawer.snapPoints.length > 0) {
|
|
129
144
|
const nearestSnapPoint = findNearestSnapPoint(pos);
|
|
@@ -132,20 +147,24 @@
|
|
|
132
147
|
const lowestSnapPoint = Math.min(...drawer.snapPoints);
|
|
133
148
|
const lowestSnapPos = snapPointToPosition(lowestSnapPoint);
|
|
134
149
|
|
|
135
|
-
if (pos > lowestSnapPos +
|
|
150
|
+
if (isFlick || pos > lowestSnapPos + 30) {
|
|
136
151
|
drawer.closeDrawer();
|
|
137
152
|
} else {
|
|
138
153
|
drawer.drawerPosition.set(snapPos);
|
|
139
154
|
drawer.setActiveSnapPoint?.(nearestSnapPoint);
|
|
140
155
|
}
|
|
141
156
|
} else {
|
|
142
|
-
if (pos >
|
|
157
|
+
if (isFlick || pos > 30) {
|
|
143
158
|
drawer.closeDrawer();
|
|
144
159
|
} else {
|
|
145
160
|
drawer.drawerPosition.set(0);
|
|
146
161
|
}
|
|
147
162
|
}
|
|
148
163
|
|
|
164
|
+
velocity = 0;
|
|
165
|
+
lastPointerPos = 0;
|
|
166
|
+
lastPointerTime = 0;
|
|
167
|
+
|
|
149
168
|
window.removeEventListener("pointermove", onPointerMove);
|
|
150
169
|
window.removeEventListener("pointerup", onPointerUp);
|
|
151
170
|
}
|
|
@@ -202,7 +221,8 @@
|
|
|
202
221
|
<div
|
|
203
222
|
bind:this={contentElement}
|
|
204
223
|
class={className}
|
|
205
|
-
|
|
224
|
+
data-svelte-drawer
|
|
225
|
+
style="transform: {getTransform()}; z-index: 50; touch-action: none; will-change: transform;{autoHeight
|
|
206
226
|
? ' height: auto;'
|
|
207
227
|
: ''}"
|
|
208
228
|
tabindex="-1"
|
|
@@ -214,3 +234,15 @@
|
|
|
214
234
|
{@render children()}
|
|
215
235
|
</div>
|
|
216
236
|
{/if}
|
|
237
|
+
|
|
238
|
+
<style>
|
|
239
|
+
:global([data-svelte-drawer]::after) {
|
|
240
|
+
content: "";
|
|
241
|
+
position: absolute;
|
|
242
|
+
background: inherit;
|
|
243
|
+
left: 0;
|
|
244
|
+
right: 0;
|
|
245
|
+
height: 200px;
|
|
246
|
+
top: 100%;
|
|
247
|
+
}
|
|
248
|
+
</style>
|