forked from akai/readest
4aebbf679f
* fix: footnote now should be hidden in srcdoc iframes * fix: eliminate white flash on startup when using dark mode * feat: rescale UI size with pixel density
21 lines
731 B
TypeScript
21 lines
731 B
TypeScript
import { getOSPlatform } from '@/utils/misc';
|
|
import { useMediaQuery } from 'react-responsive';
|
|
|
|
// use desktop size as base size
|
|
export const useResponsiveSize = (baseSize: number) => {
|
|
const isPhone = useMediaQuery({ maxWidth: 480 });
|
|
const isTablet = useMediaQuery({ minWidth: 481, maxWidth: 1024 });
|
|
if (typeof window === 'undefined') {
|
|
return baseSize;
|
|
}
|
|
const pixelRatio = window.devicePixelRatio || 2.4;
|
|
const isMobile = ['android', 'ios'].includes(getOSPlatform());
|
|
if (isPhone && isMobile) return baseSize * (pixelRatio / 3) * 1.25;
|
|
if (isTablet && isMobile) return baseSize * (pixelRatio / 3) * 1.25;
|
|
return baseSize;
|
|
};
|
|
|
|
export const useDefaultIconSize = () => {
|
|
return useResponsiveSize(20);
|
|
};
|