Skip to content

Commit a51a752

Browse files
committed
perf(demo): improve OrbitalDrag touch responsiveness on iOS
- Remove unnecessary { passive: false } from pointermove listener (drag handler never calls preventDefault) - Auto-pause inertia rAF loop when all velocities decay to zero; auto-resume via watcher when a gesture ends with residual velocity - Remove eager inertia.resume() on mount (watcher handles it)
1 parent 7608e55 commit a51a752

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

demo/@/components/custom/orbital-drag/OrbitalDrag.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ onMounted(() => {
253253
useEventListener(window, "gesturechange", pinch.gesture as (event: Event) => void, { passive: false });
254254
useEventListener(window, "gestureend", pinch.stopGesture);
255255
256-
inertia.resume();
257256
});
258257
259258
onUnmounted(() => {

demo/@/components/custom/orbital-drag/useOrbitalInertia.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useRafFn } from "@vueuse/core";
22
import type { Ref } from "vue";
3+
import { watch } from "vue";
34
import type { TransformState, VelocityState } from ".";
45
import { axes } from ".";
56

@@ -36,6 +37,16 @@ export function useOrbitalInertia(params: OrbitalInertiaParams) {
3637
updateLinearTransform,
3738
} = params;
3839

40+
const hasVelocity = () => {
41+
if (Math.abs(angularVelocitySpeed.value) > 1e-4) return true;
42+
for (const category of ["translate", "scale"] as const) {
43+
for (const v of Object.values(velocity.value[category])) {
44+
if (Math.abs(v as number) > 0.01) return true;
45+
}
46+
}
47+
return false;
48+
};
49+
3950
const applyInertia = () => {
4051
if (isDragging.value || isTouching.value || isWheeling.value) return;
4152

@@ -66,9 +77,24 @@ export function useOrbitalInertia(params: OrbitalInertiaParams) {
6677
}
6778
}
6879
}
80+
81+
// Auto-pause when all velocities have decayed to zero
82+
if (!hasVelocity()) {
83+
pause();
84+
}
6985
};
7086

71-
const { pause, resume } = useRafFn(applyInertia);
87+
const { pause, resume } = useRafFn(applyInertia, { immediate: false });
88+
89+
// Auto-resume the inertia loop when a gesture ends with residual velocity
90+
watch(
91+
() => isDragging.value || isTouching.value || isWheeling.value,
92+
(active) => {
93+
if (!active && hasVelocity()) {
94+
resume();
95+
}
96+
},
97+
);
7298

7399
return { pause, resume };
74100
}

demo/@/components/custom/orbital-drag/useOrbitalPointer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export function useOrbitalPointer(params: OrbitalPointerParams) {
317317
startDrag(event);
318318
containerRef.value!.setPointerCapture(event.pointerId);
319319
const doc = containerRef.value!.ownerDocument;
320-
doc.addEventListener("pointermove", onPointerMove, { passive: false });
320+
doc.addEventListener("pointermove", onPointerMove);
321321
doc.addEventListener("pointerup", onPointerUp);
322322
doc.addEventListener("pointercancel", onPointerUp);
323323
};

0 commit comments

Comments
 (0)