openguessr-ui 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Popup.svelte +16 -9
- package/package.json +1 -1
package/components/Popup.svelte
CHANGED
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
let uiWindowHeight = $state();
|
|
64
64
|
|
|
65
65
|
// Drawer state
|
|
66
|
+
let dragTouchId;
|
|
66
67
|
let dragStartY = $state();
|
|
67
68
|
let dragStartX;
|
|
68
69
|
let dragStartVerticalOffset;
|
|
@@ -87,27 +88,33 @@
|
|
|
87
88
|
openAnimationFrame = requestAnimationFrame(step);
|
|
88
89
|
};
|
|
89
90
|
|
|
91
|
+
// Check if the touch that started the drag is included
|
|
92
|
+
const findDragTouch = (touches) => [...touches].find((touch) => touch.identifier === dragTouchId);
|
|
93
|
+
|
|
90
94
|
const dragStart = (event) => {
|
|
91
|
-
// Abort if not a drawer, or if content should be scrolled by the "finger downwards" movement because it isn't scrolled all the way up
|
|
92
|
-
if (!popupToDrawer.current || isScrolledDown(event.target, contentEl)) return;
|
|
95
|
+
// Abort if not a drawer, already tracking a finger, or if content should be scrolled by the "finger downwards" movement because it isn't scrolled all the way up
|
|
96
|
+
if (!popupToDrawer.current || dragStartY != null || isScrolledDown(event.target, contentEl)) return;
|
|
93
97
|
|
|
94
98
|
// Catch the drawer where it is (could still be animating open)
|
|
95
99
|
cancelAnimationFrame(openAnimationFrame);
|
|
100
|
+
const touch = event.changedTouches[0]; // Changed touches lists only new touches, not ones "still" on screen
|
|
101
|
+
dragTouchId = touch.identifier;
|
|
96
102
|
dragStartVerticalOffset = drawerVerticalOffset;
|
|
97
|
-
dragStartY =
|
|
98
|
-
dragStartX =
|
|
103
|
+
dragStartY = touch.clientY;
|
|
104
|
+
dragStartX = touch.clientX;
|
|
99
105
|
velocitySamples = [{ y: dragStartY, time: performance.now() }];
|
|
100
106
|
};
|
|
101
107
|
|
|
102
108
|
const drag = (event) => {
|
|
103
|
-
|
|
109
|
+
const touch = findDragTouch(event.touches);
|
|
110
|
+
if (dragStartY == null || !touch) return;
|
|
104
111
|
|
|
105
|
-
const eventY =
|
|
112
|
+
const eventY = touch.clientY;
|
|
106
113
|
|
|
107
114
|
// On the first move, decide whether the gesture drags the drawer or scrolls the content
|
|
108
115
|
if (!isDragging) {
|
|
109
116
|
// Horizontal movements belong to the content, e.g. horizontally scrolling elements
|
|
110
|
-
const isScrollingHorizontally = Math.abs(
|
|
117
|
+
const isScrollingHorizontally = Math.abs(touch.clientX - dragStartX) > Math.abs(eventY - dragStartY); // Check if more horizontal movement than vertical
|
|
111
118
|
|
|
112
119
|
// Dragging finger upwards while the touched element (or an ancestor up to the content) can still scroll down
|
|
113
120
|
// Mainly relevant for the slow stretch animation when the drwaer is dragged upwards (which shouldn't show when content is scrolled down)
|
|
@@ -132,8 +139,8 @@
|
|
|
132
139
|
drawerVerticalOffset = delta > 0 ? delta : delta * 0.05; // Allow dragging the drawer upwards, but make it less effective (that's what the x0.05 is for)
|
|
133
140
|
};
|
|
134
141
|
|
|
135
|
-
const dragEnd = () => {
|
|
136
|
-
if (dragStartY == null) return;
|
|
142
|
+
const dragEnd = (event) => {
|
|
143
|
+
if (dragStartY == null || !findDragTouch(event.changedTouches)) return; // Only the dragging finger ends the drag
|
|
137
144
|
dragStartY = null;
|
|
138
145
|
|
|
139
146
|
if (!isDragging) return animateDrawerOpen(); // Single tap without drag, resume opening if it was caught mid-animation
|