|
| 1 | +import type { SkFont } from "@shopify/react-native-skia"; |
| 2 | +import type { SharedValue } from "react-native-reanimated"; |
| 3 | +import type { AnimationBehaviorProps, DigitsProp, Direction, TextAlign } from "../core/types"; |
| 4 | + |
| 5 | +/** Value props, mutually exclusive: provide `value` (JS-driven) or `sharedValue` (worklet-driven), not both. */ |
| 6 | +type SkiaNumberFlowValueProps = |
| 7 | + | { |
| 8 | + /** JS-thread numeric value. Mutually exclusive with sharedValue. */ |
| 9 | + value: number; |
| 10 | + /** Intl.NumberFormatOptions for value formatting */ |
| 11 | + format?: Intl.NumberFormatOptions; |
| 12 | + /** Locale(s) for Intl.NumberFormat */ |
| 13 | + locales?: Intl.LocalesArgument; |
| 14 | + sharedValue?: never; |
| 15 | + } |
| 16 | + | { |
| 17 | + value?: never; |
| 18 | + format?: never; |
| 19 | + locales?: never; |
| 20 | + /** Worklet-driven pre-formatted string. Mutually exclusive with value. */ |
| 21 | + sharedValue: SharedValue<string>; |
| 22 | + }; |
| 23 | + |
| 24 | +interface SkiaNumberFlowBaseProps extends AnimationBehaviorProps { |
| 25 | + /** Force equal-width digits using percentile-based interpolation between min and max digit widths. Equivalent to `fontVariant: ['tabular-nums']` on native components. */ |
| 26 | + tabularNums?: boolean; |
| 27 | + |
| 28 | + /** SkFont instance from useFont(). Required; renders empty until font loads. */ |
| 29 | + font: SkFont | null; |
| 30 | + /** Text color. Accepts a static string or a SharedValue for animated color transitions. Defaults to "#000000". */ |
| 31 | + color?: string | SharedValue<string>; |
| 32 | + /** X position within the Canvas. Defaults to 0. */ |
| 33 | + x?: number; |
| 34 | + /** Y position within the Canvas (baseline). Defaults to 0. */ |
| 35 | + y?: number; |
| 36 | + /** Available width for alignment calculations. Defaults to 0. */ |
| 37 | + width?: number; |
| 38 | + /** Text alignment within the available width. Defaults to "start" (left in LTR, right in RTL). Accepts "start"/"end" for direction-aware alignment. */ |
| 39 | + textAlign?: TextAlign; |
| 40 | + /** Overrides automatic RTL detection from I18nManager.isRTL. Omit to follow the system setting. In sharedValue/scrubbing mode, controls alignment only (bidi visual reordering requires value mode, since the SharedValue string lacks the bidi marks that Intl.NumberFormat embeds). */ |
| 41 | + direction?: Direction; |
| 42 | + /** Static string prepended before the number */ |
| 43 | + prefix?: string; |
| 44 | + /** Static string appended after the number */ |
| 45 | + suffix?: string; |
| 46 | + /** Parent opacity (SharedValue for animation coordination) */ |
| 47 | + opacity?: SharedValue<number>; |
| 48 | + |
| 49 | + /** |
| 50 | + * Per-position digit constraints. Maps integer position (0=ones, 1=tens, ...) |
| 51 | + * to { max: N } where N is the highest digit value (inclusive). |
| 52 | + * Example: { 1: { max: 5 } } for a wheel where tens go 0-5. |
| 53 | + */ |
| 54 | + digits?: DigitsProp; |
| 55 | + |
| 56 | + /** |
| 57 | + * Controls digit width during worklet-driven scrubbing (when sharedValue is active). |
| 58 | + * Value between 0 and 1 representing the percentile between min and max digit width. |
| 59 | + * - 0: use narrowest digit width (tightest, may clip wide digits) |
| 60 | + * - 0.5: use average digit width |
| 61 | + * - 1: use widest digit width (no clipping, but wider spacing) |
| 62 | + * Defaults to 0.75 (75th percentile) for a good balance. |
| 63 | + * Only affects digits; symbols like "." keep their natural width. |
| 64 | + */ |
| 65 | + scrubDigitWidthPercentile?: number; |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * Props for SkiaNumberFlow. |
| 70 | + * Value changes are auto-announced for screen reader users. |
| 71 | + * For VoiceOver/TalkBack focus-based reading, set `accessibilityLabel` on the parent Canvas. |
| 72 | + */ |
| 73 | +export type SkiaNumberFlowProps = SkiaNumberFlowBaseProps & SkiaNumberFlowValueProps; |
| 74 | + |
| 75 | +interface SkiaTimeFlowBaseProps extends AnimationBehaviorProps { |
| 76 | + /** Use 24-hour format. Default: true. Only applies when hours are shown. */ |
| 77 | + is24Hour?: boolean; |
| 78 | + /** Pad hours with leading zero. Default: true. "09:30" vs "9:30". */ |
| 79 | + padHours?: boolean; |
| 80 | + |
| 81 | + /** Force equal-width digits using percentile-based interpolation between min and max digit widths. Equivalent to `fontVariant: ['tabular-nums']` on native components. */ |
| 82 | + tabularNums?: boolean; |
| 83 | + |
| 84 | + /** SkFont instance from useFont(). Required; renders empty until font loads. */ |
| 85 | + font: SkFont | null; |
| 86 | + /** Text color. Accepts a static string or a SharedValue for animated color transitions. Defaults to "#000000". */ |
| 87 | + color?: string | SharedValue<string>; |
| 88 | + /** X position within the Canvas. Defaults to 0. */ |
| 89 | + x?: number; |
| 90 | + /** Y position within the Canvas (baseline). Defaults to 0. */ |
| 91 | + y?: number; |
| 92 | + /** Available width for alignment calculations. Defaults to 0. */ |
| 93 | + width?: number; |
| 94 | + /** Text alignment within the available width. Defaults to "start" (left in LTR, right in RTL). Accepts "start"/"end" for direction-aware alignment. */ |
| 95 | + textAlign?: TextAlign; |
| 96 | + /** Overrides automatic RTL detection from I18nManager.isRTL. Omit to follow the system setting. Controls text alignment only; bidi visual reordering of characters applies to NumberFlow/SkiaNumberFlow, not SkiaTimeFlow. */ |
| 97 | + direction?: Direction; |
| 98 | + /** Parent opacity (SharedValue for animation coordination) */ |
| 99 | + opacity?: SharedValue<number>; |
| 100 | +} |
| 101 | + |
| 102 | +type SkiaTimeFlowValueProps = |
| 103 | + | { |
| 104 | + /** Hours value (0-23). Omit to hide the hours segment. */ |
| 105 | + hours?: number; |
| 106 | + /** Minutes value (0-59). Required when using direct time values. */ |
| 107 | + minutes: number; |
| 108 | + /** Seconds value (0-59). Omit to hide the seconds segment. */ |
| 109 | + seconds?: number; |
| 110 | + /** Centiseconds value (0-99). Omit to hide. Requires seconds to be set. Displayed as ".CC" after seconds. */ |
| 111 | + centiseconds?: number; |
| 112 | + /** Unix timestamp in ms. Extracts hours/minutes/seconds automatically. */ |
| 113 | + timestamp?: number; |
| 114 | + /** Timezone offset in ms for timestamp mode. */ |
| 115 | + timezoneOffset?: number; |
| 116 | + sharedValue?: never; |
| 117 | + } |
| 118 | + | { |
| 119 | + hours?: never; |
| 120 | + minutes?: never; |
| 121 | + seconds?: never; |
| 122 | + centiseconds?: never; |
| 123 | + timestamp?: never; |
| 124 | + timezoneOffset?: never; |
| 125 | + /** Worklet-driven pre-formatted time string (e.g. "14:30", "2:30 PM"). */ |
| 126 | + sharedValue: SharedValue<string>; |
| 127 | + }; |
| 128 | + |
| 129 | +/** |
| 130 | + * Props for SkiaTimeFlow. |
| 131 | + * Value changes are auto-announced for screen reader users. |
| 132 | + * For VoiceOver/TalkBack focus-based reading, set `accessibilityLabel` on the parent Canvas. |
| 133 | + */ |
| 134 | +export type SkiaTimeFlowProps = SkiaTimeFlowBaseProps & SkiaTimeFlowValueProps; |
0 commit comments