From 4dad3d1c89fd5a6390e7b56f3dae8d5ae87bf81a Mon Sep 17 00:00:00 2001 From: Damiano Plebani Date: Wed, 18 Dec 2024 14:07:39 +0100 Subject: [PATCH] Enable dynamic component scaling in the legacy UI --- src/components/typography/IOText.tsx | 4 ++-- src/utils/accessibility.ts | 13 +++++-------- src/utils/fonts.ts | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/typography/IOText.tsx b/src/components/typography/IOText.tsx index 2dc36ab3..f73e5198 100644 --- a/src/components/typography/IOText.tsx +++ b/src/components/typography/IOText.tsx @@ -10,8 +10,8 @@ import { IOColors, useIOTheme } from "../../core"; import { useBoldTextEnabled } from "../../utils/accessibility"; import { IOFontFamily, - IOFontSizeMultiplier, IOFontWeight, + IOMaxFontSizeMultiplier, makeFontStyleObject } from "../../utils/fonts"; @@ -142,7 +142,7 @@ export const IOText = forwardRef( /* Accessible typography based on the `fontScale` parameter */ const accessibleFontSizeProps: ComponentProps = { allowFontScaling, - maxFontSizeMultiplier: maxFontSizeMultiplier ?? IOFontSizeMultiplier + maxFontSizeMultiplier: maxFontSizeMultiplier ?? IOMaxFontSizeMultiplier }; return ( diff --git a/src/utils/accessibility.ts b/src/utils/accessibility.ts index c2c89179..0214e9da 100644 --- a/src/utils/accessibility.ts +++ b/src/utils/accessibility.ts @@ -1,7 +1,6 @@ import { useEffect, useState } from "react"; import { AccessibilityInfo, Platform, useWindowDimensions } from "react-native"; -import { useIOExperimentalDesign } from "../core"; -import { IOFontSizeMultiplier } from "./fonts"; +import { IOMaxFontSizeMultiplier } from "./fonts"; /** * Query whether a bold text is currently enabled. The result is true @@ -37,7 +36,7 @@ export const useBoldTextEnabled = () => { /** * Returns a font size multiplier based on the font scale of the device, - * but limited to the `IOFontSizeMultiplier` value. + * but limited to the `IOMaxFontSizeMultiplier` value. * @returns number */ export const useIOFontDynamicScale = (): { @@ -45,17 +44,15 @@ export const useIOFontDynamicScale = (): { spacingScaleMultiplier: number; hugeFontEnabled: boolean; } => { - const { isExperimental } = useIOExperimentalDesign(); const { fontScale } = useWindowDimensions(); - const deviceFontScale = isExperimental ? fontScale : 1; - const hugeFontEnabled = deviceFontScale >= 1.35; + const hugeFontEnabled = fontScale >= 1.35; - const dynamicFontScale = Math.min(deviceFontScale, IOFontSizeMultiplier); + const dynamicFontScale = Math.min(fontScale, IOMaxFontSizeMultiplier); /* We make the spacing dynamic based on the font scale, but we multiply this value to limit the amount of scaling applied to the spacing */ const spacingScaleMultiplier = - dynamicFontScale <= IOFontSizeMultiplier ? 1 : 0.8; + dynamicFontScale <= IOMaxFontSizeMultiplier ? 1 : 0.8; return { hugeFontEnabled, diff --git a/src/utils/fonts.ts b/src/utils/fonts.ts index b6216b79..734aa7ae 100644 --- a/src/utils/fonts.ts +++ b/src/utils/fonts.ts @@ -122,7 +122,7 @@ export const makeFontFamilyName = ( const defaultFont: IOFontFamily = "TitilliumSansPro"; const defaultWeight: IOFontWeight = "Regular"; const defaultFontSize: IOFontSize = 16; -export const IOFontSizeMultiplier = 1.5; +export const IOMaxFontSizeMultiplier = 1.5; /** * Return a {@link FontStyleObject} with the fields filled based on the platform (iOS or Android).