react-native-nitro-input 0.3.0 → 0.3.1

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +90 -2
  3. package/android/src/main/cpp/JReflowEngine.cpp +32 -0
  4. package/android/src/main/cpp/JReflowEngine.hpp +13 -0
  5. package/android/src/main/cpp/JRollingEngine.cpp +42 -2
  6. package/android/src/main/cpp/JRollingEngine.hpp +9 -1
  7. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +76 -1
  8. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +88 -0
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextMeasure.kt +25 -0
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +140 -0
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
  12. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +388 -136
  13. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroTextView.kt +868 -0
  14. package/android/src/main/java/com/margelo/nitro/nitroinput/ReflowEngine.kt +21 -0
  15. package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +13 -2
  16. package/cpp/RollingEngine.cpp +92 -8
  17. package/cpp/RollingEngine.hpp +36 -2
  18. package/ios/HybridNitroNumberFormatPlatform.swift +87 -9
  19. package/ios/HybridNitroNumberView.swift +82 -1
  20. package/ios/HybridNitroTextView.swift +134 -0
  21. package/ios/NitroNumberView.swift +368 -135
  22. package/ios/NitroTextView.swift +583 -0
  23. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
  24. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  25. package/lib/commonjs/src/NitroNumber.js +52 -3
  26. package/lib/commonjs/src/NitroText.js +138 -0
  27. package/lib/commonjs/src/NitroTime.js +65 -0
  28. package/lib/commonjs/src/formatProps.js +76 -16
  29. package/lib/commonjs/src/index.js +6 -1
  30. package/lib/commonjs/src/specs/NitroText.nitro.js +2 -0
  31. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
  32. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  33. package/lib/module/src/NitroNumber.js +53 -4
  34. package/lib/module/src/NitroText.js +98 -0
  35. package/lib/module/src/NitroTime.js +29 -0
  36. package/lib/module/src/formatProps.js +76 -17
  37. package/lib/module/src/index.js +2 -0
  38. package/lib/module/src/specs/NitroText.nitro.js +1 -0
  39. package/lib/typescript/src/NitroNumber.d.ts +79 -1
  40. package/lib/typescript/src/NitroText.d.ts +67 -0
  41. package/lib/typescript/src/NitroTime.d.ts +19 -0
  42. package/lib/typescript/src/formatProps.d.ts +30 -4
  43. package/lib/typescript/src/index.d.ts +4 -1
  44. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +67 -0
  45. package/lib/typescript/src/specs/NitroText.nitro.d.ts +60 -0
  46. package/nitro.json +20 -0
  47. package/nitrogen/generated/android/NitroInput+autolinking.cmake +6 -0
  48. package/nitrogen/generated/android/NitroInputOnLoad.cpp +34 -0
  49. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +243 -0
  50. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +40 -0
  51. package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp +58 -0
  52. package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.hpp +64 -0
  53. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +253 -0
  54. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +104 -0
  55. package/nitrogen/generated/android/c++/JNitroNumberShimmerDirection.hpp +61 -0
  56. package/nitrogen/generated/android/c++/JNitroNumberSignDisplay.hpp +67 -0
  57. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +100 -0
  58. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +174 -0
  59. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.hpp +54 -0
  60. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +136 -0
  61. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextMeasureSpec.kt +60 -0
  62. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +179 -0
  63. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberShimmerDirection.kt +24 -0
  64. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberSignDisplay.kt +26 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewManager.kt +96 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewStateUpdater.kt +23 -0
  67. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +34 -0
  68. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +132 -11
  69. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +16 -0
  70. package/nitrogen/generated/ios/NitroInputAutolinking.mm +16 -0
  71. package/nitrogen/generated/ios/NitroInputAutolinking.swift +24 -0
  72. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +146 -0
  73. package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.cpp +11 -0
  74. package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.hpp +90 -0
  75. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.cpp +11 -0
  76. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +233 -0
  77. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +120 -0
  78. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +264 -0
  79. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +20 -0
  80. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +493 -0
  81. package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec.swift +56 -0
  82. package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec_cxx.swift +150 -0
  83. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +75 -0
  84. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +608 -0
  85. package/nitrogen/generated/ios/swift/NitroNumberShimmerDirection.swift +44 -0
  86. package/nitrogen/generated/ios/swift/NitroNumberSignDisplay.swift +52 -0
  87. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +40 -0
  88. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +46 -0
  89. package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.cpp +22 -0
  90. package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.hpp +63 -0
  91. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +62 -0
  92. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +115 -0
  93. package/nitrogen/generated/shared/c++/NitroNumberShimmerDirection.hpp +80 -0
  94. package/nitrogen/generated/shared/c++/NitroNumberSignDisplay.hpp +88 -0
  95. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +40 -0
  96. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +62 -0
  97. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +74 -0
  98. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +149 -0
  99. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
  100. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  101. package/package.json +1 -1
  102. package/src/NitroNumber.tsx +183 -9
  103. package/src/NitroText.tsx +166 -0
  104. package/src/NitroTime.tsx +68 -0
  105. package/src/formatProps.ts +108 -18
  106. package/src/index.ts +5 -0
  107. package/src/specs/NitroNumber.nitro.ts +69 -0
  108. package/src/specs/NitroText.nitro.ts +65 -0
@@ -3,12 +3,14 @@ import { I18nManager, StyleSheet, } from 'react-native';
3
3
  import { callback, getHostComponent, } from 'react-native-nitro-modules';
4
4
  import NitroNumberViewConfig from '../nitrogen/generated/shared/json/NitroNumberViewConfig.json';
5
5
  import { toNumericWeight, toProcessedColor } from './styleHelpers';
