remove unused haptics hook

This commit is contained in:
yohlo
2025-08-20 22:50:00 -05:00
parent f51c278cd3
commit b3edbbcc00

View File

@@ -1,61 +0,0 @@
// Sneaky way of triggering haptic feedback, without using the vibration API (not available on iOS)
// Source: https://github.com/posaune0423/use-haptic
import { useCallback, useEffect, useMemo, useRef } from "react";
const detectiOS = (): boolean => {
if (typeof navigator === "undefined") {
return false;
}
const toMatch = [/iPhone/i, /iPad/i, /iPod/i];
return toMatch.some((toMatchItem) => {
return RegExp(toMatchItem).exec(navigator.userAgent);
});
};
const useHaptic = (
duration = 200,
): { triggerHaptic: () => void } => {
const inputRef = useRef<HTMLInputElement | null>(null);
const labelRef = useRef<HTMLLabelElement | null>(null);
const isIOS = useMemo(() => detectiOS(), []);
useEffect(() => {
const input = document.createElement("input");
input.type = "checkbox";
input.id = "haptic-switch";
input.setAttribute("switch", "");
input.style.display = "none";
document.body.appendChild(input);
inputRef.current = input;
const label = document.createElement("label");
label.htmlFor = "haptic-switch";
label.style.display = "none";
document.body.appendChild(label);
labelRef.current = label;
return () => {
document.body.removeChild(input);
document.body.removeChild(label);
};
}, []);
const triggerHaptic = useCallback(() => {
if (isIOS) {
labelRef.current?.click();
} else {
if (navigator?.vibrate) {
navigator.vibrate(duration);
} else {
labelRef.current?.click();
}
}
}, [isIOS]);
return { triggerHaptic };
};
export default useHaptic;