import { clamp } from 'lodash' import { useWindowDimensions } from 'react-native' export const useFontScale = ({ maxFontSizeMultiplier, minFontSizeMultiplier, }: { maxFontSizeMultiplier?: number minFontSizeMultiplier?: number } = {}) => { const { fontScale: nativeFontScale } = useWindowDimensions() // Infinity values are used to negate the scale if only one constraint is provided. This ensures that the scale is clamped to the provided constraint. const maxFontScale = maxFontSizeMultiplier ?? Number.POSITIVE_INFINITY const minFontScale = minFontSizeMultiplier ?? Number.NEGATIVE_INFINITY const clampedScale = clamp(nativeFontScale, minFontScale, maxFontScale) return clampedScale }