6
- import { formatProps } from './formatProps';
6
+ import { compactParts, formatProps } from './formatProps';
7
7
  /**
8
8
  * The raw Nitro host component. Prefer {@link NitroNumber}, which adds
9
9
  * auto-sizing, color/weight conversion and a convenient handle.
10
10
  */
11
11
  export const NativeNitroNumberView = getHostComponent('NitroNumberView', () => NitroNumberViewConfig);
12
+ const EMPTY = [];
13
+ const EMPTY_STRINGS = [];
12
14
  /** Each transition's own timing, used when the props leave it unsaid. */
13
15
  const TRANSITION_DEFAULTS = {
14
16
  roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
@@ -25,7 +27,7 @@ const TRANSITION_DEFAULTS = {
25
27
  * The view sizes itself to its content unless you pass an explicit `width` /
26
28
  * `height` in `style`.
27
29
  */
28
- export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, tabularNums, format, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, onNativeRef, style, ...viewProps }, ref) {
30
+ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, tabularNums, format, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, signDisplay, plusSign, minusSign, prefixColor, suffixColor, fractionColor, fractionFontSize, fractionAlign, digitGlyphs, groupingSizes, digits, continuous, animated, respectReduceMotion, onAnimationStart, onAnimationEnd, onNativeRef, style, ...viewProps }, ref) {
29
31
  const nativeRef = useRef(null);
30
32
  const latestOnNativeRef = useRef(onNativeRef);
31
33
  latestOnNativeRef.current = onNativeRef;
@@ -35,6 +37,10 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
35
37
  latestOnRevealMilestone.current = onRevealMilestone;
36
38
  const latestValue = useRef(value);
37
39
  latestValue.current = value;
40
+ const latestOnAnimationStart = useRef(onAnimationStart);
41
+ latestOnAnimationStart.current = onAnimationStart;
42
+ const latestOnAnimationEnd = useRef(onAnimationEnd);
43
+ latestOnAnimationEnd.current = onAnimationEnd;
38
44
  const [size, setSize] = useState(null);
39
45
  // Nitro callbacks must be wrapped with `callback()` and the wrapper object
40
46
  // has to be referentially stable, otherwise every render re-sets the prop.
@@ -57,6 +63,13 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
57
63
  const onRevealMilestoneCallback = useMemo(() => callback((index, milestone) => {
58
64
  latestOnRevealMilestone.current?.(index, milestone);
59
65
  }), []);
66
+ const onAnimationStartCallback = useMemo(() => callback(() => {
67
+ latestOnAnimationStart.current?.();
68
+ }), []);
69
+ // The figure a compact format rolls is not the value (1.2 for 1,234): report the value.
70
+ const onAnimationEndCallback = useMemo(() => callback((shown) => {
71
+ latestOnAnimationEnd.current?.(compactRef.current ? latestValue.current : shown);
72
+ }), []);
60
73
  // A new array literal each render must not re-set the native prop. Always an
61
74
  // array (empty = no tiers): removing the prop would reach native as `null`,
62
75
  // which Nitro's array parser rejects ("Value is null, expected an Object").
@@ -70,7 +83,7 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
70
83
  jumpTo: (next) => nativeRef.current?.jumpTo(next),
71
84
  animateTo: (next) => nativeRef.current?.animateTo(next),
72
85
  revealTo: (next) => nativeRef.current?.revealTo(next),
73
- getValue: () => nativeRef.current?.value ?? latestValue.current,
86
+ getValue: () => (compactRef.current ? latestValue.current : nativeRef.current?.value ?? latestValue.current),
74
87
  get native() {
75
88
  return nativeRef.current;
76
89
  },
@@ -84,12 +97,48 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
84
97
  // render and had the whole configuration re-applied on every value change.
85
98
  const processedColor = useMemo(() => toProcessedColor(color) ?? Infinity, [color]);
86
99
  const processedShimmerColor = useMemo(() => toProcessedColor(shimmerColor) ?? Infinity, [shimmerColor]);
100
+ const processedShimmerBase = useMemo(() => toProcessedColor(shimmerBaseColor) ?? Infinity, [shimmerBaseColor]);
87
101
  const processedFlashUp = useMemo(() => toProcessedColor(flashUpColor) ?? Infinity, [flashUpColor]);
88
102
  const processedFlashDown = useMemo(() => toProcessedColor(flashDownColor) ?? Infinity, [flashDownColor]);
89
103
  const numericWeight = toNumericWeight(fontWeight) ?? 400;
90
104
  const resolvedFontSize = fontSize ?? 32;
91
105
  const resolvedAffixAlign = affixAlign ?? 'baseline';
92
106
  const derived = format ? formatProps(format) : undefined;
107
+ // Compact notation: "1.2K" rolls the figure 1.2 and swaps the suffix.
108
+ const compact = format && derived?.compact ? compactParts(format, value) : undefined;
109
+ const compactRef = useRef(false);
110
+ compactRef.current = compact !== undefined;
111
+ // Which way the value moved, for a compact figure that fell while the value grew (999 → 1K).
112
+ const previousValue = useRef(value);
113
+ const compactDirection = compact && direction === undefined ? (value >= previousValue.current ? 'up' : 'down') : undefined;
114
+ previousValue.current = value;
115
+ const processedPrefixColor = useMemo(() => toProcessedColor(prefixColor) ?? Infinity, [prefixColor]);
116
+ const processedSuffixColor = useMemo(() => toProcessedColor(suffixColor) ?? Infinity, [suffixColor]);
117
+ const processedFractionColor = useMemo(() => toProcessedColor(fractionColor) ?? Infinity, [fractionColor]);
118
+ // Arrays reach native only when their contents change.
119
+ const digitMaxKey = digits ? JSON.stringify(digits) : '';
120
+ const digitMax = useMemo(() => {
121
+ if (!digits)
122
+ return EMPTY;
123
+ const out = [];
124
+ for (const [position, spec] of Object.entries(digits)) {
125
+ const index = Number(position);
126
+ if (!Number.isInteger(index) || index < 0 || index >= 20)
127
+ continue;
128
+ while (out.length <= index)
129
+ out.push(9);
130
+ out[index] = spec.max;
131
+ }
132
+ return out;
133
+ // eslint-disable-next-line react-hooks/exhaustive-deps
134
+ }, [digitMaxKey]);
135
+ const glyphs = digitGlyphs ?? derived?.digitGlyphs ?? EMPTY_STRINGS;
136
+ const glyphsKey = glyphs.join('|');
137
+ const stableGlyphs = useMemo(() => glyphs, [glyphsKey]); // eslint-disable-line react-hooks/exhaustive-deps
138
+ const groups = groupingSizes ?? derived?.groupingSizes ?? EMPTY;
139
+ const groupsKey = groups.join(',');
140
+ const stableGroups = useMemo(() => groups, [groupsKey]); // eslint-disable-line react-hooks/exhaustive-deps
141
+ const still = animated === false;
93
142
  const autoSize = useMemo(() => size !== null
94
143
  ? { width: size.width, height: size.height }
95
144
  : { height: (fontSize ?? 32) * 1.25 }, [size, fontSize]);
@@ -98,5 +147,5 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
98
147
  // does not hand a Hybrid View its resolved direction, so native is told.
99
148
  const layoutDirection = useMemo(() => StyleSheet.flatten(style)?.direction, [style]);
100
149
  const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && I18nManager.isRTL);
