mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-03-22 22:00:59 +00:00
switch from ogg -> m4a for Mobile Safari
This commit is contained in:
parent
6acccfa2a8
commit
9e7604d0e4
6279 changed files with 584 additions and 591 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useCallback, useRef, useSyncExternalStore } from "react";
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
// Only check pointer: coarse. Adding "hover: none" would be more precise but
|
||||
// Samsung Android devices incorrectly report hover: hover for touchscreens.
|
||||
|
|
@ -6,27 +6,18 @@ import { useCallback, useRef, useSyncExternalStore } from "react";
|
|||
const query = "(pointer: coarse)";
|
||||
const getServerSnapshot = () => null;
|
||||
|
||||
export function useTouchDevice() {
|
||||
const queryRef = useRef<null | ReturnType<typeof window.matchMedia>>(null);
|
||||
|
||||
const subscribe = useCallback((onStoreChange: () => void) => {
|
||||
const mql = window.matchMedia(query);
|
||||
mql.addEventListener("change", onStoreChange);
|
||||
queryRef.current = mql;
|
||||
return () => {
|
||||
mql.removeEventListener("change", onStoreChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const getSnapshot = useCallback(() => {
|
||||
return queryRef.current?.matches ?? null;
|
||||
}, []);
|
||||
|
||||
const isTouch = useSyncExternalStore<boolean | null>(
|
||||
subscribe,
|
||||
getSnapshot,
|
||||
getServerSnapshot,
|
||||
);
|
||||
|
||||
return isTouch;
|
||||
function subscribe(onStoreChange: () => void) {
|
||||
const mql = window.matchMedia(query);
|
||||
mql.addEventListener("change", onStoreChange);
|
||||
return () => {
|
||||
mql.removeEventListener("change", onStoreChange);
|
||||
};
|
||||
}
|
||||
|
||||
function getSnapshot() {
|
||||
return window.matchMedia(query).matches;
|
||||
}
|
||||
|
||||
export function useTouchDevice() {
|
||||
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue