react-native-nitro-input 0.1.0 → 0.3.0

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 (221) hide show
  1. package/CHANGELOG.md +343 -3
  2. package/NitroInput.podspec +4 -4
  3. package/README.md +420 -53
  4. package/android/CMakeLists.txt +9 -3
  5. package/android/gradle.properties +1 -1
  6. package/android/src/main/cpp/JOutlineGeometry.hpp +1 -1
  7. package/android/src/main/cpp/JReflowEngine.cpp +132 -0
  8. package/android/src/main/cpp/{JMorphEngine.hpp → JReflowEngine.hpp} +7 -7
  9. package/android/src/main/cpp/JRollingEngine.cpp +223 -0
  10. package/android/src/main/cpp/JRollingEngine.hpp +68 -0
  11. package/android/src/main/cpp/cpp-adapter.cpp +4 -2
  12. package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +1 -1
  13. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +21 -1
  14. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +209 -0
  15. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +496 -0
  16. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
  17. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +107 -26
  18. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1881 -0
  19. package/android/src/main/java/com/margelo/nitro/nitroinput/{MorphEngine.kt → ReflowEngine.kt} +2 -2
  20. package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +60 -0
  21. package/cpp/AmountFormatter.cpp +5 -0
  22. package/cpp/AmountFormatter.hpp +10 -2
  23. package/cpp/{MorphEngine.cpp → ReflowEngine.cpp} +52 -47
  24. package/cpp/{MorphEngine.hpp → ReflowEngine.hpp} +12 -4
  25. package/cpp/RollingEngine.cpp +1234 -0
  26. package/cpp/RollingEngine.hpp +475 -0
  27. package/cpp/SwiftNonCopyable.hpp +22 -0
  28. package/cpp/numberformat/HybridNitroNumberFormat.cpp +498 -0
  29. package/cpp/numberformat/HybridNitroNumberFormat.hpp +74 -0
  30. package/cpp/numberformat/HybridNitroNumberFormatFactory.hpp +11 -0
  31. package/cpp/numberformat/NumberFormatCore.cpp +629 -0
  32. package/cpp/numberformat/NumberFormatCore.hpp +154 -0
  33. package/cpp/numberformat/NumberFormatProbe.cpp +354 -0
  34. package/cpp/numberformat/NumberFormatProbe.hpp +63 -0
  35. package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
  36. package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
  37. package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +16 -1
  38. package/ios/HybridNitroNumberFormatPlatform.swift +348 -0
  39. package/ios/HybridNitroNumberView.swift +458 -0
  40. package/ios/NitroInputView.swift +148 -64
  41. package/ios/NitroNumberView.swift +2074 -0
  42. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
  43. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +61 -0
  44. package/lib/commonjs/src/NitroInput.js +27 -56
  45. package/lib/commonjs/src/NitroNumber.js +141 -0
  46. package/lib/commonjs/src/NumberFormat.js +525 -0
  47. package/lib/commonjs/src/formatProps.js +48 -0
  48. package/lib/commonjs/src/index.js +6 -3
  49. package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
  50. package/lib/commonjs/src/specs/NumberFormat.nitro.js +2 -0
  51. package/lib/commonjs/src/styleHelpers.js +36 -0
  52. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
  53. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +61 -0
  54. package/lib/module/src/NitroInput.js +18 -47
  55. package/lib/module/src/NitroNumber.js +102 -0
  56. package/lib/module/src/NumberFormat.js +521 -0
  57. package/lib/module/src/formatProps.js +45 -0
  58. package/lib/module/src/index.js +2 -1
  59. package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
  60. package/lib/module/src/specs/NumberFormat.nitro.js +1 -0
  61. package/lib/module/src/styleHelpers.js +32 -0
  62. package/lib/typescript/src/NitroInput.d.ts +50 -21
  63. package/lib/typescript/src/NitroNumber.d.ts +246 -0
  64. package/lib/typescript/src/NumberFormat.d.ts +47 -0
  65. package/lib/typescript/src/formatProps.d.ts +21 -0
  66. package/lib/typescript/src/index.d.ts +5 -2
  67. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +19 -9
  68. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +250 -0
  69. package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +139 -0
  70. package/lib/typescript/src/styleHelpers.d.ts +3 -0
  71. package/nitro.json +26 -0
  72. package/nitrogen/generated/android/NitroInput+autolinking.cmake +10 -0
  73. package/nitrogen/generated/android/NitroInputOnLoad.cpp +48 -0
  74. package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
  75. package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +10 -10
  76. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +45 -0
  77. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +10 -0
  78. package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.cpp +118 -0
  79. package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.hpp +64 -0
  80. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +590 -0
  81. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +168 -0
  82. package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.cpp +65 -0
  83. package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.hpp +64 -0
  84. package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
  85. package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +64 -0
  86. package/nitrogen/generated/android/c++/JNitroNumberEasing.hpp +67 -0
  87. package/nitrogen/generated/android/c++/JNitroNumberRevealStyle.hpp +58 -0
  88. package/nitrogen/generated/android/c++/JNitroNumberTextAlign.hpp +64 -0
  89. package/nitrogen/generated/android/c++/JNitroNumberTransition.hpp +61 -0
  90. package/nitrogen/generated/android/c++/JNumberFormatCompactDisplay.hpp +58 -0
  91. package/nitrogen/generated/android/c++/JNumberFormatCurrencyDisplay.hpp +64 -0
  92. package/nitrogen/generated/android/c++/JNumberFormatCurrencySign.hpp +58 -0
  93. package/nitrogen/generated/android/c++/JNumberFormatNotation.hpp +64 -0
  94. package/nitrogen/generated/android/c++/JNumberFormatPlatformOptions.hpp +161 -0
  95. package/nitrogen/generated/android/c++/JNumberFormatPlatformSymbols.hpp +89 -0
  96. package/nitrogen/generated/android/c++/JNumberFormatRoundingMode.hpp +79 -0
  97. package/nitrogen/generated/android/c++/JNumberFormatSignDisplay.hpp +67 -0
  98. package/nitrogen/generated/android/c++/JNumberFormatStyle.hpp +64 -0
  99. package/nitrogen/generated/android/c++/JNumberFormatUnitDisplay.hpp +61 -0
  100. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +25 -0
  101. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +329 -0
  102. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.hpp +54 -0
  103. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void.kt +78 -0
  104. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +9 -9
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +30 -0
  106. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatformSpec.kt +60 -0
  107. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +399 -0
  108. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroPlatformNumberFormatterSpec.kt +62 -0
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberAffixAlign.kt +25 -0
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +25 -0
  111. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberEasing.kt +26 -0
  112. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberRevealStyle.kt +23 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTextAlign.kt +25 -0
  114. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTransition.kt +24 -0
  115. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCompactDisplay.kt +23 -0
  116. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencyDisplay.kt +25 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencySign.kt +23 -0
  118. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatNotation.kt +25 -0
  119. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformOptions.kt +136 -0
  120. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformSymbols.kt +91 -0
  121. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatRoundingMode.kt +30 -0
  122. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatSignDisplay.kt +26 -0
  123. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatStyle.kt +25 -0
  124. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatUnitDisplay.kt +24 -0
  125. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewManager.kt +96 -0
  126. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewStateUpdater.kt +23 -0
  127. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +59 -0
  128. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +311 -0
  129. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +63 -0
  130. package/nitrogen/generated/ios/NitroInputAutolinking.mm +26 -0
  131. package/nitrogen/generated/ios/NitroInputAutolinking.swift +24 -0
  132. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +30 -0
  133. package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.cpp +11 -0
  134. package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.hpp +122 -0
  135. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
  136. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +474 -0
  137. package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.cpp +11 -0
  138. package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.hpp +94 -0
  139. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +30 -0
  140. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +450 -0
  141. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  142. package/nitrogen/generated/ios/swift/Func_void_double_double.swift +5 -5
  143. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +5 -0
  144. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +55 -0
  145. package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec.swift +56 -0
  146. package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec_cxx.swift +159 -0
  147. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +108 -0
  148. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1387 -0
  149. package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec.swift +56 -0
  150. package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec_cxx.swift +155 -0
  151. package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
  152. package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +48 -0
  153. package/nitrogen/generated/ios/swift/NitroNumberEasing.swift +52 -0
  154. package/nitrogen/generated/ios/swift/NitroNumberRevealStyle.swift +40 -0
  155. package/nitrogen/generated/ios/swift/NitroNumberTextAlign.swift +48 -0
  156. package/nitrogen/generated/ios/swift/NitroNumberTransition.swift +44 -0
  157. package/nitrogen/generated/ios/swift/NumberFormatCompactDisplay.swift +40 -0
  158. package/nitrogen/generated/ios/swift/NumberFormatCurrencyDisplay.swift +48 -0
  159. package/nitrogen/generated/ios/swift/NumberFormatCurrencySign.swift +40 -0
  160. package/nitrogen/generated/ios/swift/NumberFormatNotation.swift +48 -0
  161. package/nitrogen/generated/ios/swift/NumberFormatPlatformOptions.swift +159 -0
  162. package/nitrogen/generated/ios/swift/NumberFormatPlatformSymbols.swift +69 -0
  163. package/nitrogen/generated/ios/swift/NumberFormatRoundingMode.swift +68 -0
  164. package/nitrogen/generated/ios/swift/NumberFormatSignDisplay.swift +52 -0
  165. package/nitrogen/generated/ios/swift/NumberFormatStyle.swift +48 -0
  166. package/nitrogen/generated/ios/swift/NumberFormatUnitDisplay.swift +44 -0
  167. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +10 -0
  168. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +10 -0
  169. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatFactorySpec.cpp +22 -0
  170. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatFactorySpec.hpp +70 -0
  171. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatPlatformSpec.cpp +22 -0
  172. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatPlatformSpec.hpp +70 -0
  173. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.cpp +23 -0
  174. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.hpp +71 -0
  175. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +127 -0
  176. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +187 -0
  177. package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.cpp +23 -0
  178. package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.hpp +65 -0
  179. package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
  180. package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +84 -0
  181. package/nitrogen/generated/shared/c++/NitroNumberEasing.hpp +88 -0
  182. package/nitrogen/generated/shared/c++/NitroNumberRevealStyle.hpp +76 -0
  183. package/nitrogen/generated/shared/c++/NitroNumberTextAlign.hpp +84 -0
  184. package/nitrogen/generated/shared/c++/NitroNumberTransition.hpp +80 -0
  185. package/nitrogen/generated/shared/c++/NumberFormatCompactDisplay.hpp +76 -0
  186. package/nitrogen/generated/shared/c++/NumberFormatCurrencyDisplay.hpp +84 -0
  187. package/nitrogen/generated/shared/c++/NumberFormatCurrencySign.hpp +76 -0
  188. package/nitrogen/generated/shared/c++/NumberFormatGrouping.hpp +80 -0
  189. package/nitrogen/generated/shared/c++/NumberFormatNotation.hpp +84 -0
  190. package/nitrogen/generated/shared/c++/NumberFormatOptions.hpp +193 -0
  191. package/nitrogen/generated/shared/c++/NumberFormatPart.hpp +87 -0
  192. package/nitrogen/generated/shared/c++/NumberFormatPlatformOptions.hpp +176 -0
  193. package/nitrogen/generated/shared/c++/NumberFormatPlatformSymbols.hpp +115 -0
  194. package/nitrogen/generated/shared/c++/NumberFormatRoundingMode.hpp +104 -0
  195. package/nitrogen/generated/shared/c++/NumberFormatRoundingPriority.hpp +80 -0
  196. package/nitrogen/generated/shared/c++/NumberFormatSignDisplay.hpp +88 -0
  197. package/nitrogen/generated/shared/c++/NumberFormatStyle.hpp +84 -0
  198. package/nitrogen/generated/shared/c++/NumberFormatTrailingZeroDisplay.hpp +76 -0
  199. package/nitrogen/generated/shared/c++/NumberFormatUnitDisplay.hpp +80 -0
  200. package/nitrogen/generated/shared/c++/ResolvedNumberFormatOptions.hpp +197 -0
  201. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +10 -0
  202. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +15 -0
  203. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +136 -0
  204. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +245 -0
  205. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
  206. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +61 -0
  207. package/package.json +15 -7
  208. package/src/NitroInput.tsx +79 -67
  209. package/src/NitroNumber.tsx +531 -0
  210. package/src/NumberFormat.ts +563 -0
  211. package/src/formatProps.ts +59 -0
  212. package/src/index.ts +38 -6
  213. package/src/specs/NitroInput.nitro.ts +19 -9
  214. package/src/specs/NitroNumber.nitro.ts +271 -0
  215. package/src/specs/NumberFormat.nitro.ts +145 -0
  216. package/src/styleHelpers.ts +32 -0
  217. package/android/src/main/cpp/JMorphEngine.cpp +0 -132
  218. package/lib/commonjs/src/MorphInput.js +0 -42
  219. package/lib/module/src/MorphInput.js +0 -6
  220. package/lib/typescript/src/MorphInput.d.ts +0 -18
  221. package/src/MorphInput.tsx +0 -30