101
- return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: value, fractionDigits: fractionDigits ?? derived?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? derived?.prefix ?? '', suffix: suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
150
+ return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: compact ? compact.value : value, fractionDigits: fractionDigits ?? compact?.fractionDigits ?? derived?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? compact?.prefix ?? derived?.prefix ?? '', suffix: suffix ?? compact?.suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? compactDirection ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: still ? 0 : revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, onAnimationStart: onAnimationStartCallback, onAnimationEnd: onAnimationEndCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, shimmerAngle: shimmerAngle ?? 31, shimmerWidth: shimmerWidth ?? 1, shimmerBaseColor: processedShimmerBase, shimmerDirection: shimmerDirection ?? 'auto', shimmerDelay: shimmerDelay ?? 0, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, signDisplay: signDisplay ?? derived?.signDisplay ?? 'auto', plusSign: plusSign ?? derived?.plusSign ?? '+', minusSign: minusSign ?? derived?.minusSign ?? '-', digitGlyphs: stableGlyphs, groupingSizes: stableGroups, digitMax: digitMax, continuous: continuous ?? false, prefixColor: processedPrefixColor, suffixColor: processedSuffixColor, fractionColor: processedFractionColor, fractionFontSize: fractionFontSize ?? Infinity, fractionAlign: fractionAlign ?? 'baseline', respectReduceMotion: respectReduceMotion ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
102
151
  });
