Skip to content

Commit

Permalink
[IOAPPX-451] Enable dynamic component scaling in the legacy UI (#371)
Browse files Browse the repository at this point in the history
## Short description
This PR enables dynamic component scaling in the legacy UI, as well.

## List of changes proposed in this pull request
- Remove `isExperimental` condition

## How to test
Check if **Selection** components have scaled sizes in the legacy UI
(new DS disabled)
  • Loading branch information
dmnplb authored Dec 18, 2024
1 parent cc3abfd commit 52d08c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/typography/IOText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { IOColors, useIOTheme } from "../../core";
import { useBoldTextEnabled } from "../../utils/accessibility";
import {
IOFontFamily,
IOFontSizeMultiplier,
IOFontWeight,
IOMaxFontSizeMultiplier,
makeFontStyleObject
} from "../../utils/fonts";

Expand Down Expand Up @@ -142,7 +142,7 @@ export const IOText = forwardRef<View, IOTextProps>(
/* Accessible typography based on the `fontScale` parameter */
const accessibleFontSizeProps: ComponentProps<typeof Text> = {
allowFontScaling,
maxFontSizeMultiplier: maxFontSizeMultiplier ?? IOFontSizeMultiplier
maxFontSizeMultiplier: maxFontSizeMultiplier ?? IOMaxFontSizeMultiplier
};

return (
Expand Down
13 changes: 5 additions & 8 deletions src/utils/accessibility.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,25 +36,23 @@ 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 = (): {
dynamicFontScale: number;
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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 52d08c1

Please sign in to comment.