@yahoo/uds-mobile 2.24.0-beta.5 → 2.24.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Avatar/AvatarIcon.cjs +2 -2
- package/dist/components/Avatar/AvatarIcon.js +2 -2
- package/dist/components/Avatar/AvatarIcon.js.map +1 -1
- package/dist/components/Avatar/AvatarImage.cjs +2 -2
- package/dist/components/Avatar/AvatarImage.js +2 -2
- package/dist/components/Avatar/AvatarImage.js.map +1 -1
- package/dist/components/Avatar/AvatarText.cjs +2 -2
- package/dist/components/Avatar/AvatarText.js +2 -2
- package/dist/components/Avatar/AvatarText.js.map +1 -1
- package/dist/components/Avatar/useAvatarFontScale.cjs +16 -0
- package/dist/components/Avatar/useAvatarFontScale.d.cts +7 -0
- package/dist/components/Avatar/useAvatarFontScale.d.cts.map +1 -0
- package/dist/components/Avatar/useAvatarFontScale.d.ts +7 -0
- package/dist/components/Avatar/useAvatarFontScale.d.ts.map +1 -0
- package/dist/components/Avatar/useAvatarFontScale.js +16 -0
- package/dist/components/Avatar/useAvatarFontScale.js.map +1 -0
- package/dist/components/Button/buttonTheme.cjs +10 -6
- package/dist/components/Button/buttonTheme.d.cts +10 -5
- package/dist/components/Button/buttonTheme.d.cts.map +1 -1
- package/dist/components/Button/buttonTheme.d.ts +10 -5
- package/dist/components/Button/buttonTheme.d.ts.map +1 -1
- package/dist/components/Button/buttonTheme.js +10 -6
- package/dist/components/Button/buttonTheme.js.map +1 -1
- package/dist/components/Button.cjs +17 -8
- package/dist/components/Button.js +17 -8
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Checkbox.cjs +4 -2
- package/dist/components/Checkbox.js +4 -2
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/Chip/ChipBase.cjs +22 -19
- package/dist/components/Chip/ChipBase.js +22 -19
- package/dist/components/Chip/ChipBase.js.map +1 -1
- package/dist/components/Icon.cjs +3 -2
- package/dist/components/Icon.d.cts.map +1 -1
- package/dist/components/Icon.d.ts.map +1 -1
- package/dist/components/Icon.js +3 -2
- package/dist/components/Icon.js.map +1 -1
- package/dist/components/Input.cjs +1 -1
- package/dist/components/Input.js +1 -1
- package/dist/components/Input.js.map +1 -1
- package/dist/components/Link.cjs +10 -1
- package/dist/components/Link.d.cts +6 -0
- package/dist/components/Link.d.cts.map +1 -1
- package/dist/components/Link.d.ts +6 -0
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +10 -1
- package/dist/components/Link.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs +18 -10
- package/dist/components/Pagination/Pagination.d.cts +2 -0
- package/dist/components/Pagination/Pagination.d.cts.map +1 -1
- package/dist/components/Pagination/Pagination.d.ts +2 -0
- package/dist/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/components/Pagination/Pagination.js +18 -10
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.cjs +8 -2
- package/dist/components/Pagination/PaginationEllipsis.d.cts.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.d.ts.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.js +9 -3
- package/dist/components/Pagination/PaginationEllipsis.js.map +1 -1
- package/dist/components/Pagination/PaginationItem.cjs +2 -1
- package/dist/components/Pagination/PaginationItem.js +2 -1
- package/dist/components/Pagination/PaginationItem.js.map +1 -1
- package/dist/components/Pagination/PaginationLink.cjs +2 -1
- package/dist/components/Pagination/PaginationLink.js +2 -1
- package/dist/components/Pagination/PaginationLink.js.map +1 -1
- package/dist/components/Pagination/PaginationNext.cjs +3 -1
- package/dist/components/Pagination/PaginationNext.js +3 -1
- package/dist/components/Pagination/PaginationNext.js.map +1 -1
- package/dist/components/Pagination/PaginationPrev.cjs +3 -1
- package/dist/components/Pagination/PaginationPrev.js +3 -1
- package/dist/components/Pagination/PaginationPrev.js.map +1 -1
- package/dist/components/Pagination/paginationContext.d.cts +2 -0
- package/dist/components/Pagination/paginationContext.d.cts.map +1 -1
- package/dist/components/Pagination/paginationContext.d.ts +2 -0
- package/dist/components/Pagination/paginationContext.d.ts.map +1 -1
- package/dist/components/Pagination/paginationContext.js.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.cjs +8 -1
- package/dist/components/Pagination/usePaginationControlStyles.d.cts.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.d.ts.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.js +9 -2
- package/dist/components/Pagination/usePaginationControlStyles.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +2 -1
- package/dist/components/Radio/Radio.js +2 -1
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/Select/SelectItem.cjs +6 -6
- package/dist/components/Select/SelectItem.js +6 -6
- package/dist/components/Select/SelectItem.js.map +1 -1
- package/dist/components/Select/SelectTrigger.cjs +1 -1
- package/dist/components/Select/SelectTrigger.js +1 -1
- package/dist/components/Select/SelectTrigger.js.map +1 -1
- package/dist/components/Switch.cjs +4 -2
- package/dist/components/Switch.js +4 -2
- package/dist/components/Switch.js.map +1 -1
- package/dist/components/Tabs/Tab.cjs +1 -1
- package/dist/components/Tabs/Tab.js +1 -1
- package/dist/components/Tabs/Tab.js.map +1 -1
- package/dist/fontScaling/androidNonlinearFontScaling.cjs +174 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts +7 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts.map +1 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts +7 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts.map +1 -0
- package/dist/fontScaling/androidNonlinearFontScaling.js +175 -0
- package/dist/fontScaling/androidNonlinearFontScaling.js.map +1 -0
- package/dist/fontScaling/useFontScale.cjs +13 -4
- package/dist/fontScaling/useFontScale.d.cts +8 -3
- package/dist/fontScaling/useFontScale.d.cts.map +1 -1
- package/dist/fontScaling/useFontScale.d.ts +8 -3
- package/dist/fontScaling/useFontScale.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.js +14 -5
- package/dist/fontScaling/useFontScale.js.map +1 -1
- package/package.json +1 -1
|
@@ -53,7 +53,6 @@ const Switch = memo(function Switch({ isOn: isOnProp, defaultIsOn = false, onCha
|
|
|
53
53
|
const activeVariant = isOn ? "on" : "off";
|
|
54
54
|
const { theme } = useUnistyles();
|
|
55
55
|
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier) ?? 0;
|
|
56
|
-
const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier);
|
|
57
56
|
useEffect(() => {
|
|
58
57
|
const checkReducedMotion = async () => {
|
|
59
58
|
setPrefersReducedMotion(await AccessibilityInfo.isReduceMotionEnabled());
|
|
@@ -79,8 +78,11 @@ const Switch = memo(function Switch({ isOn: isOnProp, defaultIsOn = false, onCha
|
|
|
79
78
|
size,
|
|
80
79
|
variant: activeVariant
|
|
81
80
|
}) ?? switchStyles;
|
|
81
|
+
const labelBaseSize = resolvedSwitchStyles.text.lineHeight ?? resolvedSwitchStyles.text.fontSize;
|
|
82
|
+
const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, typeof labelBaseSize === "number" ? labelBaseSize : void 0);
|
|
82
83
|
const handleIconSize = resolvedSwitchStyles.handleIcon.fontSize;
|
|
83
|
-
const
|
|
84
|
+
const handleIconScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, typeof handleIconSize === "number" ? handleIconSize : void 0);
|
|
85
|
+
const scaledHandleIconSize = typeof handleIconSize === "number" ? Math.round(handleIconSize * handleIconScaleFactor) : void 0;
|
|
84
86
|
const scaledTrackWidth = Math.round(resolvedSwitchStyles.switch.width * fontScaleFactor);
|
|
85
87
|
const scaledTrackPadding = Math.round(resolvedSwitchStyles.switch.padding * fontScaleFactor);
|
|
86
88
|
const scaledHandleWidth = Math.round(resolvedSwitchStyles.handle.width * fontScaleFactor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","names":["StyleSheet"],"sources":["../../src/components/Switch.tsx"],"sourcesContent":["import type { UniversalSwitchProps } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { memo, useCallback, useEffect, useMemo, useState } from 'react';\nimport type {\n AccessibilityProps,\n StyleProp,\n TextStyle,\n View,\n ViewProps,\n ViewStyle,\n} from 'react-native';\nimport { AccessibilityInfo, I18nManager, Platform, Pressable } from 'react-native';\nimport Animated, { useAnimatedStyle, useDerivedValue, withTiming } from 'react-native-reanimated';\n// eslint-disable-next-line uds/no-use-unistyles -- switch variant layers need concrete web styles\nimport { StyleSheet, useUnistyles } from 'react-native-unistyles';\nimport { useAnimatedVariantColor } from 'react-native-unistyles/reanimated';\n\nimport { switchStyles } from '../../generated/styles';\nimport { useFontScale } from '../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { FormLabel } from './FormLabel';\nimport type { IconSlotType } from './IconSlot';\nimport { IconSlot } from './IconSlot';\n\ninterface SwitchProps extends Omit<ViewProps, 'style'>, UniversalSwitchProps<IconSlotType> {\n /** Ref to the underlying View */\n ref?: Ref<View>;\n /** Callback when the switch value changes */\n onChange?: (value: boolean) => void;\n /** Whether the switch is disabled */\n disabled?: boolean;\n /** Whether the switch is required (shows asterisk with label) */\n required?: boolean;\n /**\n * Caps how far the track, handle, and label grow with the OS text-size\n * setting; all scale by the same factor. Set null to remove the cap;\n * override app-wide via UDSFontScalingProvider.\n * @default 2\n */\n maxFontSizeMultiplier?: number | null;\n /** Accessibility hint describing what happens when activated */\n accessibilityHint?: AccessibilityProps['accessibilityHint'];\n}\n\nconst ANIMATION_DURATION = 120;\n\n/**\n * **Switch component for toggling options**\n *\n * @description\n * A switch (also called a toggle) is a binary on/off input control.\n * It allows users to pick between two clearly opposite choices.\n *\n * @category Form\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Switch } from '@yahoo/uds-mobile/Switch';\n *\n * <Switch label=\"Notifications\" />\n * <Switch isOn={enabled} onChange={setEnabled} label=\"Dark mode\" />\n * <Switch onIcon=\"Check\" offIcon=\"Cross\" label=\"Sync\" />\n * ```\n *\n * @usage\n * - Settings: For toggling preferences on/off\n * - Feature flags: For enabling/disabling features\n * - Immediate effect toggles (no submit button needed)\n *\n * @accessibility\n * - Sets `accessibilityRole=\"switch\"` automatically\n * - Announces on/off state to screen readers\n * - Respects system reduce motion preference\n * - Supports `reduceMotion` prop to disable animations\n *\n * @see {@link Checkbox} for forms with submit actions\n * @see {@link Radio} for single-select options\n */\nconst Switch = memo(function Switch({\n isOn: isOnProp,\n defaultIsOn = false,\n onChange,\n label,\n labelPosition = 'start',\n size = 'md',\n onIcon,\n offIcon,\n disabled = false,\n required,\n maxFontSizeMultiplier,\n accessibilityHint,\n reduceMotion = false,\n ref,\n ...viewProps\n}: SwitchProps) {\n const isControlled = isOnProp !== undefined;\n const [internalIsOn, setInternalIsOn] = useState(defaultIsOn);\n const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);\n const isOn = isControlled ? isOnProp : internalIsOn;\n const activeVariant = isOn ? 'on' : 'off';\n const { theme } = useUnistyles();\n\n // One capped factor governs track, handle, travel, and label.\n const resolvedMaxFontSizeMultiplier =\n useMaxFontSizeMultiplier('control', maxFontSizeMultiplier) ?? 0;\n const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier);\n // Check system reduced motion preference\n useEffect(() => {\n const checkReducedMotion = async () => {\n const isReduceMotionEnabled = await AccessibilityInfo.isReduceMotionEnabled();\n setPrefersReducedMotion(isReduceMotionEnabled);\n };\n checkReducedMotion();\n\n const subscription = AccessibilityInfo.addEventListener(\n 'reduceMotionChanged',\n setPrefersReducedMotion,\n );\n return () => subscription.remove();\n }, []);\n\n const shouldReduceMotion = reduceMotion || prefersReducedMotion;\n const animationDuration = shouldReduceMotion ? 0 : ANIMATION_DURATION;\n\n const progress = useDerivedValue(\n () => withTiming(isOn ? 1 : 0, { duration: animationDuration }),\n [isOn, animationDuration],\n );\n\n const handlePress = useCallback(() => {\n if (disabled) {\n return;\n }\n\n const newValue = !isOn;\n\n if (!isControlled) {\n setInternalIsOn(newValue);\n }\n\n onChange?.(newValue);\n }, [disabled, isOn, isControlled, onChange]);\n\n // On web, useVariants returns the resolved style object instead of mutating\n // switchStyles in place.\n const variantSwitchStyles = switchStyles.useVariants({\n size,\n variant: activeVariant,\n }) as unknown as typeof switchStyles | undefined;\n const resolvedSwitchStyles = variantSwitchStyles ?? switchStyles;\n // Size the handle glyph from the configured size layer and the same factor\n // as the handle it sits in, rather than a fixed icon token or native scaling.\n const handleIconSize = resolvedSwitchStyles.handleIcon.fontSize;\n const scaledHandleIconSize =\n typeof handleIconSize === 'number' ? Math.round(handleIconSize * fontScaleFactor) : undefined;\n\n // Derive travel from the same rounded metrics used to render the control.\n // Scaling the token travel independently can differ by a pixel at fractional\n // font scales, leaving unequal insets at opposite ends of the track.\n const scaledTrackWidth = Math.round(resolvedSwitchStyles.switch.width * fontScaleFactor);\n const scaledTrackPadding = Math.round(resolvedSwitchStyles.switch.padding * fontScaleFactor);\n const scaledHandleWidth = Math.round(resolvedSwitchStyles.handle.width * fontScaleFactor);\n const scaledHandleTravel = Math.max(\n 0,\n scaledTrackWidth - scaledHandleWidth - scaledTrackPadding * 2,\n );\n // RTL mirrors the track layout but not transforms, so travel flips sign.\n const travelDistance = scaledHandleTravel * (I18nManager.isRTL ? -1 : 1);\n\n const variantLayerStyles = useMemo(() => {\n const components = theme.components as unknown as Record<string, Record<string, unknown>>;\n const getLayerStyle = <TStyle,>(layer: string) =>\n components[`switch/variant/default/active/${activeVariant}/${layer}/rest`] as\n TStyle | undefined;\n\n return {\n handle: getLayerStyle<ViewStyle>('handle'),\n handleIcon: getLayerStyle<TextStyle>('handleIcon'),\n switch: getLayerStyle<ViewStyle>('switch'),\n text: getLayerStyle<TextStyle>('rootText'),\n };\n }, [activeVariant, theme]);\n\n // Get animated track color from design tokens (changes when variant changes)\n const trackBackgroundColor = useAnimatedVariantColor(\n resolvedSwitchStyles.switch,\n 'backgroundColor',\n );\n\n const animatedTrackStyle = useAnimatedStyle(() => {\n 'worklet';\n return {\n backgroundColor: withTiming(trackBackgroundColor.value, { duration: animationDuration }),\n };\n });\n\n const animatedHandleStyle = useAnimatedStyle(() => {\n 'worklet';\n return {\n transform: [{ translateX: progress.value * travelDistance }],\n };\n });\n\n const rootStyle: StyleProp<ViewStyle> = useMemo(\n () => [resolvedSwitchStyles.root, switchStaticStyles.root({ disabled })],\n [resolvedSwitchStyles.root, disabled],\n );\n\n // Track and handle grow by the capped factor so the handle (and its icon)\n // stays contained. Scale the track's inset too so the derived travel lands\n // the handle at the same distance from either end.\n const scaleDimensions = useCallback(\n (style: ViewStyle | undefined): ViewStyle | undefined => {\n if (!style || fontScaleFactor === 1) {\n return undefined;\n }\n const { width, height, padding } = style;\n return typeof width === 'number' && typeof height === 'number'\n ? {\n width: Math.round(width * fontScaleFactor),\n height: Math.round(height * fontScaleFactor),\n ...(typeof padding === 'number' && {\n padding: Math.round(padding * fontScaleFactor),\n }),\n }\n : undefined;\n },\n [fontScaleFactor],\n );\n\n const trackStyle: StyleProp<ViewStyle> = useMemo(\n () => [\n resolvedSwitchStyles.switch,\n switchStaticStyles.track,\n variantLayerStyles.switch,\n scaleDimensions(resolvedSwitchStyles.switch as ViewStyle),\n // On web, the animated variant color hook currently resolves to Unistyles'\n // black fallback, so the concrete variant layer provides the track color.\n Platform.OS !== 'web' && animatedTrackStyle,\n ],\n [resolvedSwitchStyles.switch, variantLayerStyles.switch, scaleDimensions, animatedTrackStyle],\n );\n\n const handleStyle: StyleProp<ViewStyle> = useMemo(\n () => [\n resolvedSwitchStyles.handle,\n switchStaticStyles.handle,\n variantLayerStyles.handle,\n scaleDimensions(resolvedSwitchStyles.handle as ViewStyle),\n animatedHandleStyle,\n ],\n [resolvedSwitchStyles.handle, variantLayerStyles.handle, scaleDimensions, animatedHandleStyle],\n );\n\n const accessibilityLabel = typeof label === 'string' ? label : undefined;\n const resolvedAccessibilityHint = accessibilityHint ?? 'Double tap to toggle';\n\n const labelContent = label && (\n <FormLabel\n color=\"inherit\"\n variant=\"inherit\"\n label={label}\n required={required}\n showRequiredAsterisk={required}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={[resolvedSwitchStyles.text, variantLayerStyles.text]}\n />\n );\n\n const a11yValue = useMemo(() => ({ text: isOn ? 'On' : 'Off' }), [isOn]);\n\n return (\n <Pressable\n ref={ref}\n onPress={handlePress}\n disabled={disabled}\n accessible\n accessibilityRole=\"switch\"\n accessibilityState={{ checked: isOn, disabled }}\n accessibilityLabel={accessibilityLabel}\n accessibilityHint={resolvedAccessibilityHint}\n accessibilityValue={a11yValue}\n {...viewProps}\n style={rootStyle}\n >\n {labelPosition === 'start' && labelContent}\n\n <Animated.View style={trackStyle} importantForAccessibility=\"no-hide-descendants\">\n <Animated.View style={handleStyle}>\n {onIcon && isOn && (\n <Animated.View style={switchStaticStyles.iconContainer}>\n <IconSlot\n icon={onIcon}\n variant=\"fill\"\n dangerouslySetSize={scaledHandleIconSize}\n allowFontScaling={false}\n style={[resolvedSwitchStyles.handleIcon, variantLayerStyles.handleIcon]}\n />\n </Animated.View>\n )}\n {offIcon && !isOn && (\n <Animated.View style={switchStaticStyles.iconContainer}>\n <IconSlot\n icon={offIcon}\n variant=\"fill\"\n dangerouslySetSize={scaledHandleIconSize}\n allowFontScaling={false}\n style={[resolvedSwitchStyles.handleIcon, variantLayerStyles.handleIcon]}\n />\n </Animated.View>\n )}\n </Animated.View>\n </Animated.View>\n\n {labelPosition === 'end' && labelContent}\n </Pressable>\n );\n});\n\nSwitch.displayName = 'Switch';\n\nconst switchStaticStyles = StyleSheet.create((theme) => ({\n handle: {\n borderRadius: theme.borderRadius.full,\n alignItems: 'center',\n justifyContent: 'center',\n },\n iconContainer: {\n position: 'absolute',\n alignItems: 'center',\n justifyContent: 'center',\n },\n track: {\n justifyContent: 'center',\n borderRadius: theme.borderRadius.full,\n },\n root: ({ disabled }: { disabled: boolean }) => ({\n flexDirection: 'row',\n alignItems: 'center',\n alignSelf: 'flex-start',\n opacity: disabled ? 0.5 : 1,\n }),\n}));\n\nexport { Switch, type SwitchProps };\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmC3B,MAAM,SAAS,KAAK,SAAS,OAAO,EAClC,MAAM,UACN,cAAc,OACd,UACA,OACA,gBAAgB,SAChB,OAAO,MACP,QACA,SACA,WAAW,OACX,UACA,uBACA,mBACA,eAAe,OACf,KACA,GAAG,aACW;CACd,MAAM,eAAe,aAAa,KAAA;CAClC,MAAM,CAAC,cAAc,mBAAmB,SAAS,YAAY;CAC7D,MAAM,CAAC,sBAAsB,2BAA2B,SAAS,MAAM;CACvE,MAAM,OAAO,eAAe,WAAW;CACvC,MAAM,gBAAgB,OAAO,OAAO;CACpC,MAAM,EAAE,UAAU,cAAc;CAGhC,MAAM,gCACJ,yBAAyB,WAAW,sBAAsB,IAAI;CAChE,MAAM,kBAAkB,aAAa,8BAA8B;CAEnE,gBAAgB;EACd,MAAM,qBAAqB,YAAY;GAErC,wBAAwB,MADY,kBAAkB,uBAAuB,CAC/B;;EAEhD,oBAAoB;EAEpB,MAAM,eAAe,kBAAkB,iBACrC,uBACA,wBACD;EACD,aAAa,aAAa,QAAQ;IACjC,EAAE,CAAC;CAGN,MAAM,oBADqB,gBAAgB,uBACI,IAAI;CAEnD,MAAM,WAAW,sBACT,WAAW,OAAO,IAAI,GAAG,EAAE,UAAU,mBAAmB,CAAC,EAC/D,CAAC,MAAM,kBAAkB,CAC1B;CAED,MAAM,cAAc,kBAAkB;EACpC,IAAI,UACF;EAGF,MAAM,WAAW,CAAC;EAElB,IAAI,CAAC,cACH,gBAAgB,SAAS;EAG3B,WAAW,SAAS;IACnB;EAAC;EAAU;EAAM;EAAc;EAAS,CAAC;CAQ5C,MAAM,uBAJsB,aAAa,YAAY;EACnD;EACA,SAAS;EAC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O,mBAAmB;gBACvC,oBAAC,UAAD;OACE,MAAM;OACN,SAAQ;OACR,oBAAoB;OACpB,kBAAkB;OAClB,OAAO,CAAC,qBAAqB,YAAY,mBAAmB,WAAW;OACvE,CAAA;MACY,CAAA,EAEjB,WAAW,CAAC,QACX,oBAAC,SAAS,MAAV;MAAe,OAAO,mBAAmB;gBACvC,oBAAC,UAAD;OACE,MAAM;OACN,SAAQ;OACR,oBAAoB;OACpB,kBAAkB;OAClB,OAAO,CAAC,qBAAqB,YAAY,mBAAmB,WAAW;OACvE,CAAA;MACY,CAAA,CAEJ;;IACF,CAAA;GAEf,kBAAkB,SAAS;GAClB;;EAEd;AAEF,OAAO,cAAc;AAErB,MAAM,qBAAqBA,aAAW,QAAQ,WAAW;CACvD,QAAQ;EACN,cAAc,MAAM,aAAa;EACjC,YAAY;EACZ,gBAAgB;EACjB;CACD,eAAe;EACb,UAAU;EACV,YAAY;EACZ,gBAAgB;EACjB;CACD,OAAO;EACL,gBAAgB;EAChB,cAAc,MAAM,aAAa;EAClC;CACD,OAAO,EAAE,gBAAuC;EAC9C,eAAe;EACf,YAAY;EACZ,WAAW;EACX,SAAS,WAAW,KAAM;EAC3B;CACF,EAAE"}
|
|
1
|
+
{"version":3,"file":"Switch.js","names":["StyleSheet"],"sources":["../../src/components/Switch.tsx"],"sourcesContent":["import type { UniversalSwitchProps } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { memo, useCallback, useEffect, useMemo, useState } from 'react';\nimport type {\n AccessibilityProps,\n StyleProp,\n TextStyle,\n View,\n ViewProps,\n ViewStyle,\n} from 'react-native';\nimport { AccessibilityInfo, I18nManager, Platform, Pressable } from 'react-native';\nimport Animated, { useAnimatedStyle, useDerivedValue, withTiming } from 'react-native-reanimated';\n// eslint-disable-next-line uds/no-use-unistyles -- switch variant layers need concrete web styles\nimport { StyleSheet, useUnistyles } from 'react-native-unistyles';\nimport { useAnimatedVariantColor } from 'react-native-unistyles/reanimated';\n\nimport { switchStyles } from '../../generated/styles';\nimport { useFontScale } from '../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { FormLabel } from './FormLabel';\nimport type { IconSlotType } from './IconSlot';\nimport { IconSlot } from './IconSlot';\n\ninterface SwitchProps extends Omit<ViewProps, 'style'>, UniversalSwitchProps<IconSlotType> {\n /** Ref to the underlying View */\n ref?: Ref<View>;\n /** Callback when the switch value changes */\n onChange?: (value: boolean) => void;\n /** Whether the switch is disabled */\n disabled?: boolean;\n /** Whether the switch is required (shows asterisk with label) */\n required?: boolean;\n /**\n * Caps how far the track, handle, and label grow with the OS text-size\n * setting; all scale by the same factor. Set null to remove the cap;\n * override app-wide via UDSFontScalingProvider.\n * @default 2\n */\n maxFontSizeMultiplier?: number | null;\n /** Accessibility hint describing what happens when activated */\n accessibilityHint?: AccessibilityProps['accessibilityHint'];\n}\n\nconst ANIMATION_DURATION = 120;\n\n/**\n * **Switch component for toggling options**\n *\n * @description\n * A switch (also called a toggle) is a binary on/off input control.\n * It allows users to pick between two clearly opposite choices.\n *\n * @category Form\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Switch } from '@yahoo/uds-mobile/Switch';\n *\n * <Switch label=\"Notifications\" />\n * <Switch isOn={enabled} onChange={setEnabled} label=\"Dark mode\" />\n * <Switch onIcon=\"Check\" offIcon=\"Cross\" label=\"Sync\" />\n * ```\n *\n * @usage\n * - Settings: For toggling preferences on/off\n * - Feature flags: For enabling/disabling features\n * - Immediate effect toggles (no submit button needed)\n *\n * @accessibility\n * - Sets `accessibilityRole=\"switch\"` automatically\n * - Announces on/off state to screen readers\n * - Respects system reduce motion preference\n * - Supports `reduceMotion` prop to disable animations\n *\n * @see {@link Checkbox} for forms with submit actions\n * @see {@link Radio} for single-select options\n */\nconst Switch = memo(function Switch({\n isOn: isOnProp,\n defaultIsOn = false,\n onChange,\n label,\n labelPosition = 'start',\n size = 'md',\n onIcon,\n offIcon,\n disabled = false,\n required,\n maxFontSizeMultiplier,\n accessibilityHint,\n reduceMotion = false,\n ref,\n ...viewProps\n}: SwitchProps) {\n const isControlled = isOnProp !== undefined;\n const [internalIsOn, setInternalIsOn] = useState(defaultIsOn);\n const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);\n const isOn = isControlled ? isOnProp : internalIsOn;\n const activeVariant = isOn ? 'on' : 'off';\n const { theme } = useUnistyles();\n\n // One resolved cap governs track, handle, travel, and label. Android may\n // resolve different nonlinear factors for the label and handle glyph.\n const resolvedMaxFontSizeMultiplier =\n useMaxFontSizeMultiplier('control', maxFontSizeMultiplier) ?? 0;\n // Check system reduced motion preference\n useEffect(() => {\n const checkReducedMotion = async () => {\n const isReduceMotionEnabled = await AccessibilityInfo.isReduceMotionEnabled();\n setPrefersReducedMotion(isReduceMotionEnabled);\n };\n checkReducedMotion();\n\n const subscription = AccessibilityInfo.addEventListener(\n 'reduceMotionChanged',\n setPrefersReducedMotion,\n );\n return () => subscription.remove();\n }, []);\n\n const shouldReduceMotion = reduceMotion || prefersReducedMotion;\n const animationDuration = shouldReduceMotion ? 0 : ANIMATION_DURATION;\n\n const progress = useDerivedValue(\n () => withTiming(isOn ? 1 : 0, { duration: animationDuration }),\n [isOn, animationDuration],\n );\n\n const handlePress = useCallback(() => {\n if (disabled) {\n return;\n }\n\n const newValue = !isOn;\n\n if (!isControlled) {\n setInternalIsOn(newValue);\n }\n\n onChange?.(newValue);\n }, [disabled, isOn, isControlled, onChange]);\n\n // On web, useVariants returns the resolved style object instead of mutating\n // switchStyles in place.\n const variantSwitchStyles = switchStyles.useVariants({\n size,\n variant: activeVariant,\n }) as unknown as typeof switchStyles | undefined;\n const resolvedSwitchStyles = variantSwitchStyles ?? switchStyles;\n const labelBaseSize = resolvedSwitchStyles.text.lineHeight ?? resolvedSwitchStyles.text.fontSize;\n const fontScaleFactor = useFontScale(\n resolvedMaxFontSizeMultiplier,\n typeof labelBaseSize === 'number' ? labelBaseSize : undefined,\n );\n // Size the handle glyph from the configured size layer and the same factor\n // Android would apply to a native glyph of this size.\n const handleIconSize = resolvedSwitchStyles.handleIcon.fontSize;\n const handleIconScaleFactor = useFontScale(\n resolvedMaxFontSizeMultiplier,\n typeof handleIconSize === 'number' ? handleIconSize : undefined,\n );\n const scaledHandleIconSize =\n typeof handleIconSize === 'number'\n ? Math.round(handleIconSize * handleIconScaleFactor)\n : undefined;\n\n // Derive travel from the same rounded metrics used to render the control.\n // Scaling the token travel independently can differ by a pixel at fractional\n // font scales, leaving unequal insets at opposite ends of the track.\n const scaledTrackWidth = Math.round(resolvedSwitchStyles.switch.width * fontScaleFactor);\n const scaledTrackPadding = Math.round(resolvedSwitchStyles.switch.padding * fontScaleFactor);\n const scaledHandleWidth = Math.round(resolvedSwitchStyles.handle.width * fontScaleFactor);\n const scaledHandleTravel = Math.max(\n 0,\n scaledTrackWidth - scaledHandleWidth - scaledTrackPadding * 2,\n );\n // RTL mirrors the track layout but not transforms, so travel flips sign.\n const travelDistance = scaledHandleTravel * (I18nManager.isRTL ? -1 : 1);\n\n const variantLayerStyles = useMemo(() => {\n const components = theme.components as unknown as Record<string, Record<string, unknown>>;\n const getLayerStyle = <TStyle,>(layer: string) =>\n components[`switch/variant/default/active/${activeVariant}/${layer}/rest`] as\n TStyle | undefined;\n\n return {\n handle: getLayerStyle<ViewStyle>('handle'),\n handleIcon: getLayerStyle<TextStyle>('handleIcon'),\n switch: getLayerStyle<ViewStyle>('switch'),\n text: getLayerStyle<TextStyle>('rootText'),\n };\n }, [activeVariant, theme]);\n\n // Get animated track color from design tokens (changes when variant changes)\n const trackBackgroundColor = useAnimatedVariantColor(\n resolvedSwitchStyles.switch,\n 'backgroundColor',\n );\n\n const animatedTrackStyle = useAnimatedStyle(() => {\n 'worklet';\n return {\n backgroundColor: withTiming(trackBackgroundColor.value, { duration: animationDuration }),\n };\n });\n\n const animatedHandleStyle = useAnimatedStyle(() => {\n 'worklet';\n return {\n transform: [{ translateX: progress.value * travelDistance }],\n };\n });\n\n const rootStyle: StyleProp<ViewStyle> = useMemo(\n () => [resolvedSwitchStyles.root, switchStaticStyles.root({ disabled })],\n [resolvedSwitchStyles.root, disabled],\n );\n\n // Track and handle grow by the capped factor so the handle (and its icon)\n // stays contained. Scale the track's inset too so the derived travel lands\n // the handle at the same distance from either end.\n const scaleDimensions = useCallback(\n (style: ViewStyle | undefined): ViewStyle | undefined => {\n if (!style || fontScaleFactor === 1) {\n return undefined;\n }\n const { width, height, padding } = style;\n return typeof width === 'number' && typeof height === 'number'\n ? {\n width: Math.round(width * fontScaleFactor),\n height: Math.round(height * fontScaleFactor),\n ...(typeof padding === 'number' && {\n padding: Math.round(padding * fontScaleFactor),\n }),\n }\n : undefined;\n },\n [fontScaleFactor],\n );\n\n const trackStyle: StyleProp<ViewStyle> = useMemo(\n () => [\n resolvedSwitchStyles.switch,\n switchStaticStyles.track,\n variantLayerStyles.switch,\n scaleDimensions(resolvedSwitchStyles.switch as ViewStyle),\n // On web, the animated variant color hook currently resolves to Unistyles'\n // black fallback, so the concrete variant layer provides the track color.\n Platform.OS !== 'web' && animatedTrackStyle,\n ],\n [resolvedSwitchStyles.switch, variantLayerStyles.switch, scaleDimensions, animatedTrackStyle],\n );\n\n const handleStyle: StyleProp<ViewStyle> = useMemo(\n () => [\n resolvedSwitchStyles.handle,\n switchStaticStyles.handle,\n variantLayerStyles.handle,\n scaleDimensions(resolvedSwitchStyles.handle as ViewStyle),\n animatedHandleStyle,\n ],\n [resolvedSwitchStyles.handle, variantLayerStyles.handle, scaleDimensions, animatedHandleStyle],\n );\n\n const accessibilityLabel = typeof label === 'string' ? label : undefined;\n const resolvedAccessibilityHint = accessibilityHint ?? 'Double tap to toggle';\n\n const labelContent = label && (\n <FormLabel\n color=\"inherit\"\n variant=\"inherit\"\n label={label}\n required={required}\n showRequiredAsterisk={required}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={[resolvedSwitchStyles.text, variantLayerStyles.text]}\n />\n );\n\n const a11yValue = useMemo(() => ({ text: isOn ? 'On' : 'Off' }), [isOn]);\n\n return (\n <Pressable\n ref={ref}\n onPress={handlePress}\n disabled={disabled}\n accessible\n accessibilityRole=\"switch\"\n accessibilityState={{ checked: isOn, disabled }}\n accessibilityLabel={accessibilityLabel}\n accessibilityHint={resolvedAccessibilityHint}\n accessibilityValue={a11yValue}\n {...viewProps}\n style={rootStyle}\n >\n {labelPosition === 'start' && labelContent}\n\n <Animated.View style={trackStyle} importantForAccessibility=\"no-hide-descendants\">\n <Animated.View style={handleStyle}>\n {onIcon && isOn && (\n <Animated.View style={switchStaticStyles.iconContainer}>\n <IconSlot\n icon={onIcon}\n variant=\"fill\"\n dangerouslySetSize={scaledHandleIconSize}\n allowFontScaling={false}\n style={[resolvedSwitchStyles.handleIcon, variantLayerStyles.handleIcon]}\n />\n </Animated.View>\n )}\n {offIcon && !isOn && (\n <Animated.View style={switchStaticStyles.iconContainer}>\n <IconSlot\n icon={offIcon}\n variant=\"fill\"\n dangerouslySetSize={scaledHandleIconSize}\n allowFontScaling={false}\n style={[resolvedSwitchStyles.handleIcon, variantLayerStyles.handleIcon]}\n />\n </Animated.View>\n )}\n </Animated.View>\n </Animated.View>\n\n {labelPosition === 'end' && labelContent}\n </Pressable>\n );\n});\n\nSwitch.displayName = 'Switch';\n\nconst switchStaticStyles = StyleSheet.create((theme) => ({\n handle: {\n borderRadius: theme.borderRadius.full,\n alignItems: 'center',\n justifyContent: 'center',\n },\n iconContainer: {\n position: 'absolute',\n alignItems: 'center',\n justifyContent: 'center',\n },\n track: {\n justifyContent: 'center',\n borderRadius: theme.borderRadius.full,\n },\n root: ({ disabled }: { disabled: boolean }) => ({\n flexDirection: 'row',\n alignItems: 'center',\n alignSelf: 'flex-start',\n opacity: disabled ? 0.5 : 1,\n }),\n}));\n\nexport { Switch, type SwitchProps };\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmC3B,MAAM,SAAS,KAAK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pB,kBAAkB;OAClB,OAAO,CAAC,qBAAqB,YAAY,mBAAmB,WAAW;OACvE,CAAA;MACY,CAAA,EAEjB,WAAW,CAAC,QACX,oBAAC,SAAS,MAAV;MAAe,OAAO,mBAAmB;gBACvC,oBAAC,UAAD;OACE,MAAM;OACN,SAAQ;OACR,oBAAoB;OACpB,kBAAkB;OAClB,OAAO,CAAC,qBAAqB,YAAY,mBAAmB,WAAW;OACvE,CAAA;MACY,CAAA,CAEJ;;IACF,CAAA;GAEf,kBAAkB,SAAS;GAClB;;EAEd;AAEF,OAAO,cAAc;AAErB,MAAM,qBAAqBA,aAAW,QAAQ,WAAW;CACvD,QAAQ;EACN,cAAc,MAAM,aAAa;EACjC,YAAY;EACZ,gBAAgB;EACjB;CACD,eAAe;EACb,UAAU;EACV,YAAY;EACZ,gBAAgB;EACjB;CACD,OAAO;EACL,gBAAgB;EAChB,cAAc,MAAM,aAAa;EAClC;CACD,OAAO,EAAE,gBAAuC;EAC9C,eAAe;EACf,YAAY;EACZ,WAAW;EACX,SAAS,WAAW,KAAM;EAC3B;CACF,EAAE"}
|
|
@@ -50,7 +50,6 @@ const Tab = (0, react.memo)(function Tab({ value, children, startIcon, endIcon,
|
|
|
50
50
|
const { theme } = (0, react_native_unistyles.useUnistyles)();
|
|
51
51
|
const [pressed, setPressed] = (0, react.useState)(false);
|
|
52
52
|
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier) ?? 0;
|
|
53
|
-
const fontScaleFactor = require_fontScaling_useFontScale.useFontScale(resolvedMaxFontSizeMultiplier);
|
|
54
53
|
const selected = !disabled && selectedId === uid;
|
|
55
54
|
const active = selected ? "on" : "off";
|
|
56
55
|
const interaction = pressed ? "pressed" : "rest";
|
|
@@ -76,6 +75,7 @@ const Tab = (0, react.memo)(function Tab({ value, children, startIcon, endIcon,
|
|
|
76
75
|
active,
|
|
77
76
|
interaction
|
|
78
77
|
]);
|
|
78
|
+
const fontScaleFactor = require_fontScaling_useFontScale.useFontScale(resolvedMaxFontSizeMultiplier, (typeof textStyle.lineHeight === "number" ? textStyle.lineHeight : void 0) ?? (typeof textStyle.fontSize === "number" ? textStyle.fontSize : void 0));
|
|
79
79
|
const iconStyle = (0, react.useMemo)(() => require_components_Tabs_tabTheme.getMergedTabLayerStyle(theme, visualVariant, active, "icon", interaction), [
|
|
80
80
|
theme,
|
|
81
81
|
visualVariant,
|
|
@@ -48,7 +48,6 @@ const Tab = memo(function Tab({ value, children, startIcon, endIcon, disabled, s
|
|
|
48
48
|
const { theme } = useUnistyles();
|
|
49
49
|
const [pressed, setPressed] = useState(false);
|
|
50
50
|
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier) ?? 0;
|
|
51
|
-
const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier);
|
|
52
51
|
const selected = !disabled && selectedId === uid;
|
|
53
52
|
const active = selected ? "on" : "off";
|
|
54
53
|
const interaction = pressed ? "pressed" : "rest";
|
|
@@ -74,6 +73,7 @@ const Tab = memo(function Tab({ value, children, startIcon, endIcon, disabled, s
|
|
|
74
73
|
active,
|
|
75
74
|
interaction
|
|
76
75
|
]);
|
|
76
|
+
const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, (typeof textStyle.lineHeight === "number" ? textStyle.lineHeight : void 0) ?? (typeof textStyle.fontSize === "number" ? textStyle.fontSize : void 0));
|
|
77
77
|
const iconStyle = useMemo(() => getMergedTabLayerStyle(theme, visualVariant, active, "icon", interaction), [
|
|
78
78
|
theme,
|
|
79
79
|
visualVariant,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tab.js","names":["RNText","Pressable"],"sources":["../../../src/components/Tabs/Tab.tsx"],"sourcesContent":["import type { UniversalTabProps } from '@yahoo/uds-types';\nimport type { ReactElement, ReactNode } from 'react';\nimport { memo, useCallback, useEffect, useId, useMemo, useState } from 'react';\nimport type { LayoutChangeEvent, PressableProps, TextStyle, ViewStyle } from 'react-native';\nimport { Text as RNText, View } from 'react-native';\n// eslint-disable-next-line uds/no-use-unistyles -- theme.components path lookups for tab layers\nimport { useUnistyles } from 'react-native-unistyles';\n\nimport type { StyleProps } from '../../../generated/styles';\nimport { ResolvedControlFontScalingProvider } from '../../fontScaling/FontScalingContext';\nimport { useFontScale } from '../../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport type { IconSlotType } from '../IconSlot';\nimport { IconSlot } from '../IconSlot';\nimport { Pressable } from '../Pressable';\nimport { useTabSelectionContext, useTabsVisualContext } from './tabsContexts';\nimport { getMergedTabLayerStyle, getTabLayerStyle } from './tabTheme';\n\nconst PRIMARY_TAB_UNDERLINE_HEIGHT = 2;\n\ninterface TabProps\n extends\n Omit<PressableProps, 'children' | 'style' | 'disabled' | 'onPress'>,\n Omit<UniversalTabProps, 'asChild' | 'className' | 'startIcon' | 'endIcon'> {\n children: UniversalTabProps['children'];\n startIcon?: IconSlotType;\n endIcon?: IconSlotType;\n style?: ViewStyle;\n}\n\nconst CLEAR_SELECTION_CHROME: ViewStyle = {\n backgroundColor: 'transparent',\n borderWidth: 0,\n borderColor: 'transparent',\n shadowOpacity: 0,\n elevation: 0,\n boxShadow: [],\n};\n\nfunction TabLabel({\n style,\n maxFontSizeMultiplier,\n children,\n}: {\n style: TextStyle;\n maxFontSizeMultiplier: number;\n children: ReactNode;\n}) {\n if (typeof children === 'string' || typeof children === 'number') {\n return (\n <RNText style={style} maxFontSizeMultiplier={maxFontSizeMultiplier}>\n {children}\n </RNText>\n );\n }\n return (\n <ResolvedControlFontScalingProvider maxFontSizeMultiplier={maxFontSizeMultiplier}>\n {children as ReactElement}\n </ResolvedControlFontScalingProvider>\n );\n}\n\n/**\n * **⚙️ Tab**\n *\n * @description\n * A single selectable tab. Must be used inside {@link TabList} within {@link Tabs}.\n *\n * @category Navigation\n * @platform mobile\n */\nconst Tab = memo(function Tab({\n value,\n children,\n startIcon,\n endIcon,\n disabled,\n style,\n ...pressableRest\n}: TabProps) {\n const generatedId = useId();\n const uid = value ?? `uds-tab-${generatedId}`;\n const { variant: visualVariant, reduceMotion, maxFontSizeMultiplier } = useTabsVisualContext();\n const { selectedId, setSelectedId, registerTab, unregisterTab, setTabLayout } =\n useTabSelectionContext();\n const { theme } = useUnistyles();\n const [pressed, setPressed] = useState(false);\n\n // One capped factor governs the label, icons, and the tab's fixed height.\n const resolvedMaxFontSizeMultiplier =\n useMaxFontSizeMultiplier('control', maxFontSizeMultiplier) ?? 0;\n const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier);\n\n const selected = !disabled && selectedId === uid;\n const active: 'on' | 'off' = selected ? 'on' : 'off';\n const interaction: 'rest' | 'pressed' = pressed ? 'pressed' : 'rest';\n\n useEffect(() => {\n registerTab(uid);\n return () => {\n unregisterTab(uid);\n };\n }, [uid, registerTab, unregisterTab]);\n\n const rootBase = useMemo(\n () => getMergedTabLayerStyle(theme, visualVariant, active, 'root', interaction) as ViewStyle,\n [theme, visualVariant, active, interaction],\n );\n const textStyle = useMemo(\n () =>\n getMergedTabLayerStyle(theme, visualVariant, active, 'rootText', interaction) as TextStyle,\n [theme, visualVariant, active, interaction],\n );\n const iconStyle = useMemo(\n () => getMergedTabLayerStyle(theme, visualVariant, active, 'icon', interaction) as TextStyle,\n [theme, visualVariant, active, interaction],\n );\n\n const iconColor = ((): StyleProps['color'] | undefined => {\n const c = iconStyle?.color;\n if (c === undefined || c === null) {\n return undefined;\n }\n return c as StyleProps['color'];\n })();\n\n /** Inactive primary tabs use transparent underline tokens on web; RN has no CSS vars for that layer. */\n const showPrimaryPerTabUnderline = visualVariant === 'primary' && !(selected && !reduceMotion);\n\n const primaryUnderlineColor = useMemo(() => {\n if (visualVariant !== 'primary') {\n return undefined;\n }\n if (selected && reduceMotion) {\n const onText = getTabLayerStyle(theme, 'primary', 'on', 'rootText', 'rest') as TextStyle;\n const c = onText.color;\n if (typeof c === 'string') {\n return c;\n }\n }\n return 'transparent';\n }, [visualVariant, selected, reduceMotion, theme]);\n\n const rootStyle = useMemo((): ViewStyle => {\n const base: ViewStyle = {\n ...rootBase,\n flexDirection: 'row',\n alignItems: 'center',\n flexShrink: 0,\n zIndex: 1,\n position: 'relative',\n };\n // A fixed token height grows with the capped label so text never clips.\n if (fontScaleFactor !== 1 && typeof base.height === 'number') {\n base.height = Math.round(base.height * fontScaleFactor);\n }\n if (selected && !reduceMotion) {\n return { ...base, ...CLEAR_SELECTION_CHROME };\n }\n return base;\n }, [rootBase, fontScaleFactor, selected, reduceMotion]);\n\n const onLayout = useCallback(\n (e: LayoutChangeEvent) => {\n setTabLayout(uid, e.nativeEvent.layout);\n },\n [uid, setTabLayout],\n );\n\n const onPress = useCallback(() => {\n if (disabled) {\n return;\n }\n setSelectedId(uid);\n }, [disabled, setSelectedId, uid]);\n\n return (\n <Pressable\n accessibilityRole=\"tab\"\n accessibilityState={{ selected, disabled: !!disabled }}\n disabled={disabled}\n onPress={onPress}\n onPressIn={() => setPressed(true)}\n onPressOut={() => setPressed(false)}\n onLayout={onLayout}\n style={[rootStyle, style]}\n {...pressableRest}\n >\n {startIcon ? (\n <IconSlot\n icon={startIcon}\n size=\"sm\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={iconStyle}\n {...(iconColor !== undefined ? { color: iconColor } : {})}\n />\n ) : null}\n <TabLabel style={textStyle} maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}>\n {children}\n </TabLabel>\n {endIcon ? (\n <IconSlot\n icon={endIcon}\n size=\"sm\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={iconStyle}\n {...(iconColor !== undefined ? { color: iconColor } : {})}\n />\n ) : null}\n {showPrimaryPerTabUnderline &&\n primaryUnderlineColor &&\n primaryUnderlineColor !== 'transparent' ? (\n <View\n accessibilityElementsHidden\n importantForAccessibility=\"no-hide-descendants\"\n pointerEvents=\"none\"\n style={{\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n height: PRIMARY_TAB_UNDERLINE_HEIGHT,\n backgroundColor: primaryUnderlineColor,\n }}\n />\n ) : null}\n </Pressable>\n );\n});\n\nTab.displayName = 'Tab';\n\nexport { Tab };\nexport type { TabProps };\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAM,+BAA+B;AAYrC,MAAM,yBAAoC;CACxC,iBAAiB;CACjB,aAAa;CACb,aAAa;CACb,eAAe;CACf,WAAW;CACX,WAAW,EAAE;CACd;AAED,SAAS,SAAS,EAChB,OACA,uBACA,YAKC;CACD,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,UACtD,OACE,oBAACA,MAAD;EAAe;EAA8B;EAC1C;EACM,CAAA;CAGb,OACE,oBAAC,oCAAD;EAA2D;EACxD;EACkC,CAAA;;;;;;;;;;;AAazC,MAAM,MAAM,KAAK,SAAS,IAAI,EAC5B,OACA,UACA,WACA,SACA,UACA,OACA,GAAG,iBACQ;CACX,MAAM,cAAc,OAAO;CAC3B,MAAM,MAAM,SAAS,WAAW;CAChC,MAAM,EAAE,SAAS,eAAe,cAAc,0BAA0B,sBAAsB;CAC9F,MAAM,EAAE,YAAY,eAAe,aAAa,eAAe,iBAC7D,wBAAwB;CAC1B,MAAM,EAAE,UAAU,cAAc;CAChC,MAAM,CAAC,SAAS,cAAc,SAAS,MAAM;CAG7C,MAAM,gCACJ,yBAAyB,WAAW,sBAAsB,IAAI;CAChE,MAAM,kBAAkB,aAAa,8BAA8B;CAEnE,MAAM,WAAW,CAAC,YAAY,eAAe;CAC7C,MAAM,SAAuB,WAAW,OAAO;CAC/C,MAAM,cAAkC,UAAU,YAAY;CAE9D,gBAAgB;EACd,YAAY,IAAI;EAChB,aAAa;GACX,cAAc,IAAI;;IAEnB;EAAC;EAAK;EAAa;EAAc,CAAC;CAErC,MAAM,WAAW,cACT,uBAAuB,OAAO,eAAe,QAAQ,QAAQ,YAAY,EAC/E;EAAC;EAAO;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,CAAC,CAAC;GAAU;EAC5C;EACD;EACT,iBAAiB,WAAW,KAAK;EACjC,kBAAkB,WAAW,MAAM;EACzB;EACV,OAAO,CAAC,WAAW,MAAM;EACzB,GAAI;YATN;GAWG,YACC,oBAAC,UAAD;IACE,MAAM;IACN,MAAK;IACL,uBAAuB;IACvB,OAAO;IACP,GAAK,cAAc,KAAA,IAAY,EAAE,OAAO,WAAW,GAAG,EAAE;IACxD,CAAA,GACA;GACJ,oBAAC,UAAD;IAAU,OAAO;IAAW,uBAAuB;IAChD;IACQ,CAAA;GACV,UACC,oBAAC,UAAD;IACE,MAAM;IACN,MAAK;IACL,uBAAuB;IACvB,OAAO;IACP,GAAK,cAAc,KAAA,IAAY,EAAE,OAAO,WAAW,GAAG,EAAE;IACxD,CAAA,GACA;GACH,8BACD,yBACA,0BAA0B,gBACxB,oBAAC,MAAD;IACE,6BAAA;IACA,2BAA0B;IAC1B,eAAc;IACd,OAAO;KACL,UAAU;KACV,MAAM;KACN,OAAO;KACP,QAAQ;KACR,QAAQ;KACR,iBAAiB;KAClB;IACD,CAAA,GACA;GACM;;EAEd;AAEF,IAAI,cAAc"}
|
|
1
|
+
{"version":3,"file":"Tab.js","names":["RNText","Pressable"],"sources":["../../../src/components/Tabs/Tab.tsx"],"sourcesContent":["import type { UniversalTabProps } from '@yahoo/uds-types';\nimport type { ReactElement, ReactNode } from 'react';\nimport { memo, useCallback, useEffect, useId, useMemo, useState } from 'react';\nimport type { LayoutChangeEvent, PressableProps, TextStyle, ViewStyle } from 'react-native';\nimport { Text as RNText, View } from 'react-native';\n// eslint-disable-next-line uds/no-use-unistyles -- theme.components path lookups for tab layers\nimport { useUnistyles } from 'react-native-unistyles';\n\nimport type { StyleProps } from '../../../generated/styles';\nimport { ResolvedControlFontScalingProvider } from '../../fontScaling/FontScalingContext';\nimport { useFontScale } from '../../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport type { IconSlotType } from '../IconSlot';\nimport { IconSlot } from '../IconSlot';\nimport { Pressable } from '../Pressable';\nimport { useTabSelectionContext, useTabsVisualContext } from './tabsContexts';\nimport { getMergedTabLayerStyle, getTabLayerStyle } from './tabTheme';\n\nconst PRIMARY_TAB_UNDERLINE_HEIGHT = 2;\n\ninterface TabProps\n extends\n Omit<PressableProps, 'children' | 'style' | 'disabled' | 'onPress'>,\n Omit<UniversalTabProps, 'asChild' | 'className' | 'startIcon' | 'endIcon'> {\n children: UniversalTabProps['children'];\n startIcon?: IconSlotType;\n endIcon?: IconSlotType;\n style?: ViewStyle;\n}\n\nconst CLEAR_SELECTION_CHROME: ViewStyle = {\n backgroundColor: 'transparent',\n borderWidth: 0,\n borderColor: 'transparent',\n shadowOpacity: 0,\n elevation: 0,\n boxShadow: [],\n};\n\nfunction TabLabel({\n style,\n maxFontSizeMultiplier,\n children,\n}: {\n style: TextStyle;\n maxFontSizeMultiplier: number;\n children: ReactNode;\n}) {\n if (typeof children === 'string' || typeof children === 'number') {\n return (\n <RNText style={style} maxFontSizeMultiplier={maxFontSizeMultiplier}>\n {children}\n </RNText>\n );\n }\n return (\n <ResolvedControlFontScalingProvider maxFontSizeMultiplier={maxFontSizeMultiplier}>\n {children as ReactElement}\n </ResolvedControlFontScalingProvider>\n );\n}\n\n/**\n * **⚙️ Tab**\n *\n * @description\n * A single selectable tab. Must be used inside {@link TabList} within {@link Tabs}.\n *\n * @category Navigation\n * @platform mobile\n */\nconst Tab = memo(function Tab({\n value,\n children,\n startIcon,\n endIcon,\n disabled,\n style,\n ...pressableRest\n}: TabProps) {\n const generatedId = useId();\n const uid = value ?? `uds-tab-${generatedId}`;\n const { variant: visualVariant, reduceMotion, maxFontSizeMultiplier } = useTabsVisualContext();\n const { selectedId, setSelectedId, registerTab, unregisterTab, setTabLayout } =\n useTabSelectionContext();\n const { theme } = useUnistyles();\n const [pressed, setPressed] = useState(false);\n\n // One capped factor governs the label, icons, and the tab's fixed height.\n const resolvedMaxFontSizeMultiplier =\n useMaxFontSizeMultiplier('control', maxFontSizeMultiplier) ?? 0;\n\n const selected = !disabled && selectedId === uid;\n const active: 'on' | 'off' = selected ? 'on' : 'off';\n const interaction: 'rest' | 'pressed' = pressed ? 'pressed' : 'rest';\n\n useEffect(() => {\n registerTab(uid);\n return () => {\n unregisterTab(uid);\n };\n }, [uid, registerTab, unregisterTab]);\n\n const rootBase = useMemo(\n () => getMergedTabLayerStyle(theme, visualVariant, active, 'root', interaction) as ViewStyle,\n [theme, visualVariant, active, interaction],\n );\n const textStyle = useMemo(\n () =>\n getMergedTabLayerStyle(theme, visualVariant, active, 'rootText', interaction) as TextStyle,\n [theme, visualVariant, active, interaction],\n );\n const fontScaleFactor = useFontScale(\n resolvedMaxFontSizeMultiplier,\n (typeof textStyle.lineHeight === 'number' ? textStyle.lineHeight : undefined) ??\n (typeof textStyle.fontSize === 'number' ? textStyle.fontSize : undefined),\n );\n const iconStyle = useMemo(\n () => getMergedTabLayerStyle(theme, visualVariant, active, 'icon', interaction) as TextStyle,\n [theme, visualVariant, active, interaction],\n );\n\n const iconColor = ((): StyleProps['color'] | undefined => {\n const c = iconStyle?.color;\n if (c === undefined || c === null) {\n return undefined;\n }\n return c as StyleProps['color'];\n })();\n\n /** Inactive primary tabs use transparent underline tokens on web; RN has no CSS vars for that layer. */\n const showPrimaryPerTabUnderline = visualVariant === 'primary' && !(selected && !reduceMotion);\n\n const primaryUnderlineColor = useMemo(() => {\n if (visualVariant !== 'primary') {\n return undefined;\n }\n if (selected && reduceMotion) {\n const onText = getTabLayerStyle(theme, 'primary', 'on', 'rootText', 'rest') as TextStyle;\n const c = onText.color;\n if (typeof c === 'string') {\n return c;\n }\n }\n return 'transparent';\n }, [visualVariant, selected, reduceMotion, theme]);\n\n const rootStyle = useMemo((): ViewStyle => {\n const base: ViewStyle = {\n ...rootBase,\n flexDirection: 'row',\n alignItems: 'center',\n flexShrink: 0,\n zIndex: 1,\n position: 'relative',\n };\n // A fixed token height grows with the capped label so text never clips.\n if (fontScaleFactor !== 1 && typeof base.height === 'number') {\n base.height = Math.round(base.height * fontScaleFactor);\n }\n if (selected && !reduceMotion) {\n return { ...base, ...CLEAR_SELECTION_CHROME };\n }\n return base;\n }, [rootBase, fontScaleFactor, selected, reduceMotion]);\n\n const onLayout = useCallback(\n (e: LayoutChangeEvent) => {\n setTabLayout(uid, e.nativeEvent.layout);\n },\n [uid, setTabLayout],\n );\n\n const onPress = useCallback(() => {\n if (disabled) {\n return;\n }\n setSelectedId(uid);\n }, [disabled, setSelectedId, uid]);\n\n return (\n <Pressable\n accessibilityRole=\"tab\"\n accessibilityState={{ selected, disabled: !!disabled }}\n disabled={disabled}\n onPress={onPress}\n onPressIn={() => setPressed(true)}\n onPressOut={() => setPressed(false)}\n onLayout={onLayout}\n style={[rootStyle, style]}\n {...pressableRest}\n >\n {startIcon ? (\n <IconSlot\n icon={startIcon}\n size=\"sm\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={iconStyle}\n {...(iconColor !== undefined ? { color: iconColor } : {})}\n />\n ) : null}\n <TabLabel style={textStyle} maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}>\n {children}\n </TabLabel>\n {endIcon ? (\n <IconSlot\n icon={endIcon}\n size=\"sm\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={iconStyle}\n {...(iconColor !== undefined ? { color: iconColor } : {})}\n />\n ) : null}\n {showPrimaryPerTabUnderline &&\n primaryUnderlineColor &&\n primaryUnderlineColor !== 'transparent' ? (\n <View\n accessibilityElementsHidden\n importantForAccessibility=\"no-hide-descendants\"\n pointerEvents=\"none\"\n style={{\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n height: PRIMARY_TAB_UNDERLINE_HEIGHT,\n backgroundColor: primaryUnderlineColor,\n }}\n />\n ) : null}\n </Pressable>\n );\n});\n\nTab.displayName = 'Tab';\n\nexport { Tab };\nexport type { TabProps };\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAM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;GAWG,YACC,oBAAC,UAAD;IACE,MAAM;IACN,MAAK;IACL,uBAAuB;IACvB,OAAO;IACP,GAAK,cAAc,KAAA,IAAY,EAAE,OAAO,WAAW,GAAG,EAAE;IACxD,CAAA,GACA;GACJ,oBAAC,UAAD;IAAU,OAAO;IAAW,uBAAuB;IAChD;IACQ,CAAA;GACV,UACC,oBAAC,UAAD;IACE,MAAM;IACN,MAAK;IACL,uBAAuB;IACvB,OAAO;IACP,GAAK,cAAc,KAAA,IAAY,EAAE,OAAO,WAAW,GAAG,EAAE;IACxD,CAAA,GACA;GACH,8BACD,yBACA,0BAA0B,gBACxB,oBAAC,MAAD;IACE,6BAAA;IACA,2BAA0B;IAC1B,eAAc;IACd,OAAO;KACL,UAAU;KACV,MAAM;KACN,OAAO;KACP,QAAQ;KACR,QAAQ;KACR,iBAAiB;KAClB;IACD,CAAA,GACA;GACM;;EAEd;AAEF,IAAI,cAAc"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region src/fontScaling/androidNonlinearFontScaling.ts
|
|
4
|
+
/**
|
|
5
|
+
* Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`
|
|
6
|
+
* is only the user's preference; multiplying by it directly does not reproduce the
|
|
7
|
+
* size that native Text renders.
|
|
8
|
+
*
|
|
9
|
+
* These lookup tables mirror Android's `FontScaleConverterFactory`. Values between
|
|
10
|
+
* table entries are linearly interpolated, as they are in the platform implementation.
|
|
11
|
+
*
|
|
12
|
+
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java
|
|
13
|
+
*/
|
|
14
|
+
const COMMON_SP_SIZES = [
|
|
15
|
+
8,
|
|
16
|
+
10,
|
|
17
|
+
12,
|
|
18
|
+
14,
|
|
19
|
+
18,
|
|
20
|
+
20,
|
|
21
|
+
24,
|
|
22
|
+
30,
|
|
23
|
+
100
|
|
24
|
+
];
|
|
25
|
+
const ANDROID_FONT_SCALE_CURVES = [
|
|
26
|
+
{
|
|
27
|
+
scale: 1.05,
|
|
28
|
+
dp: [
|
|
29
|
+
8.4,
|
|
30
|
+
10.5,
|
|
31
|
+
12.6,
|
|
32
|
+
14.8,
|
|
33
|
+
18.6,
|
|
34
|
+
20.6,
|
|
35
|
+
24.4,
|
|
36
|
+
30,
|
|
37
|
+
100
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
scale: 1.1,
|
|
42
|
+
dp: [
|
|
43
|
+
8.8,
|
|
44
|
+
11,
|
|
45
|
+
13.2,
|
|
46
|
+
15.6,
|
|
47
|
+
19.2,
|
|
48
|
+
21.2,
|
|
49
|
+
24.8,
|
|
50
|
+
30,
|
|
51
|
+
100
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
scale: 1.15,
|
|
56
|
+
dp: [
|
|
57
|
+
9.2,
|
|
58
|
+
11.5,
|
|
59
|
+
13.8,
|
|
60
|
+
16.4,
|
|
61
|
+
19.8,
|
|
62
|
+
21.8,
|
|
63
|
+
25.2,
|
|
64
|
+
30,
|
|
65
|
+
100
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
scale: 1.2,
|
|
70
|
+
dp: [
|
|
71
|
+
9.6,
|
|
72
|
+
12,
|
|
73
|
+
14.4,
|
|
74
|
+
17.2,
|
|
75
|
+
20.4,
|
|
76
|
+
22.4,
|
|
77
|
+
25.6,
|
|
78
|
+
30,
|
|
79
|
+
100
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
scale: 1.3,
|
|
84
|
+
dp: [
|
|
85
|
+
10.4,
|
|
86
|
+
13,
|
|
87
|
+
15.6,
|
|
88
|
+
18.8,
|
|
89
|
+
21.6,
|
|
90
|
+
23.6,
|
|
91
|
+
26.4,
|
|
92
|
+
30,
|
|
93
|
+
100
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
scale: 1.5,
|
|
98
|
+
dp: [
|
|
99
|
+
12,
|
|
100
|
+
15,
|
|
101
|
+
18,
|
|
102
|
+
22,
|
|
103
|
+
24,
|
|
104
|
+
26,
|
|
105
|
+
28,
|
|
106
|
+
30,
|
|
107
|
+
100
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
scale: 1.8,
|
|
112
|
+
dp: [
|
|
113
|
+
14.4,
|
|
114
|
+
18,
|
|
115
|
+
21.6,
|
|
116
|
+
24.4,
|
|
117
|
+
27.6,
|
|
118
|
+
30.8,
|
|
119
|
+
32.8,
|
|
120
|
+
34.8,
|
|
121
|
+
100
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
scale: 2,
|
|
126
|
+
dp: [
|
|
127
|
+
16,
|
|
128
|
+
20,
|
|
129
|
+
24,
|
|
130
|
+
26,
|
|
131
|
+
30,
|
|
132
|
+
34,
|
|
133
|
+
36,
|
|
134
|
+
38,
|
|
135
|
+
100
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
function lerp(start, end, amount) {
|
|
140
|
+
return start + (end - start) * amount;
|
|
141
|
+
}
|
|
142
|
+
function interpolateSize(fontSize, dpValues) {
|
|
143
|
+
if (fontSize <= 0) return fontSize;
|
|
144
|
+
for (let index = 0; index < COMMON_SP_SIZES.length; index += 1) {
|
|
145
|
+
const currentSp = COMMON_SP_SIZES[index];
|
|
146
|
+
if (fontSize === currentSp) return dpValues[index];
|
|
147
|
+
if (fontSize < currentSp) {
|
|
148
|
+
const previousSp = index === 0 ? 0 : COMMON_SP_SIZES[index - 1];
|
|
149
|
+
const previousDp = index === 0 ? 0 : dpValues[index - 1];
|
|
150
|
+
const amount = (fontSize - previousSp) / (currentSp - previousSp);
|
|
151
|
+
return lerp(previousDp, dpValues[index], amount);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const lastIndex = COMMON_SP_SIZES.length - 1;
|
|
155
|
+
return fontSize * (dpValues[lastIndex] / COMMON_SP_SIZES[lastIndex]);
|
|
156
|
+
}
|
|
157
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
158
|
+
function convertAndroidSpToDp(fontSize, fontScale) {
|
|
159
|
+
const firstCurve = ANDROID_FONT_SCALE_CURVES[0];
|
|
160
|
+
const lastCurve = ANDROID_FONT_SCALE_CURVES[ANDROID_FONT_SCALE_CURVES.length - 1];
|
|
161
|
+
if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) return fontSize * fontScale;
|
|
162
|
+
for (let index = 0; index < ANDROID_FONT_SCALE_CURVES.length; index += 1) {
|
|
163
|
+
const curve = ANDROID_FONT_SCALE_CURVES[index];
|
|
164
|
+
if (fontScale === curve.scale) return interpolateSize(fontSize, curve.dp);
|
|
165
|
+
if (fontScale < curve.scale) {
|
|
166
|
+
const previousCurve = ANDROID_FONT_SCALE_CURVES[index - 1];
|
|
167
|
+
const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);
|
|
168
|
+
return lerp(interpolateSize(fontSize, previousCurve.dp), interpolateSize(fontSize, curve.dp), amount);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return fontSize * fontScale;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
exports.convertAndroidSpToDp = convertAndroidSpToDp;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/fontScaling/androidNonlinearFontScaling.d.ts
|
|
3
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
4
|
+
declare function convertAndroidSpToDp(fontSize: number, fontScale: number): number;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { convertAndroidSpToDp };
|
|
7
|
+
//# sourceMappingURL=androidNonlinearFontScaling.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.d.cts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;iBAmDS,oBAAA,CAAqB,QAAA,UAAkB,SAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/fontScaling/androidNonlinearFontScaling.d.ts
|
|
3
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
4
|
+
declare function convertAndroidSpToDp(fontSize: number, fontScale: number): number;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { convertAndroidSpToDp };
|
|
7
|
+
//# sourceMappingURL=androidNonlinearFontScaling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.d.ts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;iBAmDS,oBAAA,CAAqB,QAAA,UAAkB,SAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
//#region src/fontScaling/androidNonlinearFontScaling.ts
|
|
3
|
+
/**
|
|
4
|
+
* Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`
|
|
5
|
+
* is only the user's preference; multiplying by it directly does not reproduce the
|
|
6
|
+
* size that native Text renders.
|
|
7
|
+
*
|
|
8
|
+
* These lookup tables mirror Android's `FontScaleConverterFactory`. Values between
|
|
9
|
+
* table entries are linearly interpolated, as they are in the platform implementation.
|
|
10
|
+
*
|
|
11
|
+
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java
|
|
12
|
+
*/
|
|
13
|
+
const COMMON_SP_SIZES = [
|
|
14
|
+
8,
|
|
15
|
+
10,
|
|
16
|
+
12,
|
|
17
|
+
14,
|
|
18
|
+
18,
|
|
19
|
+
20,
|
|
20
|
+
24,
|
|
21
|
+
30,
|
|
22
|
+
100
|
|
23
|
+
];
|
|
24
|
+
const ANDROID_FONT_SCALE_CURVES = [
|
|
25
|
+
{
|
|
26
|
+
scale: 1.05,
|
|
27
|
+
dp: [
|
|
28
|
+
8.4,
|
|
29
|
+
10.5,
|
|
30
|
+
12.6,
|
|
31
|
+
14.8,
|
|
32
|
+
18.6,
|
|
33
|
+
20.6,
|
|
34
|
+
24.4,
|
|
35
|
+
30,
|
|
36
|
+
100
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
scale: 1.1,
|
|
41
|
+
dp: [
|
|
42
|
+
8.8,
|
|
43
|
+
11,
|
|
44
|
+
13.2,
|
|
45
|
+
15.6,
|
|
46
|
+
19.2,
|
|
47
|
+
21.2,
|
|
48
|
+
24.8,
|
|
49
|
+
30,
|
|
50
|
+
100
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
scale: 1.15,
|
|
55
|
+
dp: [
|
|
56
|
+
9.2,
|
|
57
|
+
11.5,
|
|
58
|
+
13.8,
|
|
59
|
+
16.4,
|
|
60
|
+
19.8,
|
|
61
|
+
21.8,
|
|
62
|
+
25.2,
|
|
63
|
+
30,
|
|
64
|
+
100
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
scale: 1.2,
|
|
69
|
+
dp: [
|
|
70
|
+
9.6,
|
|
71
|
+
12,
|
|
72
|
+
14.4,
|
|
73
|
+
17.2,
|
|
74
|
+
20.4,
|
|
75
|
+
22.4,
|
|
76
|
+
25.6,
|
|
77
|
+
30,
|
|
78
|
+
100
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
scale: 1.3,
|
|
83
|
+
dp: [
|
|
84
|
+
10.4,
|
|
85
|
+
13,
|
|
86
|
+
15.6,
|
|
87
|
+
18.8,
|
|
88
|
+
21.6,
|
|
89
|
+
23.6,
|
|
90
|
+
26.4,
|
|
91
|
+
30,
|
|
92
|
+
100
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
scale: 1.5,
|
|
97
|
+
dp: [
|
|
98
|
+
12,
|
|
99
|
+
15,
|
|
100
|
+
18,
|
|
101
|
+
22,
|
|
102
|
+
24,
|
|
103
|
+
26,
|
|
104
|
+
28,
|
|
105
|
+
30,
|
|
106
|
+
100
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
scale: 1.8,
|
|
111
|
+
dp: [
|
|
112
|
+
14.4,
|
|
113
|
+
18,
|
|
114
|
+
21.6,
|
|
115
|
+
24.4,
|
|
116
|
+
27.6,
|
|
117
|
+
30.8,
|
|
118
|
+
32.8,
|
|
119
|
+
34.8,
|
|
120
|
+
100
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
scale: 2,
|
|
125
|
+
dp: [
|
|
126
|
+
16,
|
|
127
|
+
20,
|
|
128
|
+
24,
|
|
129
|
+
26,
|
|
130
|
+
30,
|
|
131
|
+
34,
|
|
132
|
+
36,
|
|
133
|
+
38,
|
|
134
|
+
100
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
];
|
|
138
|
+
function lerp(start, end, amount) {
|
|
139
|
+
return start + (end - start) * amount;
|
|
140
|
+
}
|
|
141
|
+
function interpolateSize(fontSize, dpValues) {
|
|
142
|
+
if (fontSize <= 0) return fontSize;
|
|
143
|
+
for (let index = 0; index < COMMON_SP_SIZES.length; index += 1) {
|
|
144
|
+
const currentSp = COMMON_SP_SIZES[index];
|
|
145
|
+
if (fontSize === currentSp) return dpValues[index];
|
|
146
|
+
if (fontSize < currentSp) {
|
|
147
|
+
const previousSp = index === 0 ? 0 : COMMON_SP_SIZES[index - 1];
|
|
148
|
+
const previousDp = index === 0 ? 0 : dpValues[index - 1];
|
|
149
|
+
const amount = (fontSize - previousSp) / (currentSp - previousSp);
|
|
150
|
+
return lerp(previousDp, dpValues[index], amount);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const lastIndex = COMMON_SP_SIZES.length - 1;
|
|
154
|
+
return fontSize * (dpValues[lastIndex] / COMMON_SP_SIZES[lastIndex]);
|
|
155
|
+
}
|
|
156
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
157
|
+
function convertAndroidSpToDp(fontSize, fontScale) {
|
|
158
|
+
const firstCurve = ANDROID_FONT_SCALE_CURVES[0];
|
|
159
|
+
const lastCurve = ANDROID_FONT_SCALE_CURVES[ANDROID_FONT_SCALE_CURVES.length - 1];
|
|
160
|
+
if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) return fontSize * fontScale;
|
|
161
|
+
for (let index = 0; index < ANDROID_FONT_SCALE_CURVES.length; index += 1) {
|
|
162
|
+
const curve = ANDROID_FONT_SCALE_CURVES[index];
|
|
163
|
+
if (fontScale === curve.scale) return interpolateSize(fontSize, curve.dp);
|
|
164
|
+
if (fontScale < curve.scale) {
|
|
165
|
+
const previousCurve = ANDROID_FONT_SCALE_CURVES[index - 1];
|
|
166
|
+
const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);
|
|
167
|
+
return lerp(interpolateSize(fontSize, previousCurve.dp), interpolateSize(fontSize, curve.dp), amount);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return fontSize * fontScale;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { convertAndroidSpToDp };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=androidNonlinearFontScaling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.js","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"sourcesContent":["/**\n * Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`\n * is only the user's preference; multiplying by it directly does not reproduce the\n * size that native Text renders.\n *\n * These lookup tables mirror Android's `FontScaleConverterFactory`. Values between\n * table entries are linearly interpolated, as they are in the platform implementation.\n *\n * @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java\n */\nconst COMMON_SP_SIZES = [8, 10, 12, 14, 18, 20, 24, 30, 100] as const;\n\nconst ANDROID_FONT_SCALE_CURVES = [\n { scale: 1.05, dp: [8.4, 10.5, 12.6, 14.8, 18.6, 20.6, 24.4, 30, 100] },\n { scale: 1.1, dp: [8.8, 11, 13.2, 15.6, 19.2, 21.2, 24.8, 30, 100] },\n { scale: 1.15, dp: [9.2, 11.5, 13.8, 16.4, 19.8, 21.8, 25.2, 30, 100] },\n { scale: 1.2, dp: [9.6, 12, 14.4, 17.2, 20.4, 22.4, 25.6, 30, 100] },\n { scale: 1.3, dp: [10.4, 13, 15.6, 18.8, 21.6, 23.6, 26.4, 30, 100] },\n { scale: 1.5, dp: [12, 15, 18, 22, 24, 26, 28, 30, 100] },\n { scale: 1.8, dp: [14.4, 18, 21.6, 24.4, 27.6, 30.8, 32.8, 34.8, 100] },\n { scale: 2, dp: [16, 20, 24, 26, 30, 34, 36, 38, 100] },\n] as const;\n\nfunction lerp(start: number, end: number, amount: number): number {\n return start + (end - start) * amount;\n}\n\nfunction interpolateSize(fontSize: number, dpValues: readonly number[]): number {\n if (fontSize <= 0) {\n return fontSize;\n }\n\n for (let index = 0; index < COMMON_SP_SIZES.length; index += 1) {\n const currentSp = COMMON_SP_SIZES[index];\n if (fontSize === currentSp) {\n return dpValues[index] as number;\n }\n if (fontSize < currentSp) {\n const previousSp = index === 0 ? 0 : COMMON_SP_SIZES[index - 1];\n const previousDp = index === 0 ? 0 : (dpValues[index - 1] as number);\n const amount = (fontSize - previousSp) / (currentSp - previousSp);\n return lerp(previousDp, dpValues[index] as number, amount);\n }\n }\n\n // Android extrapolates beyond the table with the last entry's ratio.\n const lastIndex = COMMON_SP_SIZES.length - 1;\n return fontSize * ((dpValues[lastIndex] as number) / COMMON_SP_SIZES[lastIndex]);\n}\n\n/** Converts an SP value to its Android 14+ nonlinear DP size. */\nfunction convertAndroidSpToDp(fontSize: number, fontScale: number): number {\n const firstCurve = ANDROID_FONT_SCALE_CURVES[0];\n const lastCurve = ANDROID_FONT_SCALE_CURVES[ANDROID_FONT_SCALE_CURVES.length - 1];\n\n // Outside Android's curve range, the platform falls back to a linear table.\n if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) {\n return fontSize * fontScale;\n }\n\n for (let index = 0; index < ANDROID_FONT_SCALE_CURVES.length; index += 1) {\n const curve = ANDROID_FONT_SCALE_CURVES[index];\n if (fontScale === curve.scale) {\n return interpolateSize(fontSize, curve.dp);\n }\n if (fontScale < curve.scale) {\n const previousCurve = ANDROID_FONT_SCALE_CURVES[index - 1];\n const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);\n return lerp(\n interpolateSize(fontSize, previousCurve.dp),\n interpolateSize(fontSize, curve.dp),\n amount,\n );\n }\n }\n\n return fontSize * fontScale;\n}\n\nexport { convertAndroidSpToDp };\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,kBAAkB;CAAC;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;AAE5D,MAAM,4BAA4B;CAChC;EAAE,OAAO;EAAM,IAAI;GAAC;GAAK;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACvE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAK;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACpE;EAAE,OAAO;EAAM,IAAI;GAAC;GAAK;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACvE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAK;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACpE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAM;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACrE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAI;G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,QAAQ,cAAc;GAChF,OAAO,KACL,gBAAgB,UAAU,cAAc,GAAG,EAC3C,gBAAgB,UAAU,MAAM,GAAG,EACnC,OACD;;;CAIL,OAAO,WAAW"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
4
|
+
const require_fontScaling_androidNonlinearFontScaling = require("./androidNonlinearFontScaling.cjs");
|
|
4
5
|
let react = require("react");
|
|
5
6
|
let react_native = require("react-native");
|
|
6
7
|
//#region src/fontScaling/useFontScale.ts
|
|
@@ -12,21 +13,29 @@ function getFontScale() {
|
|
|
12
13
|
return react_native.Dimensions.get("window").fontScale;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
|
-
* The
|
|
16
|
-
* around scaled text (e.g. a checkbox box growing with its
|
|
16
|
+
* The effective scale for `fontSize`, clamped to `[1, cap]`, for sizing
|
|
17
|
+
* containers around scaled text (e.g. a checkbox box growing with its
|
|
18
|
+
* checkmark).
|
|
17
19
|
*
|
|
18
20
|
* `cap` uses the same semantics as `maxFontSizeMultiplier`: a number >= 1
|
|
19
21
|
* caps the scale; `null`, `0`, or `undefined` leave it uncapped. The result
|
|
20
22
|
* is never below 1 so containers never shrink under their token metrics
|
|
21
23
|
* (font scales < 1 shrink text only, as today).
|
|
22
24
|
*
|
|
25
|
+
* Pass the SP size that the geometry accompanies on Android so this mirrors
|
|
26
|
+
* Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy
|
|
27
|
+
* scalar behavior for custom callers that do not know their base size.
|
|
28
|
+
*
|
|
23
29
|
* Subscribes to font-scale changes only — rotation does not re-render, and
|
|
24
30
|
* components re-render solely when the user changes the OS text size.
|
|
25
31
|
*/
|
|
26
|
-
function useFontScale(cap) {
|
|
32
|
+
function useFontScale(cap, fontSize) {
|
|
27
33
|
const fontScale = (0, react.useSyncExternalStore)(subscribe, getFontScale, getFontScale);
|
|
28
34
|
const effectiveCap = typeof cap === "number" && cap >= 1 ? cap : Number.POSITIVE_INFINITY;
|
|
29
|
-
|
|
35
|
+
const cappedFontScale = Math.min(fontScale, effectiveCap);
|
|
36
|
+
const platformVersion = Number(react_native.Platform.Version);
|
|
37
|
+
const nativeScale = react_native.Platform.OS === "android" && platformVersion >= 34 && typeof fontSize === "number" && fontSize > 0 ? require_fontScaling_androidNonlinearFontScaling.convertAndroidSpToDp(fontSize, cappedFontScale) / fontSize : cappedFontScale;
|
|
38
|
+
return Math.max(1, nativeScale);
|
|
30
39
|
}
|
|
31
40
|
//#endregion
|
|
32
41
|
exports.useFontScale = useFontScale;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fontScaling/useFontScale.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
5
|
-
* around scaled text (e.g. a checkbox box growing with its
|
|
4
|
+
* The effective scale for `fontSize`, clamped to `[1, cap]`, for sizing
|
|
5
|
+
* containers around scaled text (e.g. a checkbox box growing with its
|
|
6
|
+
* checkmark).
|
|
6
7
|
*
|
|
7
8
|
* `cap` uses the same semantics as `maxFontSizeMultiplier`: a number >= 1
|
|
8
9
|
* caps the scale; `null`, `0`, or `undefined` leave it uncapped. The result
|
|
9
10
|
* is never below 1 so containers never shrink under their token metrics
|
|
10
11
|
* (font scales < 1 shrink text only, as today).
|
|
11
12
|
*
|
|
13
|
+
* Pass the SP size that the geometry accompanies on Android so this mirrors
|
|
14
|
+
* Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy
|
|
15
|
+
* scalar behavior for custom callers that do not know their base size.
|
|
16
|
+
*
|
|
12
17
|
* Subscribes to font-scale changes only — rotation does not re-render, and
|
|
13
18
|
* components re-render solely when the user changes the OS text size.
|
|
14
19
|
*/
|
|
15
|
-
declare function useFontScale(cap?: number | null): number;
|
|
20
|
+
declare function useFontScale(cap?: number | null, fontSize?: number): number;
|
|
16
21
|
//#endregion
|
|
17
22
|
export { useFontScale };
|
|
18
23
|
//# sourceMappingURL=useFontScale.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFontScale.d.cts","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFontScale.d.cts","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"mappings":";;;;;;;;;;;;;;;;;;;iBAiCS,YAAA,CAAa,GAAA,kBAAqB,QAAA"}
|