@@ -0,0 +1,98 @@
1
+ import React, { useMemo } from 'react';
2
+ import { I18nManager, PixelRatio, StyleSheet, } from 'react-native';
3
+ import { getHostComponent, NitroModules } from 'react-native-nitro-modules';
4
+ import NitroTextViewConfig from '../nitrogen/generated/shared/json/NitroTextViewConfig.json';
5
+ import { toNumericWeight, toProcessedColor } from './styleHelpers';
6
+ /** The raw Nitro host component behind {@link NitroText}. */
7
+ export const NativeNitroTextView = getHostComponent('NitroTextView', () => NitroTextViewConfig);
8
+ let measurer = null;
9
+ function measure() {
10
+ measurer ??= NitroModules.createHybridObject('NitroTextMeasure');
11
+ return measurer;
12
+ }
13
+ const lineHeights = new Map();
14
+ /**
15
+ * A single line of text that morphs to the next, natively, as Torph does on
16
+ * the web: the characters the two share glide to their new places, digits
17
+ * matched by place ("$1,204" → "$1,318" rolls the hundreds and tens), and the
18
+ * rest fade out and in ("Sign in" → "Signing in…"). At rest it is one line
19
+ * drawn in one pass, like a label: no text field, no layer per character.
20
+ * It sizes itself to its text in the render that mounts it (a native
21
+ * measurement, synchronously); a `width` in `style` overrides it.
22
+ *
23
+ * Only the props that were set go to the native view, as
24
+ * react-native-plain-text does: every prop that crosses is converted and
25
+ * stored per view in the commit, and the native side holds the defaults.
26
+ */
27
+ export function NitroText({ children, fontSize, fontWeight, fontFamily, color, letterSpacing, textAlign, allowFontScaling, maxFontSizeMultiplier, duration, easing, bounce, effect, respectReduceMotion, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, style, ...viewProps }) {
28
+ const text = typeof children === 'string' ? children : String(children);
29
+ const scale = allowFontScaling
30
+ ? maxFontSizeMultiplier && maxFontSizeMultiplier > 0
31
+ ? Math.min(PixelRatio.getFontScale(), maxFontSizeMultiplier)
32
+ : PixelRatio.getFontScale()
33
+ : 1;
34
+ const size = (fontSize ?? 17) * scale;
35
+ const weight = fontWeight === undefined ? 400 : toNumericWeight(fontWeight) ?? 400;
36
+ const family = fontFamily ?? '';
37
+ const spacing = letterSpacing ?? 0;
38
+ const width = useMemo(() => measure().measure(text, size, weight, family, spacing), [text, size, weight, family, spacing]);
39
+ const fontKey = `${size}|${weight}|${family}`;
40
+ let height = lineHeights.get(fontKey);
41
+ if (height === undefined) {
42
+ height = measure().lineHeight(size, weight, family);
43
+ lineHeights.set(fontKey, height);
44
+ }
45
+ const native = viewProps;
46
+ native.text = text;
47
+ native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style];
48
+ if (size !== 17)
49
+ native.fontSize = size;
50
+ if (weight !== 400)
51
+ native.fontWeight = weight;
52
+ if (family !== '')
53
+ native.fontFamily = family;
54
+ if (spacing !== 0)
55
+ native.letterSpacing = spacing;
56
+ const processedColor = toProcessedColor(color);
57
+ if (processedColor !== undefined)
58
+ native.color = processedColor;
59
+ if (textAlign !== undefined)
60
+ native.textAlign = textAlign;
61
+ if (duration !== undefined)
62
+ native.duration = duration;
63
+ if (easing !== undefined)
64
+ native.easing = easing;
65
+ if (bounce !== undefined)
66
+ native.bounce = bounce;
67
+ if (effect !== undefined)
68
+ native.effect = effect;
69
+ if (respectReduceMotion !== undefined)
70
+ native.respectReduceMotion = respectReduceMotion;
71
+ if (loading !== undefined)
72
+ native.loading = loading;
73
+ const processedShimmerColor = toProcessedColor(shimmerColor);
74
+ if (processedShimmerColor !== undefined)
75
+ native.shimmerColor = processedShimmerColor;
76
+ if (shimmerDuration !== undefined)
77
+ native.shimmerDuration = shimmerDuration;
78
+ if (shimmerAngle !== undefined)
79
+ native.shimmerAngle = shimmerAngle;
80
+ if (shimmerWidth !== undefined)
81
+ native.shimmerWidth = shimmerWidth;
82
+ const processedShimmerBaseColor = toProcessedColor(shimmerBaseColor);
83
+ if (processedShimmerBaseColor !== undefined)
84
+ native.shimmerBaseColor = processedShimmerBaseColor;
85
+ if (shimmerDirection !== undefined)
86
+ native.shimmerDirection = shimmerDirection;
87
+ if (shimmerDelay !== undefined)
88
+ native.shimmerDelay = shimmerDelay;
89
+ // The start edge follows the layout direction, the app's unless the style sets one.
90
+ const direction = style == null ? undefined : StyleSheet.flatten(style).direction;
91
+ if (direction === 'rtl' || (direction !== 'ltr' && I18nManager.isRTL))
92
+ native.rightToLeft = true;
93
+ // The native view is the accessibility element, labelled with its text and
94
+ // announced as text. A label from outside takes over, on this view.
95
+ if (native.accessibilityLabel != null && native.accessible === undefined)
96
+ native.accessible = true;
97
+ return React.createElement(NativeNitroTextView, { ...native });
98
+ }
@@ -0,0 +1,29 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { NitroNumber } from './NitroNumber';
3
+ const LAYOUT = {
4
+ 'm:ss': { hours: false, digits: 3 },
5
+ 'mm:ss': { hours: false, digits: 4 },
6
+ 'h:mm:ss': { hours: true, digits: 5 },
7
+ 'hh:mm:ss': { hours: true, digits: 6 },
8
+ };
9
+ // The tens of seconds, and of minutes when hours are shown, wrap after 5.
10
+ const SECONDS = { 1: { max: 5 } };
11
+ const MINUTES_AND_SECONDS = { 1: { max: 5 }, 3: { max: 5 } };
12
+ // One separator before the seconds: 125:00 is 125 minutes, not 1:25:00.
13
+ const MINUTES_ONLY = [2, 0];
14
+ const PAIRS = [2];
15
+ /**
16
+ * A clock, a timer or a countdown: `NitroNumber` with the time as its figure
17
+ * (12:34:56 is 123456), grouped in pairs, and the tens of seconds and minutes
18
+ * wrapping after 5, so 0:59 → 1:00 turns them one step, as a clock's wheels
19
+ * do, instead of rolling back through 4, 3, 2, 1.
20
+ */
21
+ export const NitroTime = forwardRef(function NitroTime({ seconds, timeFormat = 'm:ss', separator = ':', ...props }, ref) {
22
+ const layout = LAYOUT[timeFormat];
23
+ const total = Math.max(0, Math.floor(Number.isFinite(seconds) ? seconds : 0));
24
+ const s = total % 60;
25
+ const value = layout.hours
26
+ ? Math.floor(total / 3600) * 10000 + (Math.floor(total / 60) % 60) * 100 + s
27
+ : Math.floor(total / 60) * 100 + s;
28
+ return (React.createElement(NitroNumber, { ref: ref, value: value, minimumIntegerDigits: layout.digits, groupingSeparator: separator, groupingSizes: layout.hours ? PAIRS : MINUTES_ONLY, digits: layout.hours ? MINUTES_AND_SECONDS : SECONDS, ...props }));
29
+ });
@@ -1,13 +1,34 @@
1
- import { sharedFormatterOf } from './NumberFormat';
1
+ import { NumberFormat, sharedFormatterOf } from './NumberFormat';
2
2
  const NUMBER_PARTS = new Set(['integer', 'group', 'decimal', 'fraction']);
3
3
  // By the native formatter, which instances built with the same locales and options share.
4
4
  const cache = new WeakMap();
