mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-14 00:03:42 +08:00
43 lines
1020 B
TypeScript
43 lines
1020 B
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
/**
|
|
* Hook to detect if the device is mobile
|
|
*/
|
|
export function useIsMobile() {
|
|
const [isMobile, setIsMobile] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const checkMobile = () => {
|
|
const mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
navigator.userAgent
|
|
) || window.innerWidth < 768;
|
|
setIsMobile(mobile);
|
|
};
|
|
|
|
checkMobile();
|
|
window.addEventListener('resize', checkMobile);
|
|
|
|
return () => window.removeEventListener('resize', checkMobile);
|
|
}, []);
|
|
|
|
return isMobile;
|
|
}
|
|
|
|
/**
|
|
* Hook to detect if the device is iOS
|
|
*/
|
|
export function useIsIOS() {
|
|
const [isIOS, setIsIOS] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const checkIOS = () => {
|
|
const ios = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window as any).MSStream;
|
|
setIsIOS(ios);
|
|
};
|
|
|
|
checkIOS();
|
|
}, []);
|
|
|
|
return isIOS;
|
|
}
|