@@ -0,0 +1,531 @@
1
+ import React, {
2
+ forwardRef,
3
+ useImperativeHandle,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ } from 'react'
8
+ import {
9
+ I18nManager,
10
+ StyleSheet,
11
+ type ColorValue,
12
+ type TextStyle,
13
+ type ViewProps,
14
+ } from 'react-native'
15
+ import {
16
+ callback,
17
+ getHostComponent,
18
+ type HybridRef,
19
+ } from 'react-native-nitro-modules'
20
+ import NitroNumberViewConfig from '../nitrogen/generated/shared/json/NitroNumberViewConfig.json'
21
+ import type {
22
+ NitroNumberAffixAlign,
23
+ NitroNumberDirection,
24
+ NitroNumberTransition,
25
+ NitroNumberEasing,
26
+ NitroNumberMethods,
27
+ NitroNumberProps as NativeNitroNumberProps,
28
+ NitroNumberRevealStyle,
29
+ NitroNumberTextAlign,
30
+ } from './specs/NitroNumber.nitro'
31
+ import { toNumericWeight, toProcessedColor } from './styleHelpers'
32
+ import { formatProps } from './formatProps'
33
+ import type { NumberFormat } from './NumberFormat'
34
+
35
+ /**
36
+ * The raw Nitro host component. Prefer {@link NitroNumber}, which adds
37
+ * auto-sizing, color/weight conversion and a convenient handle.
38
+ */
39
+ export const NativeNitroNumberView = getHostComponent<
40
+ NativeNitroNumberProps,
41
+ NitroNumberMethods
42
+ >('NitroNumberView', () => NitroNumberViewConfig)
43
+
44
+ /** The native Nitro `HybridObject` behind a mounted {@link NitroNumber}. */
45
+ export type NitroNumberRef = HybridRef<
46
+ NativeNitroNumberProps,
47
+ NitroNumberMethods
48
+ >
49
+
50
+ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
51
+ /**
52
+ * The number to display. Every change rolls each digit natively to its new
53
+ * glyph, in the direction of the change. The first value is shown instantly.
54
+ * At most 18 digits are shown: `|value| × 10^fractionDigits` is clamped at
55
+ * 10^17, and a JS number carries exact integers only up to 2^53.
56
+ */
57
+ value: number
58
+ /** Digits shown after the decimal separator. Default: `0`. */
59
+ fractionDigits?: number
60
+ /** Zero-pads the integer part to at least this many digits. Default: `1`. */
61
+ minimumIntegerDigits?: number
62
+ /** Inserted between every three integer digits (e.g. `','`). Default: none. */
63
+ groupingSeparator?: string
64
+ /** Placed between integer and fraction digits. Default: `'.'`. */
65
+ decimalSeparator?: string
66
+ /** Static text drawn before the number, e.g. `'$'`. */
67
+ prefix?: string
68
+ /** Static text drawn after the number, e.g. `'%'`. */
69
+ suffix?: string
70
+ /**
71
+ * How a value change plays. `'roll'` (default) is the odometer: every
72
+ * changed digit rolls through the digits between its old and new glyph, in
73
+ * the direction of the change. `'numeric'` is the numeric transition, the
74
+ * effect of SwiftUI's `.contentTransition(.numericText())`: each changed
75
+ * glyph swaps in place, the old one softening, shrinking and sliding out
76
+ * while the new one slides in from the other side and comes into focus, the
77
+ * digits cascading from the left; unchanged digits stay put. `'scramble'`
78
+ * shows a different random digit every few frames until each changed digit
79
+ * locks on its target, from the left.
80
+ *
81
+ * Each swap style has its own defaults for `duration`, `easing` and
82
+ * `stagger`: numeric 480 / (its own clocks) / 150, scramble 500 / `'linear'` / 60.
83
+ */
84
+ transition?: NitroNumberTransition
85
+ /**
86
+ * The change flash: every digit whose glyph changes lights up in this
87
+ * colour when the value grew (e.g. a green), stays lit while it moves,
88
+ * and fades back over `flashDuration` once it has landed. Unset: no flash.
89
+ */
90
+ flashUpColor?: ColorValue
91
+ /** The change flash's colour when the value shrank (e.g. a red). Unset: no flash. */
92
+ flashDownColor?: ColorValue
93
+ /** Milliseconds a change flash takes to fade, once the digit has landed. Default: `600`. */
94
+ flashDuration?: number
95
+ /**
96
+ * A punch of the whole figure on every value change, its peak overshoot
97
+ * as a fraction of the size, `0` (none, the default) to `1`; rung out like
98
+ * the reveal's landing pop. `0.08` is a nudge, `0.2` a slam.
99
+ */
100
+ popOnChange?: number
101
+ /** Duration in ms of the roll played when `value` changes. `0` snaps. Default: `500` (each swap transition has its own, see `transition`). */
102
+ duration?: number
103
+ /** Timing curve of the roll. Default: `'easeInOut'` (the scramble has its own, see `transition`; the numeric transition keeps SwiftUI's own clocks and ignores it). */
104
+ easing?: NitroNumberEasing
105
+ /** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15` (the numeric transition has its own, fixed). */
106
+ bounce?: number
107
+ /**
108
+ * Delay in ms between the start of each digit's roll, least significant
109
+ * digit first, so a change cascades like a mechanical carry. In the numeric
110
+ * transition it is the span of the whole cascade instead: the digits that
111
+ * change start spread evenly over it from the leftmost to the rightmost,
112
+ * however many there are, the way the effect cascades on iOS. Default: `0`
113
+ * (`150` for the numeric transition).
114
+ */
115
+ stagger?: number
116
+ /**
117
+ * Which way the digits roll. `'auto'` follows the sign of the change;
118
+ * `'up'` / `'down'` force one; `'shortest'` rolls each digit its own
119
+ * shorter way round (1 → 2 is one step up even when the value falls, where
120
+ * `'auto'` rolls nine steps down), which is calmer on big jumps. The numeric transition and the reveal ignore it. Default: `'auto'`.
121
+ */
122
+ direction?: NitroNumberDirection
123
+ /**
124
+ * Jackpot reveal, the casino "you won" presentation. While `false` the view
125
+ * holds the opening frame of `value` ("$0.00": its layout, every digit blank
126
+ * except the mandatory ones); when it turns `true` the figure plays its
127
+ * `revealStyle` to `value` and lands with a pop. Pair it with
128
+ * `textAlign="center"` for a centred hero figure. Leave it `undefined` for
129
+ * a normal NitroNumber. To let the user skip the reveal, call `jumpTo(value)`.
130
+ */
131
+ reveal?: boolean
132
+ /**
133
+ * `'count'` (default) is the win-meter rollup: the figure tallies up from 0
134
+ * like a slot's win counter, taking off at once, running at a constant
135
+ * rate and braking into the total (and into each tier with
136
+ * `revealMilestones`), swelling slightly as it climbs, digits swapping in
137
+ * place and leading digits appearing as the count reaches them. `'spin'`
138
+ * is the jackpot reels: every digit spins like a slot reel, then the reels
139
+ * brake and lock one at a time from the left, each with a mechanical bounce.
140
+ */
141
+ revealStyle?: NitroNumberRevealStyle
142
+ /** Duration of the reveal in ms (the count, or the time until the last reel locks). Default: `2200`. */
143
+ revealDuration?: number
144
+ /** Peak overshoot of the reveal's landing pop, `0` (none) to `1`. Default: `0.12`. */
145
+ revealBounce?: number
146
+ /**
147
+ * `'count'` style: how much smaller the figure opens, as a fraction of its
148
+ * size, growing to full size over the count, the way a big win's meter is
149
+ * enlarged as it climbs. `0` = no growth. Default: `0.2`.
150
+ */
151
+ revealGrow?: number
152
+ /** `'spin'` style: ms between one reel locking and the next, shortened to fit `revealDuration`. Default: `200`. */
153
+ revealStagger?: number
154
+ /**
155
+ * `'count'` style: the win tiers of a casino rollup ("Big win" → "Mega win"
156
+ * → "Epic win"), in the figure's units. When the count reaches one, the
157
+ * figure punches, pauses on it for `revealMilestoneHold` and
158
+ * `onRevealMilestone` fires, so the app can slam its banner in, fire the
159
+ * confetti and play the sting on that beat. Values at or above `value` are ignored.
160
+ */
161
+ revealMilestones?: number[]
162
+ /** `'count'` style: ms the count pauses on each milestone (the banner's moment). Default: `0`. */
163
+ revealMilestoneHold?: number
164
+ /** Called once a reveal has landed (count finished or last reel locked, and the pop rung out). */
165
+ onRevealEnd?: () => void
166
+ /** Called when the count reaches a milestone: its index among the usable milestones and its value. */
167
+ onRevealMilestone?: (index: number, value: number) => void
168
+ /**
169
+ * Loading glint: the ink keeps its color while a slanted, text-wide band of
170
+ * `shimmerColor` sweeps through the glyphs (a "shine" skeleton). Toggling
171
+ * cross-fades; the number keeps its size so nothing jumps when the value
172
+ * arrives. Default: `false`.
173
+ */
174
+ loading?: boolean
175
+ /** Color of the glint's core, e.g. your theme's lightest neutral. Defaults to `#D6D9E1` (`#2B2E37` in dark mode). */
176
+ shimmerColor?: ColorValue
177
+ /** Duration of one sweep in ms (linear, repeating). Default: `950`. */
178
+ shimmerDuration?: number
179
+ /** Font size of the digits in points. Default: `32`. */
180
+ fontSize?: number
181
+ /** Font size of `prefix`, e.g. a smaller currency symbol. Defaults to `fontSize`. */
182
+ prefixFontSize?: number
183
+ /** Font size of `suffix`, e.g. a smaller currency code. Defaults to `fontSize`. */
184
+ suffixFontSize?: number
185
+ /**
186
+ * How prefix and suffix line up with the digits: `'top'` pins glyph tops,
187
+ * `'bottom'` pins the bottom of the line boxes, `'baseline'` shares the
188
+ * digits' baseline, `'center'` centres. Default: `'baseline'`.
189
+ */
190
+ affixAlign?: NitroNumberAffixAlign
191
+ /** Alignment of `prefix` only. Defaults to `affixAlign`. */
192
+ prefixAlign?: NitroNumberAffixAlign
193
+ /** Alignment of `suffix` only. Defaults to `affixAlign`. */
194
+ suffixAlign?: NitroNumberAffixAlign
195
+ /**
196
+ * Points added after every glyph, like `Text`'s `letterSpacing` (negative
197
+ * tightens). A smaller prefix or suffix gets it in proportion to its size.
198
+ * Default: `0`.
199
+ */
200
+ letterSpacing?: number
201
+ /** Points between the prefix and the digits, in place of the letter spacing there. Defaults to the letter spacing. */
202
+ prefixSpacing?: number
203
+ /** Points between the digits and the suffix, in place of the letter spacing there. Defaults to the letter spacing. */
204
+ suffixSpacing?: number
205
+ /** Points the prefix is moved down after `prefixAlign` places it (negative: up). Default: `0`. */
206
+ prefixOffset?: number
207
+ /** Points the suffix is moved down after `suffixAlign` places it (negative: up). Default: `0`. */
208
+ suffixOffset?: number
209
+ /**
210
+ * `true` (the default): every digit as wide as the widest, so columns never
211
+ * move, what a ticker or a price wants. `false`: each digit at its own
212
+ * width, the font's proportional figures, for a face whose "1" is narrow
213
+ * (or that has no tabular figures at all); a changing column's width
214
+ * then eases once from the old digit's to the new one's.
215
+ */
216
+ tabularNums?: boolean
217
+ /**
218
+ * A `NumberFormat` the number follows: its prefix and suffix (the currency
219
+ * where the locale puts it), grouping and decimal separators, fraction
220
+ * digits and minimum integer digits. The individual props override what it
221
+ * says.
222
+ */
223
+ format?: NumberFormat
224
+ /**
225
+ * Scale the number down when the view is narrower than its content, and back
226
+ * up (never above `fontSize`) when it fits again. Give the view a fixed
227
+ * `width` in `style`; the view keeps its full-size height so the box around
228
+ * it never moves, only the amount scales. Like `Text`'s prop. Default: `false`.
229
+ */
230
+ adjustsFontSizeToFit?: boolean
231
+ /** Smallest scale `adjustsFontSizeToFit` may apply, `0`–`1`. Default: `0.5`. */
232
+ minimumFontScale?: number
233
+ /**
234
+ * Scale the fonts with the system text size (Dynamic Type / Android font
235
+ * scale) like `Text` does. Off by default so amounts keep their design size.
236
+ */
237
+ allowFontScaling?: boolean
238
+ /** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
239
+ maxFontSizeMultiplier?: number
240
+ /** Font weight, like `Text`'s `fontWeight`. Default: `'normal'`. */
241
+ fontWeight?: TextStyle['fontWeight']
242
+ /** Font family name, like `Text`'s `fontFamily`. Defaults to the system font. */
243
+ fontFamily?: string
244
+ /** Text color. Defaults to the platform's primary label color. */
245
+ color?: ColorValue
246
+ /**
247
+ * Where the number sits when the view is wider than its content, e.g. when
248
+ * you give it a fixed `width` so it doesn't reflow as digits appear.
249
+ * Default: `'auto'`: the start edge of the layout direction, as `Text`.
250
+ * `'left'` and `'right'` are absolute.
251
+ */
252
+ textAlign?: NitroNumberTextAlign
253
+ /** Receives the native Nitro object once the view is mounted. */
254
+ onNativeRef?: (ref: NitroNumberRef) => void
255
+ }
256
+
257
+ /** Imperative handle exposed through `ref`. Methods are no-ops before mount. */
258
+ export interface NitroNumberHandle {
259
+ /**
260
+ * Shows `value` immediately with continuously positioned digits (odometer
261
+ * style, `12.5` shows the last digit half way between `2` and `3`). No roll
262
+ * is played. Useful for scrubbing, e.g. from a scroll or drag handler.
263
+ */
264
+ jumpTo(value: number): void
265
+ /** Rolls to `value` natively, exactly like changing the `value` prop. */
266
+ animateTo(value: number): void
267
+ /** Plays a jackpot reveal to `value` (counts up from 0), whatever the `reveal` prop says. */
268
+ revealTo(value: number): void
269
+ /** The value currently shown or being rolled towards. */
270
+ getValue(): number
271
+ /** The native Nitro object, or `null` before mount. */
272
+ readonly native: NitroNumberRef | null
273
+ }
274
+
275
+ interface Size {
276
+ width: number
277
+ height: number
278
+ }
279
+
280
+ /** Each transition's own timing, used when the props leave it unsaid. */
281
+ const TRANSITION_DEFAULTS: Record<NitroNumberTransition, { duration: number; easing: NitroNumberEasing; stagger: number }> = {
282
+ roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
283
+ numeric: { duration: 480, easing: 'spring', stagger: 150 },
284
+ scramble: { duration: 500, easing: 'linear', stagger: 60 },
285
+ }
286
+
287
+ /**
288
+ * A number that animates its changes natively: an odometer roll, SwiftUI's
289
+ * numeric transition or a scramble.
290
+ *
291
+ * Change `value` and every digit rolls to its new glyph on the native side.
292
+ * Use the ref's `animateTo` / `jumpTo` for imperative updates.
293
+ *
294
+ * The view sizes itself to its content unless you pass an explicit `width` /
295
+ * `height` in `style`.
296
+ */
297
+ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
298
+ function NitroNumber(
299
+ {
300
+ value,
301
+ fractionDigits,
302
+ minimumIntegerDigits,
303
+ groupingSeparator,
304
+ decimalSeparator,
305
+ prefix,
306
+ suffix,
307
+ transition,
308
+ flashUpColor,
309
+ flashDownColor,
310
+ flashDuration,
311
+ popOnChange,
312
+ duration,
313
+ easing,
314
+ bounce,
315
+ stagger,
316
+ direction,
317
+ reveal,
318
+ revealStyle,
319
+ revealDuration,
320
+ revealBounce,
321
+ revealGrow,
322
+ revealStagger,
323
+ revealMilestones,
324
+ revealMilestoneHold,
325
+ onRevealEnd,
326
+ onRevealMilestone,
327
+ loading,
328
+ shimmerColor,
329
+ shimmerDuration,
330
+ fontSize,
331
+ prefixFontSize,
332
+ suffixFontSize,
333
+ affixAlign,
334
+ prefixAlign,
335
+ suffixAlign,
336
+ letterSpacing,
337
+ prefixSpacing,
338
+ suffixSpacing,
339
+ prefixOffset,
340
+ suffixOffset,
341
+ tabularNums,
342
+ format,
343
+ adjustsFontSizeToFit,
344
+ minimumFontScale,
345
+ allowFontScaling,
346
+ maxFontSizeMultiplier,
347
+ fontWeight,
348
+ fontFamily,
349
+ color,
350
+ textAlign,
351
+ onNativeRef,
352
+ style,
353
+ ...viewProps
354
+ },
355
+ ref
356
+ ) {
357
+ const nativeRef = useRef<NitroNumberRef | null>(null)
358
+ const latestOnNativeRef = useRef(onNativeRef)
359
+ latestOnNativeRef.current = onNativeRef
360
+ const latestOnRevealEnd = useRef(onRevealEnd)
361
+ latestOnRevealEnd.current = onRevealEnd
362
+ const latestOnRevealMilestone = useRef(onRevealMilestone)
363
+ latestOnRevealMilestone.current = onRevealMilestone
364
+ const latestValue = useRef(value)
365
+ latestValue.current = value
366
+
367
+ const [size, setSize] = useState<Size | null>(null)
368
+
369
+ // Nitro callbacks must be wrapped with `callback()` and the wrapper object
370
+ // has to be referentially stable, otherwise every render re-sets the prop.
371
+ const hybridRef = useMemo(
372
+ () =>
373
+ callback((instance: NitroNumberRef) => {
374
+ nativeRef.current = instance
375
+ latestOnNativeRef.current?.(instance)
376
+ }),
377
+ []
378
+ )
379
+ const onSizeChange = useMemo(
380
+ () =>
381
+ callback((width: number, height: number) => {
382
+ setSize((previous) =>
383
+ previous !== null &&
384
+ previous.width === width &&
385
+ previous.height === height
386
+ ? previous
387
+ : { width, height }
388
+ )
389
+ }),
390
+ []
391
+ )
392
+
393
+ // Stable like the others; the latest handler is read through a ref so a
394
+ // caller passing an inline arrow doesn't re-set the native prop each render.
395
+ const onRevealEndCallback = useMemo(
396
+ () =>
397
+ callback(() => {
398
+ latestOnRevealEnd.current?.()
399
+ }),
400
+ []
401
+ )
402
+ const onRevealMilestoneCallback = useMemo(
403
+ () =>
404
+ callback((index: number, milestone: number) => {
405
+ latestOnRevealMilestone.current?.(index, milestone)
406
+ }),
407
+ []
408
+ )
409
+ // A new array literal each render must not re-set the native prop. Always an
410
+ // array (empty = no tiers): removing the prop would reach native as `null`,
411
+ // which Nitro's array parser rejects ("Value is null, expected an Object").
412
+ const milestonesKey = revealMilestones?.join(',') ?? ''
413
+ const stableMilestones = useMemo(
414
+ () => (revealMilestones ? [...revealMilestones] : []),
415
+ // eslint-disable-next-line react-hooks/exhaustive-deps
416
+ [milestonesKey]
417
+ )
418
+
419
+ // One handle for the component's lifetime: `getValue` reads the latest
420
+ // prop through a ref, so a value change doesn't hand the parent a new object.
421
+ useImperativeHandle(
422
+ ref,
423
+ () => ({
424
+ jumpTo: (next) => nativeRef.current?.jumpTo(next),
425
+ animateTo: (next) => nativeRef.current?.animateTo(next),
426
+ revealTo: (next) => nativeRef.current?.revealTo(next),
427
+ getValue: () => nativeRef.current?.value ?? latestValue.current,
428
+ get native() {
429
+ return nativeRef.current
430
+ },
431
+ }),
432
+ []
433
+ )
434
+
435
+ // Every native prop is sent with an explicit value: an optional prop that
436
+ // is *removed* reaches native as `null`, which Nitro's parser rejects and
437
+ // React Native turns into a fatal error. `Infinity` stands for "platform
438
+ // default" where there is no value to express it (colors), `''` for fonts.
439
+ // Not `NaN`: Nitro only calls a native setter when a prop's value changed,
440
+ // and NaN never equals itself, so a NaN sentinel re-set the colour on every
441
+ // render and had the whole configuration re-applied on every value change.
442
+ const processedColor = useMemo(() => toProcessedColor(color) ?? Infinity, [color])
443
+ const processedShimmerColor = useMemo(
444
+ () => toProcessedColor(shimmerColor) ?? Infinity,
445
+ [shimmerColor]
446
+ )
447
+ const processedFlashUp = useMemo(() => toProcessedColor(flashUpColor) ?? Infinity, [flashUpColor])
448
+ const processedFlashDown = useMemo(() => toProcessedColor(flashDownColor) ?? Infinity, [flashDownColor])
449
+ const numericWeight = toNumericWeight(fontWeight) ?? 400
450
+ const resolvedFontSize = fontSize ?? 32
451
+ const resolvedAffixAlign = affixAlign ?? 'baseline'
452
+ const derived = format ? formatProps(format) : undefined
453
+
454
+ const autoSize = useMemo(
455
+ () =>
456
+ size !== null
457
+ ? { width: size.width, height: size.height }
458
+ : { height: (fontSize ?? 32) * 1.25 },
459
+ [size, fontSize]
460
+ )
461
+
462
+ // The layout direction, resolved the way React Native resolves it for its
463
+ // own views: the view's `style.direction` if it says, else the app's. Fabric
464
+ // does not hand a Hybrid View its resolved direction, so native is told.
465
+ const layoutDirection = useMemo(
466
+ () => (StyleSheet.flatten(style) as { direction?: unknown } | undefined)?.direction,
467
+ [style]
468
+ )
469
+ const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && I18nManager.isRTL)
470
+
471
+ return (
472
+ <NativeNitroNumberView
473
+ {...viewProps}
474
+ style={[autoSize, style]}
475
+ hybridRef={hybridRef}
476
+ value={value}
477
+ fractionDigits={fractionDigits ?? derived?.fractionDigits ?? 0}
478
+ minimumIntegerDigits={minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1}
479
+ groupingSeparator={groupingSeparator ?? derived?.groupingSeparator ?? ''}
480
+ decimalSeparator={decimalSeparator ?? derived?.decimalSeparator ?? '.'}
481
+ prefix={prefix ?? derived?.prefix ?? ''}
482
+ suffix={suffix ?? derived?.suffix ?? ''}
483
+ transition={transition ?? 'roll'}
484
+ flashUpColor={processedFlashUp}
485
+ flashDownColor={processedFlashDown}
486
+ flashDuration={flashDuration ?? 600}
487
+ popOnChange={popOnChange ?? 0}
488
+ duration={duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration}
489
+ easing={easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing}
490
+ bounce={bounce ?? 0.15}
491
+ stagger={stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger}
492
+ rollDirection={direction ?? 'auto'}
493
+ revealState={reveal === undefined ? 0 : reveal ? 2 : 1}
494
+ revealStyle={revealStyle ?? 'count'}
495
+ revealDuration={revealDuration ?? 2200}
496
+ revealBounce={revealBounce ?? 0.12}
497
+ revealGrow={revealGrow ?? 0.2}
498
+ revealStagger={revealStagger ?? 200}
499
+ revealMilestones={stableMilestones}
500
+ revealMilestoneHold={revealMilestoneHold ?? 0}
501
+ onRevealEnd={onRevealEndCallback}
502
+ onRevealMilestone={onRevealMilestoneCallback}
503
+ loading={loading ?? false}
504
+ shimmerColor={processedShimmerColor}
505
+ shimmerDuration={shimmerDuration ?? 950}
506
+ fontSize={resolvedFontSize}
507
+ prefixFontSize={prefixFontSize ?? resolvedFontSize}
508
+ suffixFontSize={suffixFontSize ?? resolvedFontSize}
509
+ affixAlign={resolvedAffixAlign}
510
+ prefixAlign={prefixAlign ?? resolvedAffixAlign}
511
+ suffixAlign={suffixAlign ?? resolvedAffixAlign}
512
+ letterSpacing={letterSpacing ?? 0}
513
+ prefixSpacing={prefixSpacing ?? Infinity}
514
+ suffixSpacing={suffixSpacing ?? Infinity}
515
+ prefixOffset={prefixOffset ?? 0}
516
+ suffixOffset={suffixOffset ?? 0}
517
+ tabularNums={tabularNums ?? true}
518
+ adjustsFontSizeToFit={adjustsFontSizeToFit ?? false}
519
+ minimumFontScale={minimumFontScale ?? 0.5}
520
+ allowFontScaling={allowFontScaling ?? false}
521
+ maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
522
+ fontWeight={numericWeight}
523
+ fontFamily={fontFamily ?? ''}
524
+ color={processedColor}
525
+ textAlign={textAlign ?? 'auto'}
526
+ rightToLeft={rightToLeft}
527
+ onSizeChange={onSizeChange}
528
+ />
529
+ )
530
+ }
531
+ )