5
+ function join(parts, from, to) {
6
+ return parts
7
+ .slice(from, to)
8
+ .map((p) => p.value)
9
+ .join('');
10
+ }
11
+ /** The text before and after the number in `parts`. */
12
+ function affixes(parts) {
13
+ const first = parts.findIndex((p) => NUMBER_PARTS.has(p.type));
14
+ let last = first;
15
+ parts.forEach((p, i) => {
16
+ if (NUMBER_PARTS.has(p.type))
17
+ last = i;
18
+ });
19
+ // The sign is the component's own glyph, not part of an affix.
20
+ const unsigned = (from, to) => join(parts.map((p) => (p.type === 'minusSign' || p.type === 'plusSign' ? { ...p, value: '' } : p)), from, to);
21
+ return {
22
+ prefix: first < 0 ? '' : unsigned(0, first),
23
+ suffix: first < 0 ? '' : unsigned(last + 1, parts.length),
24
+ };
25
+ }
5
26
  /**
6
27
  * The prefix, suffix, separators and digit counts of `format`, read off its
7
28
  * parts once and cached per formatter. The components keep their own model
8
- * (a sign, a prefix, digits grouped in threes, a suffix), so a format outside
9
- * it (Indian grouping, native digits, accounting parentheses) is followed as
10
- * far as that model goes.
29
+ * (a sign, a prefix, digits in groups, a suffix), so a format outside it
30
+ * (accounting parentheses, a unit between the digits) is followed as far as
31
+ * that model goes.
11
32
  */
12
33
  export function formatProps(format) {
13
34
  const key = sharedFormatterOf(format) ?? format;
@@ -15,31 +36,69 @@ export function formatProps(format) {
15
36
  if (cached)
16
37
  return cached;
17
38
  const resolved = format.resolvedOptions();
39
+ const compact = resolved.notation === 'compact';
18
40
  const fractionDigits = resolved.maximumFractionDigits ?? 0;
19
41
  // A value with every part: groups, and a fraction when the format has one.
20
- const parts = format.formatToParts(fractionDigits > 0 ? 1234567.5 : 1234567);
21
- const first = parts.findIndex((p) => NUMBER_PARTS.has(p.type));
22
- let last = first;
23
- parts.forEach((p, i) => {
24
- if (NUMBER_PARTS.has(p.type))
25
- last = i;
26
- });
27
- const text = (from, to) => parts
28
- .slice(from, to)
29
- .map((p) => p.value)
30
- .join('');
42
+ // Compact notation would print it "1.2M", so its affixes come per value.
43
+ const parts = format.formatToParts(compact ? 1 : fractionDigits > 0 ? 1234567.5 : 1234567);
31
44
  const negative = format.formatToParts(-1);
32
45
  const minus = negative.findIndex((p) => p.type === 'minusSign');
33
46
  const currency = negative.findIndex((p) => p.type === 'currency' || p.type === 'percentSign');
47
+ const integers = parts.filter((p) => p.type === 'integer').map((p) => p.value.length);
34
48
  const props = {
35
- prefix: first < 0 ? '' : text(0, first),
36
- suffix: first < 0 ? '' : text(last + 1, parts.length),
49
+ ...affixes(parts),
37
50
  groupingSeparator: parts.find((p) => p.type === 'group')?.value ?? '',
38
51
  decimalSeparator: parts.find((p) => p.type === 'decimal')?.value ?? '.',
39
52
  fractionDigits,
40
53
  minimumIntegerDigits: resolved.minimumIntegerDigits,
41
54
  signPlacement: minus >= 0 && currency >= 0 && minus > currency ? 'afterAffix' : 'beforeAffix',
55
+ signDisplay: (resolved.signDisplay ?? 'auto'),
56
+ minusSign: negative[minus]?.value ?? '-',
57
+ plusSign: '+',
58
+ digitGlyphs: digitGlyphsOf(resolved.locale, resolved.numberingSystem),
59
+ // "12,34,567": the last group is the first size, the one before it every later one.
60
+ groupingSizes: integers.length >= 3 ? [integers[integers.length - 1], integers[integers.length - 2]] : [3],
61
+ compact,
42
62
  };
43
63
  cache.set(key, props);
44
64
  return props;
45
65
  }
66
+ const digitGlyphCache = new Map();
67
+ /** The ten digits of a numbering system, or [] for Latin ones. */
68
+ function digitGlyphsOf(locale, numberingSystem) {
69
+ if (!numberingSystem || numberingSystem === 'latn')
70
+ return [];
71
+ const cached = digitGlyphCache.get(numberingSystem);
72
+ if (cached)
73
+ return cached;
74
+ const digits = new NumberFormat(locale, { numberingSystem, useGrouping: false });
75
+ const glyphs = Array.from({ length: 10 }, (_, d) => digits.format(d));
76
+ const result = glyphs.every((g, d) => g === String(d)) ? [] : glyphs;
77
+ digitGlyphCache.set(numberingSystem, result);
78
+ return result;
79
+ }
80
+ /**
81
+ * Compact notation's parts for `value`: "1.2K" is the figure 1.2 with the
82
+ * suffix "K", so the digits roll and the suffix swaps as the value crosses
83
+ * a thousand, a million…
84
+ */
85
+ export function compactParts(format, value) {
86
+ const parts = format.formatToParts(value);
87
+ const props = formatProps(format);
88
+ const latin = (text) => props.digitGlyphs.length === 10
89
+ ? Array.from(text)
90
+ .map((c) => {
91
+ const d = props.digitGlyphs.indexOf(c);
92
+ return d >= 0 ? String(d) : c;
93
+ })
94
+ .join('')
95
+ : text;
96
+ const integer = latin(parts.filter((p) => p.type === 'integer').map((p) => p.value).join(''));
97
+ const fraction = latin(parts.filter((p) => p.type === 'fraction').map((p) => p.value).join(''));
98
+ const magnitude = Number(fraction ? `${integer}.${fraction}` : integer);
99
+ return {
100
+ value: (value < 0 ? -1 : 1) * (Number.isFinite(magnitude) ? magnitude : 0),
101
+ fractionDigits: fraction.length,
102
+ ...affixes(parts),
103
+ };
104
+ }
@@ -2,4 +2,6 @@ export { NitroInput, NativeNitroInputView, } from './NitroInput';
2
2
  export { isWorklet, } from './worklets';
3
3
  export { useNitroInputState, } from './useNitroInputState';
4
4
  export { NitroNumber, NativeNitroNumberView, } from './NitroNumber';
5
+ export { NitroTime } from './NitroTime';
6
+ export { NitroText, NativeNitroTextView } from './NitroText';
5
7
  export { NumberFormat } from './NumberFormat';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { type ColorValue, type TextStyle, type ViewProps } from 'react-native';
3
3
  import { type HybridRef } from 'react-native-nitro-modules';
4
- import type { NitroNumberAffixAlign, NitroNumberDirection, NitroNumberTransition, NitroNumberEasing, NitroNumberMethods, NitroNumberProps as NativeNitroNumberProps, NitroNumberRevealStyle, NitroNumberTextAlign } from './specs/NitroNumber.nitro';
4
+ import type { NitroNumberAffixAlign, NitroNumberDirection, NitroNumberTransition, NitroNumberEasing, NitroNumberMethods, NitroNumberProps as NativeNitroNumberProps, NitroNumberRevealStyle, NitroNumberShimmerDirection, NitroNumberSignDisplay, NitroNumberTextAlign } from './specs/NitroNumber.nitro';
5
5
  import type { NumberFormat } from './NumberFormat';
6
6
  /**
7
7
  * The raw Nitro host component. Prefer {@link NitroNumber}, which adds
@@ -139,6 +139,19 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
139
139
  shimmerColor?: ColorValue;
140
140
  /** Duration of one sweep in ms (linear, repeating). Default: `950`. */
141
141
  shimmerDuration?: number;
142
+ /** The band's slant in degrees: 0 upright, positive leans it like "/", negative the other way. Default: `31`. */
143
+ shimmerAngle?: number;
144
+ /** The band's width as a fraction of the number's: `0.5` is a narrow glint. Default: `1`. */
145
+ shimmerWidth?: number;
146
+ /**
147
+ * The glyphs' colour outside the band while loading: a light grey makes the
148
+ * figure a skeleton that the band lights up. Default: `color`.
149
+ */
150
+ shimmerBaseColor?: ColorValue;
151
+ /** Which way the band sweeps. Default: `'auto'`, the layout direction. */
152
+ shimmerDirection?: NitroNumberShimmerDirection;
153
+ /** A pause after each sweep, in ms. Default: `0`. */
154
+ shimmerDelay?: number;
142
155
  /** Font size of the digits in points. Default: `32`. */
143
156
  fontSize?: number;
144
157
  /** Font size of `prefix`, e.g. a smaller currency symbol. Defaults to `fontSize`. */
@@ -213,6 +226,71 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
213
226
  * `'left'` and `'right'` are absolute.
214
227
  */
215
228
  textAlign?: NitroNumberTextAlign;
229
+ /**
230
+ * Which values carry a sign, as `Intl.NumberFormat`'s `signDisplay`:
231
+ * `'always'` and `'exceptZero'` put a plus on gains ("+$12.40"), and a plus
232
+ * that turns into a minus swaps like any other glyph. A value that rounds to
233
+ * zero at the shown fraction digits counts as zero. Default: `'auto'`
234
+ * (negatives), or the `format`'s.
235
+ */
236
+ signDisplay?: NitroNumberSignDisplay;
237
+ /** The glyph drawn for a plus sign. Default: `'+'`. */
238
+ plusSign?: string;
239
+ /** The glyph drawn for a minus sign, e.g. `'−'` (U+2212). Default: `'-'`, or the `format` locale's. */
240
+ minusSign?: string;
241
+ /** The prefix's color. Default: `color`. */
242
+ prefixColor?: ColorValue;
243
+ /** The suffix's color. Default: `color`. */
244
+ suffixColor?: ColorValue;
245
+ /** The fraction digits' and decimal separator's color: dimmer cents. Default: `color`. */
246
+ fractionColor?: ColorValue;
247
+ /** The fraction digits' and decimal separator's size: smaller cents. Default: `fontSize`. */
248
+ fractionFontSize?: number;
249
+ /**
250
+ * How smaller fraction digits line up with the integer ones: `'baseline'`,
251
+ * or `'top'` for superscript cents ("$12⁹⁹"). Default: `'baseline'`.
252
+ */
253
+ fractionAlign?: NitroNumberAffixAlign;
254
+ /**
255
+ * The ten glyphs drawn for 0 to 9, for native digits (Arabic-Indic,
256
+ * Devanagari…). Default: `'0'`…`'9'`, or the `format`'s numbering system.
257
+ */
258
+ digitGlyphs?: string[];
259
+ /**
260
+ * Digit group sizes counted from the decimal point: the first group, then
261
+ * every later one. `[3, 2]` is Indian grouping (12,34,567), `[2]` a clock
262
+ * (12:34:56 with `groupingSeparator=":"`). Default: `[3]`, or the `format`'s.
263
+ */
264
+ groupingSizes?: number[];
265
+ /**
266
+ * The highest digit a position shows before it wraps to 0, keyed by integer
267
+ * position (0 the ones, 1 the tens…), as NumberFlow's `digits`:
268
+ * `{ 1: { max: 5 } }` makes the tens of a clock's seconds wrap after 5, so
269
+ * 59 → 00 turns them one step instead of five back.
270
+ */
271
+ digits?: Record<number, {
272
+ max: number;
273
+ }>;
274
+ /**
275
+ * Rolls turn the wheels below the highest one that changes a full turn too,
276
+ * so 100 → 200 seems to pass through every value between. Rolls only.
277
+ * Default: `false`.
278
+ */
279
+ continuous?: boolean;
280
+ /**
281
+ * `false` shows every change at once, without a roll or a reveal (the flash
282
+ * and the pop still play). Default: `true`.
283
+ */
284
+ animated?: boolean;
285
+ /** Snap instead of animating while the system's Reduce Motion is on. Default: `true`. */
286
+ respectReduceMotion?: boolean;
287
+ /** Called when the figure starts moving from rest: a change, or a reveal. */
288
+ onAnimationStart?: () => void;
289
+ /**
290
+ * Called when the figure comes to rest, with the value it shows: once for a
291
+ * run of changes that arrived while it was moving. Snapped changes fire neither.
292
+ */
293
+ onAnimationEnd?: (value: number) => void;
216
294
  /** Receives the native Nitro object once the view is mounted. */
217
295
  onNativeRef?: (ref: NitroNumberRef) => void;
218
296
  }
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import { type ColorValue, type TextStyle, type ViewProps } from 'react-native';
3
+ import type { NitroTextMethods, NitroTextProps as NativeNitroTextProps } from './specs/NitroText.nitro';
4
+ import type { NitroInputEasing, NitroInputEffect } from './specs/NitroInput.nitro';
5
+ import type { NitroNumberShimmerDirection, NitroNumberTextAlign } from './specs/NitroNumber.nitro';
6
+ /** The raw Nitro host component behind {@link NitroText}. */
7
+ export declare const NativeNitroTextView: import("react-native-nitro-modules").ReactNativeView<NativeNitroTextProps, NitroTextMethods>;
8
+ /** What a {@link NitroText} takes: the text, its typography, the morph's timing and the loading shimmer. */
9
+ export interface NitroTextProps extends Omit<ViewProps, 'children'> {
10
+ /** The text: a string or a number. A change morphs to it. */
11
+ children: string | number;
12
+ /** Default: `17`. */
13
+ fontSize?: number;
14
+ /** Like `Text`'s. Default: `'normal'`. */
15
+ fontWeight?: TextStyle['fontWeight'];
16
+ /** Defaults to the system font. */
17
+ fontFamily?: string;
18
+ /** Defaults to the platform's label colour. */
19
+ color?: ColorValue;
20
+ /** Points after every character. Default: `0`. */
21
+ letterSpacing?: number;
22
+ /** Where the line sits in a wider view. Default: `'auto'`, the start edge. */
23
+ textAlign?: NitroNumberTextAlign;
24
+ /** Scale with the system text size, like `Text`. Default: `false`. */
25
+ allowFontScaling?: boolean;
26
+ /** Cap for `allowFontScaling`; `0` is none. Default: `0`. */
27
+ maxFontSizeMultiplier?: number;
28
+ /** Of a morph, in ms; `0` switches at once. Default: `400`. */
29
+ duration?: number;
30
+ /** Default: `'expo'`. */
31
+ easing?: NitroInputEasing;
32
+ /** Overshoot of the `'spring'` easing. Default: `0.15`. */
33
+ bounce?: number;
34
+ /** How characters enter and leave: `'auto'` slides digits and fades letters. Default: `'auto'`. */
35
+ effect?: NitroInputEffect;
36
+ /** Snap instead of morphing while Reduce Motion is on. Default: `true`. */
37
+ respectReduceMotion?: boolean;
38
+ /** A loading glint through the text, as `NitroNumber`'s `loading`. Default: `false`. */
39
+ loading?: boolean;
40
+ shimmerColor?: ColorValue;
41
+ /** ms per sweep. Default: `950`. */
42
+ shimmerDuration?: number;
43
+ /** Degrees; 0 upright. Default: `31`. */
44
+ shimmerAngle?: number;
45
+ /** A fraction of the text's width. Default: `1`. */
46
+ shimmerWidth?: number;
47
+ /** The glyphs' colour outside the band: a skeleton. Default: `color`. */
48
+ shimmerBaseColor?: ColorValue;
49
+ /** Default: `'auto'`, the layout direction. */
50
+ shimmerDirection?: NitroNumberShimmerDirection;
51
+ /** ms of pause after each sweep. Default: `0`. */
52
+ shimmerDelay?: number;
53
+ }
54
+ /**
55
+ * A single line of text that morphs to the next, natively, as Torph does on
56
+ * the web: the characters the two share glide to their new places, digits
57
+ * matched by place ("$1,204" → "$1,318" rolls the hundreds and tens), and the
58
+ * rest fade out and in ("Sign in" → "Signing in…"). At rest it is one line
59
+ * drawn in one pass, like a label: no text field, no layer per character.
60
+ * It sizes itself to its text in the render that mounts it (a native
61
+ * measurement, synchronously); a `width` in `style` overrides it.
62
+ *
63
+ * Only the props that were set go to the native view, as
64
+ * react-native-plain-text does: every prop that crosses is converted and
65
+ * stored per view in the commit, and the native side holds the defaults.
66
+ */
67
+ export declare function NitroText({ children, fontSize, fontWeight, fontFamily, color, letterSpacing, textAlign, allowFontScaling, maxFontSizeMultiplier, duration, easing, bounce, effect, respectReduceMotion, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, style, ...viewProps }: NitroTextProps): React.JSX.Element;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { type NitroNumberHandle, type NitroNumberProps } from './NitroNumber';
3
+ /** How a {@link NitroTime} lays the time out. */
4
+ export type NitroTimeFormat = 'm:ss' | 'mm:ss' | 'h:mm:ss' | 'hh:mm:ss';
5
+ export interface NitroTimeProps extends Omit<NitroNumberProps, 'value' | 'digits' | 'groupingSizes' | 'groupingSeparator' | 'minimumIntegerDigits' | 'fractionDigits' | 'decimalSeparator' | 'format'> {
6
+ /** The time in whole seconds (a timer's elapsed time, a countdown's remaining one). Negatives show as 0. */
7
+ seconds: number;
8
+ /** Default: `'m:ss'`. Without hours the minutes run past 59 (125:00). */
9
+ timeFormat?: NitroTimeFormat;
10
+ /** Between the fields. Default: `':'`. */
11
+ separator?: string;
12
+ }
13
+ /**
14
+ * A clock, a timer or a countdown: `NitroNumber` with the time as its figure
15
+ * (12:34:56 is 123456), grouped in pairs, and the tens of seconds and minutes
16
+ * wrapping after 5, so 0:59 → 1:00 turns them one step, as a clock's wheels
17
+ * do, instead of rolling back through 4, 3, 2, 1.
18
+ */
19
+ export declare const NitroTime: React.ForwardRefExoticComponent<NitroTimeProps & React.RefAttributes<NitroNumberHandle>>;
@@ -1,4 +1,4 @@
1
- import { type NumberFormat } from './NumberFormat';
1
+ import { NumberFormat } from './NumberFormat';
2
2
  /** What `NitroNumber` and `NitroInput` take from a `NumberFormat` through their `format` prop. */
3
3
  export interface FormatProps {
4
4
  prefix: string;
@@ -10,12 +10,38 @@ export interface FormatProps {
10
10
  minimumIntegerDigits: number;
11
11
  /** Whether a negative amount's sign comes before the prefix ("-$5") or after it ("$-5"). */
12
12
  signPlacement: 'beforeAffix' | 'afterAffix';
13
+ /** Which values carry a sign, as the format's `signDisplay`. */
14
+ signDisplay: 'auto' | 'always' | 'exceptZero' | 'negative' | 'never';
15
+ /** The minus sign the locale writes ("-", or "−" in Swedish and Finnish). */
16
+ minusSign: string;
17
+ /** The plus sign the locale writes. */
18
+ plusSign: string;
19
+ /** The glyphs for 0…9 in the format's numbering system; empty for Latin digits. */
20
+ digitGlyphs: string[];
21
+ /** The first digit group and every later one, from the decimal point ([3, 2]: 12,34,567). */
22
+ groupingSizes: number[];
23
+ /** Compact notation: the prefix, suffix and digits follow the value (`compactParts`). */
24
+ compact: boolean;
13
25
  }
14
26
  /**
15
27
  * The prefix, suffix, separators and digit counts of `format`, read off its
16
28
  * parts once and cached per formatter. The components keep their own model
17
- * (a sign, a prefix, digits grouped in threes, a suffix), so a format outside
18
- * it (Indian grouping, native digits, accounting parentheses) is followed as
19
- * far as that model goes.
29
+ * (a sign, a prefix, digits in groups, a suffix), so a format outside it
30
+ * (accounting parentheses, a unit between the digits) is followed as far as
31
+ * that model goes.
20
32
  */
21
33
  export declare function formatProps(format: NumberFormat): FormatProps;
34
+ /** What a compact format shows for one value: the figure to roll and the text around it. */
35
+ export interface CompactParts {
36
+ /** The figure as the digits show it: 1.2 for "1.2K". */
37
+ value: number;
38
+ fractionDigits: number;
39
+ prefix: string;
40
+ suffix: string;
41
+ }
42
+ /**
43
+ * Compact notation's parts for `value`: "1.2K" is the figure 1.2 with the
44
+ * suffix "K", so the digits roll and the suffix swaps as the value crosses
45
+ * a thousand, a million…
46
+ */
47
+ export declare function compactParts(format: NumberFormat, value: number): CompactParts;
@@ -4,6 +4,9 @@ export { useNitroInputState, type NitroInputState, type SharedValueLike, } from
4
4
  export type { NitroInputLabelBehavior, NitroInputMode, NitroInputNotation, NitroInputVariant, NitroInputEasing, NitroInputEffect, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputAffixAlign, NitroInputSignPlacement, NitroInputKeyboardType, NitroInputReturnKeyType, NitroInputAutoCapitalize, NitroInputSubmitBehavior, NitroInputKeyboardAppearance, NitroInputMethods, NitroInputProps as NativeNitroInputProps, NitroInputView, } from './specs/NitroInput.nitro';
5
5
  export type { NitroInputWorklets } from './specs/NitroInputWorklets.nitro';
6
6
  export { NitroNumber, NativeNitroNumberView, type NitroNumberProps, type NitroNumberHandle, type NitroNumberRef, } from './NitroNumber';
7
- export type { NitroNumberAffixAlign, NitroNumberDirection, NitroNumberTransition, NitroNumberEasing, NitroNumberRevealStyle, NitroNumberTextAlign, NitroNumberMethods, NitroNumberProps as NativeNitroNumberProps, NitroNumberView, } from './specs/NitroNumber.nitro';
7
+ export { NitroTime, type NitroTimeProps, type NitroTimeFormat } from './NitroTime';
8
+ export { NitroText, NativeNitroTextView, type NitroTextProps } from './NitroText';
9
+ export type { NitroTextMeasure, NitroTextView } from './specs/NitroText.nitro';
10
+ export type { NitroNumberAffixAlign, NitroNumberDirection, NitroNumberTransition, NitroNumberEasing, NitroNumberRevealStyle, NitroNumberShimmerDirection, NitroNumberSignDisplay, NitroNumberTextAlign, NitroNumberMethods, NitroNumberProps as NativeNitroNumberProps, NitroNumberView, } from './specs/NitroNumber.nitro';
8
11
  export { NumberFormat, type NumberFormatConstructor, type NumberFormatRangePart } from './NumberFormat';
9
12
  export type { NumberFormatOptions, NumberFormatPart, ResolvedNumberFormatOptions, NumberFormatStyle, NumberFormatCurrencyDisplay, NumberFormatCurrencySign, NumberFormatUnitDisplay, NumberFormatNotation, NumberFormatCompactDisplay, NumberFormatSignDisplay, NumberFormatRoundingMode, NumberFormatRoundingPriority, NumberFormatTrailingZeroDisplay, NumberFormatGrouping, } from './specs/NumberFormat.nitro';