react-native-nitro-input 0.2.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 (222) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +132 -2
  3. package/android/CMakeLists.txt +4 -0
  4. package/android/gradle.properties +1 -1
  5. package/android/src/main/cpp/JReflowEngine.cpp +32 -0
  6. package/android/src/main/cpp/JReflowEngine.hpp +13 -0
  7. package/android/src/main/cpp/JRollingEngine.cpp +43 -2
  8. package/android/src/main/cpp/JRollingEngine.hpp +9 -1
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +20 -0
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +284 -0
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +113 -0
  12. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextMeasure.kt +25 -0
  13. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +140 -0
  14. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
  15. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +69 -10
  16. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +522 -130
  17. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroTextView.kt +868 -0
  18. package/android/src/main/java/com/margelo/nitro/nitroinput/ReflowEngine.kt +21 -0
  19. package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +14 -2
  20. package/cpp/RollingEngine.cpp +102 -8
  21. package/cpp/RollingEngine.hpp +44 -3
  22. package/cpp/numberformat/HybridNitroNumberFormat.cpp +498 -0
  23. package/cpp/numberformat/HybridNitroNumberFormat.hpp +74 -0
  24. package/cpp/numberformat/HybridNitroNumberFormatFactory.hpp +11 -0
  25. package/cpp/numberformat/NumberFormatCore.cpp +629 -0
  26. package/cpp/numberformat/NumberFormatCore.hpp +154 -0
  27. package/cpp/numberformat/NumberFormatProbe.cpp +354 -0
  28. package/cpp/numberformat/NumberFormatProbe.hpp +63 -0
  29. package/ios/HybridNitroInputView.swift +15 -0
  30. package/ios/HybridNitroNumberFormatPlatform.swift +426 -0
  31. package/ios/HybridNitroNumberView.swift +101 -1
  32. package/ios/HybridNitroTextView.swift +134 -0
  33. package/ios/NitroInputView.swift +79 -19
  34. package/ios/NitroNumberView.swift +520 -147
  35. package/ios/NitroTextView.swift +583 -0
  36. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
  37. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
  38. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  39. package/lib/commonjs/src/NitroInput.js +8 -6
  40. package/lib/commonjs/src/NitroNumber.js +54 -3
  41. package/lib/commonjs/src/NitroText.js +138 -0
  42. package/lib/commonjs/src/NitroTime.js +65 -0
  43. package/lib/commonjs/src/NumberFormat.js +525 -0
  44. package/lib/commonjs/src/formatProps.js +108 -0
  45. package/lib/commonjs/src/index.js +8 -1
  46. package/lib/commonjs/src/specs/NitroText.nitro.js +2 -0
  47. package/lib/commonjs/src/specs/NumberFormat.nitro.js +2 -0
  48. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
  49. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
  50. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  51. package/lib/module/src/NitroInput.js +8 -6
  52. package/lib/module/src/NitroNumber.js +54 -3
  53. package/lib/module/src/NitroText.js +98 -0
  54. package/lib/module/src/NitroTime.js +29 -0
  55. package/lib/module/src/NumberFormat.js +521 -0
  56. package/lib/module/src/formatProps.js +104 -0
  57. package/lib/module/src/index.js +3 -0
  58. package/lib/module/src/specs/NitroText.nitro.js +1 -0
  59. package/lib/module/src/specs/NumberFormat.nitro.js +1 -0
  60. package/lib/typescript/src/NitroInput.d.ts +22 -0
  61. package/lib/typescript/src/NitroNumber.d.ts +115 -2
  62. package/lib/typescript/src/NitroText.d.ts +67 -0
  63. package/lib/typescript/src/NitroTime.d.ts +19 -0
  64. package/lib/typescript/src/NumberFormat.d.ts +47 -0
  65. package/lib/typescript/src/formatProps.d.ts +47 -0
  66. package/lib/typescript/src/index.d.ts +6 -1
  67. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +10 -0
  68. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +80 -1
  69. package/lib/typescript/src/specs/NitroText.nitro.d.ts +60 -0
  70. package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +139 -0
  71. package/nitro.json +36 -0
  72. package/nitrogen/generated/android/NitroInput+autolinking.cmake +12 -0
  73. package/nitrogen/generated/android/NitroInputOnLoad.cpp +62 -0
  74. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +45 -0
  75. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +10 -0
  76. package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.cpp +118 -0
  77. package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.hpp +64 -0
  78. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +297 -0
  79. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +52 -0
  80. package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.cpp +65 -0
  81. package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.hpp +64 -0
  82. package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp +58 -0
  83. package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.hpp +64 -0
  84. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +253 -0
  85. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +104 -0
  86. package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +3 -0
  87. package/nitrogen/generated/android/c++/JNitroNumberShimmerDirection.hpp +61 -0
  88. package/nitrogen/generated/android/c++/JNitroNumberSignDisplay.hpp +67 -0
  89. package/nitrogen/generated/android/c++/JNumberFormatCompactDisplay.hpp +58 -0
  90. package/nitrogen/generated/android/c++/JNumberFormatCurrencyDisplay.hpp +64 -0
  91. package/nitrogen/generated/android/c++/JNumberFormatCurrencySign.hpp +58 -0
  92. package/nitrogen/generated/android/c++/JNumberFormatNotation.hpp +64 -0
  93. package/nitrogen/generated/android/c++/JNumberFormatPlatformOptions.hpp +161 -0
  94. package/nitrogen/generated/android/c++/JNumberFormatPlatformSymbols.hpp +89 -0
  95. package/nitrogen/generated/android/c++/JNumberFormatRoundingMode.hpp +79 -0
  96. package/nitrogen/generated/android/c++/JNumberFormatSignDisplay.hpp +67 -0
  97. package/nitrogen/generated/android/c++/JNumberFormatStyle.hpp +64 -0
  98. package/nitrogen/generated/android/c++/JNumberFormatUnitDisplay.hpp +61 -0
  99. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +25 -0
  100. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +130 -0
  101. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +174 -0
  102. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.hpp +54 -0
  103. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +30 -0
  104. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatformSpec.kt +60 -0
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +172 -0
  106. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroPlatformNumberFormatterSpec.kt +62 -0
  107. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextMeasureSpec.kt +60 -0
  108. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +179 -0
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +2 -1
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberShimmerDirection.kt +24 -0
  111. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberSignDisplay.kt +26 -0
  112. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCompactDisplay.kt +23 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencyDisplay.kt +25 -0
  114. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencySign.kt +23 -0
  115. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatNotation.kt +25 -0
  116. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformOptions.kt +136 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformSymbols.kt +91 -0
  118. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatRoundingMode.kt +30 -0
  119. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatSignDisplay.kt +26 -0
  120. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatStyle.kt +25 -0
  121. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatUnitDisplay.kt +24 -0
  122. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewManager.kt +96 -0
  123. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewStateUpdater.kt +23 -0
  124. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +68 -0
  125. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +184 -0
  126. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +56 -0
  127. package/nitrogen/generated/ios/NitroInputAutolinking.mm +34 -0
  128. package/nitrogen/generated/ios/NitroInputAutolinking.swift +36 -0
  129. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +30 -0
  130. package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.cpp +11 -0
  131. package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.hpp +122 -0
  132. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +188 -0
  133. package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.cpp +11 -0
  134. package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.hpp +94 -0
  135. package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.cpp +11 -0
  136. package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.hpp +90 -0
  137. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.cpp +11 -0
  138. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +233 -0
  139. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +30 -0
  140. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +156 -0
  141. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +264 -0
  142. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +5 -0
  143. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +55 -0
  144. package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec.swift +56 -0
  145. package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec_cxx.swift +159 -0
  146. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +26 -0
  147. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +658 -21
  148. package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec.swift +56 -0
  149. package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec_cxx.swift +155 -0
  150. package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec.swift +56 -0
  151. package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec_cxx.swift +150 -0
  152. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +75 -0
  153. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +608 -0
  154. package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +4 -0
  155. package/nitrogen/generated/ios/swift/NitroNumberShimmerDirection.swift +44 -0
  156. package/nitrogen/generated/ios/swift/NitroNumberSignDisplay.swift +52 -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 +52 -0
  176. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +58 -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++/HybridNitroTextMeasureSpec.cpp +22 -0
  180. package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.hpp +63 -0
  181. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +62 -0
  182. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +115 -0
  183. package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +4 -0
  184. package/nitrogen/generated/shared/c++/NitroNumberShimmerDirection.hpp +80 -0
  185. package/nitrogen/generated/shared/c++/NitroNumberSignDisplay.hpp +88 -0
  186. package/nitrogen/generated/shared/c++/NumberFormatCompactDisplay.hpp +76 -0
  187. package/nitrogen/generated/shared/c++/NumberFormatCurrencyDisplay.hpp +84 -0
  188. package/nitrogen/generated/shared/c++/NumberFormatCurrencySign.hpp +76 -0
  189. package/nitrogen/generated/shared/c++/NumberFormatGrouping.hpp +80 -0
  190. package/nitrogen/generated/shared/c++/NumberFormatNotation.hpp +84 -0
  191. package/nitrogen/generated/shared/c++/NumberFormatOptions.hpp +193 -0
  192. package/nitrogen/generated/shared/c++/NumberFormatPart.hpp +87 -0
  193. package/nitrogen/generated/shared/c++/NumberFormatPlatformOptions.hpp +176 -0
  194. package/nitrogen/generated/shared/c++/NumberFormatPlatformSymbols.hpp +115 -0
  195. package/nitrogen/generated/shared/c++/NumberFormatRoundingMode.hpp +104 -0
  196. package/nitrogen/generated/shared/c++/NumberFormatRoundingPriority.hpp +80 -0
  197. package/nitrogen/generated/shared/c++/NumberFormatSignDisplay.hpp +88 -0
  198. package/nitrogen/generated/shared/c++/NumberFormatStyle.hpp +84 -0
  199. package/nitrogen/generated/shared/c++/NumberFormatTrailingZeroDisplay.hpp +76 -0
  200. package/nitrogen/generated/shared/c++/NumberFormatUnitDisplay.hpp +80 -0
  201. package/nitrogen/generated/shared/c++/ResolvedNumberFormatOptions.hpp +197 -0
  202. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +10 -0
  203. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +15 -0
  204. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +52 -0
  205. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +80 -0
  206. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +74 -0
  207. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +149 -0
  208. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
  209. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
  210. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  211. package/package.json +2 -2
  212. package/src/NitroInput.tsx +42 -7
  213. package/src/NitroNumber.tsx +236 -12
  214. package/src/NitroText.tsx +166 -0
  215. package/src/NitroTime.tsx +68 -0
  216. package/src/NumberFormat.ts +563 -0
  217. package/src/formatProps.ts +149 -0
  218. package/src/index.ts +23 -0
  219. package/src/specs/NitroInput.nitro.ts +10 -0
  220. package/src/specs/NitroNumber.nitro.ts +82 -1
  221. package/src/specs/NitroText.nitro.ts +65 -0
  222. package/src/specs/NumberFormat.nitro.ts +145 -0
@@ -26,9 +26,13 @@ import type {
26
26
  NitroNumberMethods,
27
27
  NitroNumberProps as NativeNitroNumberProps,
28
28
  NitroNumberRevealStyle,
29
+ NitroNumberShimmerDirection,
30
+ NitroNumberSignDisplay,
29
31
  NitroNumberTextAlign,
30
32
  } from './specs/NitroNumber.nitro'
31
33
  import { toNumericWeight, toProcessedColor } from './styleHelpers'
34
+ import { compactParts, formatProps } from './formatProps'
35
+ import type { NumberFormat } from './NumberFormat'
32
36
 
33
37
  /**
34
38
  * The raw Nitro host component. Prefer {@link NitroNumber}, which adds
@@ -111,7 +115,12 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
111
115
  * (`150` for the numeric transition).
112
116
  */
113
117
  stagger?: number
114
- /** Which way the digits roll. `'auto'` follows the sign of the change. Default: `'auto'`. */
118
+ /**
119
+ * Which way the digits roll. `'auto'` follows the sign of the change;
120
+ * `'up'` / `'down'` force one; `'shortest'` rolls each digit its own
121
+ * shorter way round (1 → 2 is one step up even when the value falls, where
122
+ * `'auto'` rolls nine steps down), which is calmer on big jumps. The numeric transition and the reveal ignore it. Default: `'auto'`.
123
+ */
115
124
  direction?: NitroNumberDirection
116
125
  /**
117
126
  * Jackpot reveal, the casino "you won" presentation. While `false` the view
@@ -169,6 +178,19 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
169
178
  shimmerColor?: ColorValue
170
179
  /** Duration of one sweep in ms (linear, repeating). Default: `950`. */
171
180
  shimmerDuration?: number
181
+ /** The band's slant in degrees: 0 upright, positive leans it like "/", negative the other way. Default: `31`. */
182
+ shimmerAngle?: number
183
+ /** The band's width as a fraction of the number's: `0.5` is a narrow glint. Default: `1`. */
184
+ shimmerWidth?: number
185
+ /**
186
+ * The glyphs' colour outside the band while loading: a light grey makes the
187
+ * figure a skeleton that the band lights up. Default: `color`.
188
+ */
189
+ shimmerBaseColor?: ColorValue
190
+ /** Which way the band sweeps. Default: `'auto'`, the layout direction. */
191
+ shimmerDirection?: NitroNumberShimmerDirection
192
+ /** A pause after each sweep, in ms. Default: `0`. */
193
+ shimmerDelay?: number
172
194
  /** Font size of the digits in points. Default: `32`. */
173
195
  fontSize?: number
174
196
  /** Font size of `prefix`, e.g. a smaller currency symbol. Defaults to `fontSize`. */
@@ -185,6 +207,35 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
185
207
  prefixAlign?: NitroNumberAffixAlign
186
208
  /** Alignment of `suffix` only. Defaults to `affixAlign`. */
187
209
  suffixAlign?: NitroNumberAffixAlign
210
+ /**
211
+ * Points added after every glyph, like `Text`'s `letterSpacing` (negative
212
+ * tightens). A smaller prefix or suffix gets it in proportion to its size.
213
+ * Default: `0`.
214
+ */
215
+ letterSpacing?: number
216
+ /** Points between the prefix and the digits, in place of the letter spacing there. Defaults to the letter spacing. */
217
+ prefixSpacing?: number
218
+ /** Points between the digits and the suffix, in place of the letter spacing there. Defaults to the letter spacing. */
219
+ suffixSpacing?: number
220
+ /** Points the prefix is moved down after `prefixAlign` places it (negative: up). Default: `0`. */
221
+ prefixOffset?: number
222
+ /** Points the suffix is moved down after `suffixAlign` places it (negative: up). Default: `0`. */
223
+ suffixOffset?: number
224
+ /**
225
+ * `true` (the default): every digit as wide as the widest, so columns never
226
+ * move, what a ticker or a price wants. `false`: each digit at its own
227
+ * width, the font's proportional figures, for a face whose "1" is narrow
228
+ * (or that has no tabular figures at all); a changing column's width
229
+ * then eases once from the old digit's to the new one's.
230
+ */
231
+ tabularNums?: boolean
232
+ /**
233
+ * A `NumberFormat` the number follows: its prefix and suffix (the currency
234
+ * where the locale puts it), grouping and decimal separators, fraction
235
+ * digits and minimum integer digits. The individual props override what it
236
+ * says.
237
+ */
238
+ format?: NumberFormat
188
239
  /**
189
240
  * Scale the number down when the view is narrower than its content, and back
190
241
  * up (never above `fontSize`) when it fits again. Give the view a fixed
@@ -214,6 +265,69 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
214
265
  * `'left'` and `'right'` are absolute.
215
266
  */
216
267
  textAlign?: NitroNumberTextAlign
268
+ /**
269
+ * Which values carry a sign, as `Intl.NumberFormat`'s `signDisplay`:
270
+ * `'always'` and `'exceptZero'` put a plus on gains ("+$12.40"), and a plus
271
+ * that turns into a minus swaps like any other glyph. A value that rounds to
272
+ * zero at the shown fraction digits counts as zero. Default: `'auto'`
273
+ * (negatives), or the `format`'s.
274
+ */
275
+ signDisplay?: NitroNumberSignDisplay
276
+ /** The glyph drawn for a plus sign. Default: `'+'`. */
277
+ plusSign?: string
278
+ /** The glyph drawn for a minus sign, e.g. `'−'` (U+2212). Default: `'-'`, or the `format` locale's. */
279
+ minusSign?: string
280
+ /** The prefix's color. Default: `color`. */
281
+ prefixColor?: ColorValue
282
+ /** The suffix's color. Default: `color`. */
283
+ suffixColor?: ColorValue
284
+ /** The fraction digits' and decimal separator's color: dimmer cents. Default: `color`. */
285
+ fractionColor?: ColorValue
286
+ /** The fraction digits' and decimal separator's size: smaller cents. Default: `fontSize`. */
287
+ fractionFontSize?: number
288
+ /**
289
+ * How smaller fraction digits line up with the integer ones: `'baseline'`,
290
+ * or `'top'` for superscript cents ("$12⁹⁹"). Default: `'baseline'`.
291
+ */
292
+ fractionAlign?: NitroNumberAffixAlign
293
+ /**
294
+ * The ten glyphs drawn for 0 to 9, for native digits (Arabic-Indic,
295
+ * Devanagari…). Default: `'0'`…`'9'`, or the `format`'s numbering system.
296
+ */
297
+ digitGlyphs?: string[]
298
+ /**
299
+ * Digit group sizes counted from the decimal point: the first group, then
300
+ * every later one. `[3, 2]` is Indian grouping (12,34,567), `[2]` a clock
301
+ * (12:34:56 with `groupingSeparator=":"`). Default: `[3]`, or the `format`'s.
302
+ */
303
+ groupingSizes?: number[]
304
+ /**
305
+ * The highest digit a position shows before it wraps to 0, keyed by integer
306
+ * position (0 the ones, 1 the tens…), as NumberFlow's `digits`:
307
+ * `{ 1: { max: 5 } }` makes the tens of a clock's seconds wrap after 5, so
308
+ * 59 → 00 turns them one step instead of five back.
309
+ */
310
+ digits?: Record<number, { max: number }>
311
+ /**
312
+ * Rolls turn the wheels below the highest one that changes a full turn too,
313
+ * so 100 → 200 seems to pass through every value between. Rolls only.
314
+ * Default: `false`.
315
+ */
316
+ continuous?: boolean
317
+ /**
318
+ * `false` shows every change at once, without a roll or a reveal (the flash
319
+ * and the pop still play). Default: `true`.
320
+ */
321
+ animated?: boolean
322
+ /** Snap instead of animating while the system's Reduce Motion is on. Default: `true`. */
323
+ respectReduceMotion?: boolean
324
+ /** Called when the figure starts moving from rest: a change, or a reveal. */
325
+ onAnimationStart?: () => void
326
+ /**
327
+ * Called when the figure comes to rest, with the value it shows: once for a
328
+ * run of changes that arrived while it was moving. Snapped changes fire neither.
329
+ */
330
+ onAnimationEnd?: (value: number) => void
217
331
  /** Receives the native Nitro object once the view is mounted. */
218
332
  onNativeRef?: (ref: NitroNumberRef) => void
219
333
  }
@@ -241,6 +355,9 @@ interface Size {
241
355
  height: number
242
356
  }
243
357
 
358
+ const EMPTY: number[] = []
359
+ const EMPTY_STRINGS: string[] = []
360
+
244
361
  /** Each transition's own timing, used when the props leave it unsaid. */
245
362
  const TRANSITION_DEFAULTS: Record<NitroNumberTransition, { duration: number; easing: NitroNumberEasing; stagger: number }> = {
246
363
  roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
@@ -291,12 +408,24 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
291
408
  loading,
292
409
  shimmerColor,
293
410
  shimmerDuration,
411
+ shimmerAngle,
412
+ shimmerWidth,
413
+ shimmerBaseColor,
414
+ shimmerDirection,
415
+ shimmerDelay,
294
416
  fontSize,
295
417
  prefixFontSize,
296
418
  suffixFontSize,
297
419
  affixAlign,
298
420
  prefixAlign,
299
421
  suffixAlign,
422
+ letterSpacing,
423
+ prefixSpacing,
424
+ suffixSpacing,
425
+ prefixOffset,
426
+ suffixOffset,
427
+ tabularNums,
428
+ format,
300
429
  adjustsFontSizeToFit,
301
430
  minimumFontScale,
302
431
  allowFontScaling,
@@ -305,6 +434,22 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
305
434
  fontFamily,
306
435
  color,
307
436
  textAlign,
437
+ signDisplay,
438
+ plusSign,
439
+ minusSign,
440
+ prefixColor,
441
+ suffixColor,
442
+ fractionColor,
443
+ fractionFontSize,
444
+ fractionAlign,
445
+ digitGlyphs,
446
+ groupingSizes,
447
+ digits,
448
+ continuous,
449
+ animated,
450
+ respectReduceMotion,
451
+ onAnimationStart,
452
+ onAnimationEnd,
308
453
  onNativeRef,
309
454
  style,
310
455
  ...viewProps
@@ -320,6 +465,10 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
320
465
  latestOnRevealMilestone.current = onRevealMilestone
321
466
  const latestValue = useRef(value)
322
467
  latestValue.current = value
468
+ const latestOnAnimationStart = useRef(onAnimationStart)
469
+ latestOnAnimationStart.current = onAnimationStart
470
+ const latestOnAnimationEnd = useRef(onAnimationEnd)
471
+ latestOnAnimationEnd.current = onAnimationEnd
323
472
 
324
473
  const [size, setSize] = useState<Size | null>(null)
325
474
 
@@ -363,6 +512,21 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
363
512
  }),
364
513
  []
365
514
  )
515
+ const onAnimationStartCallback = useMemo(
516
+ () =>
517
+ callback(() => {
518
+ latestOnAnimationStart.current?.()
519
+ }),
520
+ []
521
+ )
522
+ // The figure a compact format rolls is not the value (1.2 for 1,234): report the value.
523
+ const onAnimationEndCallback = useMemo(
524
+ () =>
525
+ callback((shown: number) => {
526
+ latestOnAnimationEnd.current?.(compactRef.current ? latestValue.current : shown)
527
+ }),
528
+ []
529
+ )
366
530
  // A new array literal each render must not re-set the native prop. Always an
367
531
  // array (empty = no tiers): removing the prop would reach native as `null`,
368
532
  // which Nitro's array parser rejects ("Value is null, expected an Object").
@@ -381,7 +545,7 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
381
545
  jumpTo: (next) => nativeRef.current?.jumpTo(next),
382
546
  animateTo: (next) => nativeRef.current?.animateTo(next),
383
547
  revealTo: (next) => nativeRef.current?.revealTo(next),
384
- getValue: () => nativeRef.current?.value ?? latestValue.current,
548
+ getValue: () => (compactRef.current ? latestValue.current : nativeRef.current?.value ?? latestValue.current),
385
549
  get native() {
386
550
  return nativeRef.current
387
551
  },
@@ -401,11 +565,45 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
401
565
  () => toProcessedColor(shimmerColor) ?? Infinity,
402
566
  [shimmerColor]
403
567
  )
568
+ const processedShimmerBase = useMemo(() => toProcessedColor(shimmerBaseColor) ?? Infinity, [shimmerBaseColor])
404
569
  const processedFlashUp = useMemo(() => toProcessedColor(flashUpColor) ?? Infinity, [flashUpColor])
405
570
  const processedFlashDown = useMemo(() => toProcessedColor(flashDownColor) ?? Infinity, [flashDownColor])
406
571
  const numericWeight = toNumericWeight(fontWeight) ?? 400
407
572
  const resolvedFontSize = fontSize ?? 32
408
573
  const resolvedAffixAlign = affixAlign ?? 'baseline'
574
+ const derived = format ? formatProps(format) : undefined
575
+ // Compact notation: "1.2K" rolls the figure 1.2 and swaps the suffix.
576
+ const compact = format && derived?.compact ? compactParts(format, value) : undefined
577
+ const compactRef = useRef(false)
578
+ compactRef.current = compact !== undefined
579
+ // Which way the value moved, for a compact figure that fell while the value grew (999 → 1K).
580
+ const previousValue = useRef(value)
581
+ const compactDirection = compact && direction === undefined ? (value >= previousValue.current ? 'up' : 'down') : undefined
582
+ previousValue.current = value
583
+ const processedPrefixColor = useMemo(() => toProcessedColor(prefixColor) ?? Infinity, [prefixColor])
584
+ const processedSuffixColor = useMemo(() => toProcessedColor(suffixColor) ?? Infinity, [suffixColor])
585
+ const processedFractionColor = useMemo(() => toProcessedColor(fractionColor) ?? Infinity, [fractionColor])
586
+ // Arrays reach native only when their contents change.
587
+ const digitMaxKey = digits ? JSON.stringify(digits) : ''
588
+ const digitMax = useMemo(() => {
589
+ if (!digits) return EMPTY
590
+ const out: number[] = []
591
+ for (const [position, spec] of Object.entries(digits)) {
592
+ const index = Number(position)
593
+ if (!Number.isInteger(index) || index < 0 || index >= 20) continue
594
+ while (out.length <= index) out.push(9)
595
+ out[index] = spec.max
596
+ }
597
+ return out
598
+ // eslint-disable-next-line react-hooks/exhaustive-deps
599
+ }, [digitMaxKey])
600
+ const glyphs = digitGlyphs ?? derived?.digitGlyphs ?? EMPTY_STRINGS
601
+ const glyphsKey = glyphs.join('|')
602
+ const stableGlyphs = useMemo(() => glyphs, [glyphsKey]) // eslint-disable-line react-hooks/exhaustive-deps
603
+ const groups = groupingSizes ?? derived?.groupingSizes ?? EMPTY
604
+ const groupsKey = groups.join(',')
605
+ const stableGroups = useMemo(() => groups, [groupsKey]) // eslint-disable-line react-hooks/exhaustive-deps
606
+ const still = animated === false
409
607
 
410
608
  const autoSize = useMemo(
411
609
  () =>
@@ -429,26 +627,26 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
429
627
  {...viewProps}
430
628
  style={[autoSize, style]}
431
629
  hybridRef={hybridRef}
432
- value={value}
433
- fractionDigits={fractionDigits ?? 0}
434
- minimumIntegerDigits={minimumIntegerDigits ?? 1}
435
- groupingSeparator={groupingSeparator ?? ''}
436
- decimalSeparator={decimalSeparator ?? '.'}
437
- prefix={prefix ?? ''}
438
- suffix={suffix ?? ''}
630
+ value={compact ? compact.value : value}
631
+ fractionDigits={fractionDigits ?? compact?.fractionDigits ?? derived?.fractionDigits ?? 0}
632
+ minimumIntegerDigits={minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1}
633
+ groupingSeparator={groupingSeparator ?? derived?.groupingSeparator ?? ''}
634
+ decimalSeparator={decimalSeparator ?? derived?.decimalSeparator ?? '.'}
635
+ prefix={prefix ?? compact?.prefix ?? derived?.prefix ?? ''}
636
+ suffix={suffix ?? compact?.suffix ?? derived?.suffix ?? ''}
439
637
  transition={transition ?? 'roll'}
440
638
  flashUpColor={processedFlashUp}
441
639
  flashDownColor={processedFlashDown}
442
640
  flashDuration={flashDuration ?? 600}
443
641
  popOnChange={popOnChange ?? 0}
444
- duration={duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration}
642
+ duration={still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration}
445
643
  easing={easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing}
446
644
  bounce={bounce ?? 0.15}
447
645
  stagger={stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger}
448
- rollDirection={direction ?? 'auto'}
646
+ rollDirection={direction ?? compactDirection ?? 'auto'}
449
647
  revealState={reveal === undefined ? 0 : reveal ? 2 : 1}
450
648
  revealStyle={revealStyle ?? 'count'}
451
- revealDuration={revealDuration ?? 2200}
649
+ revealDuration={still ? 0 : revealDuration ?? 2200}
452
650
  revealBounce={revealBounce ?? 0.12}
453
651
  revealGrow={revealGrow ?? 0.2}
454
652
  revealStagger={revealStagger ?? 200}
@@ -456,15 +654,41 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
456
654
  revealMilestoneHold={revealMilestoneHold ?? 0}
457
655
  onRevealEnd={onRevealEndCallback}
458
656
  onRevealMilestone={onRevealMilestoneCallback}
657
+ onAnimationStart={onAnimationStartCallback}
658
+ onAnimationEnd={onAnimationEndCallback}
459
659
  loading={loading ?? false}
460
660
  shimmerColor={processedShimmerColor}
461
661
  shimmerDuration={shimmerDuration ?? 950}
662
+ shimmerAngle={shimmerAngle ?? 31}
663
+ shimmerWidth={shimmerWidth ?? 1}
664
+ shimmerBaseColor={processedShimmerBase}
665
+ shimmerDirection={shimmerDirection ?? 'auto'}
666
+ shimmerDelay={shimmerDelay ?? 0}
462
667
  fontSize={resolvedFontSize}
463
668
  prefixFontSize={prefixFontSize ?? resolvedFontSize}
464
669
  suffixFontSize={suffixFontSize ?? resolvedFontSize}
465
670
  affixAlign={resolvedAffixAlign}
466
671
  prefixAlign={prefixAlign ?? resolvedAffixAlign}
467
672
  suffixAlign={suffixAlign ?? resolvedAffixAlign}
673
+ letterSpacing={letterSpacing ?? 0}
674
+ prefixSpacing={prefixSpacing ?? Infinity}
675
+ suffixSpacing={suffixSpacing ?? Infinity}
676
+ prefixOffset={prefixOffset ?? 0}
677
+ suffixOffset={suffixOffset ?? 0}
678
+ tabularNums={tabularNums ?? true}
679
+ signDisplay={signDisplay ?? derived?.signDisplay ?? 'auto'}
680
+ plusSign={plusSign ?? derived?.plusSign ?? '+'}
681
+ minusSign={minusSign ?? derived?.minusSign ?? '-'}
682
+ digitGlyphs={stableGlyphs}
683
+ groupingSizes={stableGroups}
684
+ digitMax={digitMax}
685
+ continuous={continuous ?? false}
686
+ prefixColor={processedPrefixColor}
687
+ suffixColor={processedSuffixColor}
688
+ fractionColor={processedFractionColor}
689
+ fractionFontSize={fractionFontSize ?? Infinity}
690
+ fractionAlign={fractionAlign ?? 'baseline'}
691
+ respectReduceMotion={respectReduceMotion ?? true}
468
692
  adjustsFontSizeToFit={adjustsFontSizeToFit ?? false}
469
693
  minimumFontScale={minimumFontScale ?? 0.5}
470
694
  allowFontScaling={allowFontScaling ?? false}
@@ -0,0 +1,166 @@
1
+ import React, { useMemo } from 'react'
2
+ import {
3
+ I18nManager,
4
+ PixelRatio,
5
+ StyleSheet,
6
+ type ColorValue,
7
+ type TextStyle,
8
+ type ViewProps,
9
+ } from 'react-native'
10
+ import { getHostComponent, NitroModules } from 'react-native-nitro-modules'
11
+ import NitroTextViewConfig from '../nitrogen/generated/shared/json/NitroTextViewConfig.json'
12
+ import type { NitroTextMeasure, NitroTextMethods, NitroTextProps as NativeNitroTextProps } from './specs/NitroText.nitro'
13
+ import type { NitroInputEasing, NitroInputEffect } from './specs/NitroInput.nitro'
14
+ import type { NitroNumberShimmerDirection, NitroNumberTextAlign } from './specs/NitroNumber.nitro'
15
+ import { toNumericWeight, toProcessedColor } from './styleHelpers'
16
+
17
+ /** The raw Nitro host component behind {@link NitroText}. */
18
+ export const NativeNitroTextView = getHostComponent<NativeNitroTextProps, NitroTextMethods>(
19
+ 'NitroTextView',
20
+ () => NitroTextViewConfig
21
+ )
22
+
23
+ /** What a {@link NitroText} takes: the text, its typography, the morph's timing and the loading shimmer. */
24
+ export interface NitroTextProps extends Omit<ViewProps, 'children'> {
25
+ /** The text: a string or a number. A change morphs to it. */
26
+ children: string | number
27
+ /** Default: `17`. */
28
+ fontSize?: number
29
+ /** Like `Text`'s. Default: `'normal'`. */
30
+ fontWeight?: TextStyle['fontWeight']
31
+ /** Defaults to the system font. */
32
+ fontFamily?: string
33
+ /** Defaults to the platform's label colour. */
34
+ color?: ColorValue
35
+ /** Points after every character. Default: `0`. */
36
+ letterSpacing?: number
37
+ /** Where the line sits in a wider view. Default: `'auto'`, the start edge. */
38
+ textAlign?: NitroNumberTextAlign
39
+ /** Scale with the system text size, like `Text`. Default: `false`. */
40
+ allowFontScaling?: boolean
41
+ /** Cap for `allowFontScaling`; `0` is none. Default: `0`. */
42
+ maxFontSizeMultiplier?: number
43
+ /** Of a morph, in ms; `0` switches at once. Default: `400`. */
44
+ duration?: number
45
+ /** Default: `'expo'`. */
46
+ easing?: NitroInputEasing
47
+ /** Overshoot of the `'spring'` easing. Default: `0.15`. */
48
+ bounce?: number
49
+ /** How characters enter and leave: `'auto'` slides digits and fades letters. Default: `'auto'`. */
50
+ effect?: NitroInputEffect
51
+ /** Snap instead of morphing while Reduce Motion is on. Default: `true`. */
52
+ respectReduceMotion?: boolean
53
+ /** A loading glint through the text, as `NitroNumber`'s `loading`. Default: `false`. */
54
+ loading?: boolean
55
+ shimmerColor?: ColorValue
56
+ /** ms per sweep. Default: `950`. */
57
+ shimmerDuration?: number
58
+ /** Degrees; 0 upright. Default: `31`. */
59
+ shimmerAngle?: number
60
+ /** A fraction of the text's width. Default: `1`. */
61
+ shimmerWidth?: number
62
+ /** The glyphs' colour outside the band: a skeleton. Default: `color`. */
63
+ shimmerBaseColor?: ColorValue
64
+ /** Default: `'auto'`, the layout direction. */
65
+ shimmerDirection?: NitroNumberShimmerDirection
66
+ /** ms of pause after each sweep. Default: `0`. */
67
+ shimmerDelay?: number
68
+ }
69
+
70
+ let measurer: NitroTextMeasure | null = null
71
+ function measure(): NitroTextMeasure {
72
+ measurer ??= NitroModules.createHybridObject<NitroTextMeasure>('NitroTextMeasure')
73
+ return measurer
74
+ }
75
+ const lineHeights = new Map<string, number>()
76
+
77
+ /**
78
+ * A single line of text that morphs to the next, natively, as Torph does on
79
+ * the web: the characters the two share glide to their new places, digits
80
+ * matched by place ("$1,204" → "$1,318" rolls the hundreds and tens), and the
81
+ * rest fade out and in ("Sign in" → "Signing in…"). At rest it is one line
82
+ * drawn in one pass, like a label: no text field, no layer per character.
83
+ * It sizes itself to its text in the render that mounts it (a native
84
+ * measurement, synchronously); a `width` in `style` overrides it.
85
+ *
86
+ * Only the props that were set go to the native view, as
87
+ * react-native-plain-text does: every prop that crosses is converted and
88
+ * stored per view in the commit, and the native side holds the defaults.
89
+ */
90
+ export function NitroText({
91
+ children,
92
+ fontSize,
93
+ fontWeight,
94
+ fontFamily,
95
+ color,
96
+ letterSpacing,
97
+ textAlign,
98
+ allowFontScaling,
99
+ maxFontSizeMultiplier,
100
+ duration,
101
+ easing,
102
+ bounce,
103
+ effect,
104
+ respectReduceMotion,
105
+ loading,
106
+ shimmerColor,
107
+ shimmerDuration,
108
+ shimmerAngle,
109
+ shimmerWidth,
110
+ shimmerBaseColor,
111
+ shimmerDirection,
112
+ shimmerDelay,
113
+ style,
114
+ ...viewProps
115
+ }: NitroTextProps) {
116
+ const text = typeof children === 'string' ? children : String(children)
117
+ const scale = allowFontScaling
118
+ ? maxFontSizeMultiplier && maxFontSizeMultiplier > 0
119
+ ? Math.min(PixelRatio.getFontScale(), maxFontSizeMultiplier)
120
+ : PixelRatio.getFontScale()
121
+ : 1
122
+ const size = (fontSize ?? 17) * scale
123
+ const weight = fontWeight === undefined ? 400 : toNumericWeight(fontWeight) ?? 400
124
+ const family = fontFamily ?? ''
125
+ const spacing = letterSpacing ?? 0
126
+ const width = useMemo(() => measure().measure(text, size, weight, family, spacing), [text, size, weight, family, spacing])
127
+ const fontKey = `${size}|${weight}|${family}`
128
+ let height = lineHeights.get(fontKey)
129
+ if (height === undefined) {
130
+ height = measure().lineHeight(size, weight, family)
131
+ lineHeights.set(fontKey, height)
132
+ }
133
+
134
+ const native: NativeNitroTextProps & Record<string, unknown> = viewProps as never
135
+ native.text = text
136
+ native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style]
137
+ if (size !== 17) native.fontSize = size
138
+ if (weight !== 400) native.fontWeight = weight
139
+ if (family !== '') native.fontFamily = family
140
+ if (spacing !== 0) native.letterSpacing = spacing
141
+ const processedColor = toProcessedColor(color)
142
+ if (processedColor !== undefined) native.color = processedColor
143
+ if (textAlign !== undefined) native.textAlign = textAlign
144
+ if (duration !== undefined) native.duration = duration
145
+ if (easing !== undefined) native.easing = easing
146
+ if (bounce !== undefined) native.bounce = bounce
147
+ if (effect !== undefined) native.effect = effect
148
+ if (respectReduceMotion !== undefined) native.respectReduceMotion = respectReduceMotion
149
+ if (loading !== undefined) native.loading = loading
150
+ const processedShimmerColor = toProcessedColor(shimmerColor)
151
+ if (processedShimmerColor !== undefined) native.shimmerColor = processedShimmerColor
152
+ if (shimmerDuration !== undefined) native.shimmerDuration = shimmerDuration
153
+ if (shimmerAngle !== undefined) native.shimmerAngle = shimmerAngle
154
+ if (shimmerWidth !== undefined) native.shimmerWidth = shimmerWidth
155
+ const processedShimmerBaseColor = toProcessedColor(shimmerBaseColor)
156
+ if (processedShimmerBaseColor !== undefined) native.shimmerBaseColor = processedShimmerBaseColor
157
+ if (shimmerDirection !== undefined) native.shimmerDirection = shimmerDirection
158
+ if (shimmerDelay !== undefined) native.shimmerDelay = shimmerDelay
159
+ // The start edge follows the layout direction, the app's unless the style sets one.
160
+ const direction = style == null ? undefined : (StyleSheet.flatten(style) as { direction?: unknown }).direction
161
+ if (direction === 'rtl' || (direction !== 'ltr' && I18nManager.isRTL)) native.rightToLeft = true
162
+ // The native view is the accessibility element, labelled with its text and
163
+ // announced as text. A label from outside takes over, on this view.
164
+ if (native.accessibilityLabel != null && native.accessible === undefined) native.accessible = true
165
+ return <NativeNitroTextView {...native} />
166
+ }
@@ -0,0 +1,68 @@
1
+ import React, { forwardRef } from 'react'
2
+ import { NitroNumber, type NitroNumberHandle, type NitroNumberProps } from './NitroNumber'
3
+
4
+ /** How a {@link NitroTime} lays the time out. */
5
+ export type NitroTimeFormat = 'm:ss' | 'mm:ss' | 'h:mm:ss' | 'hh:mm:ss'
6
+
7
+ export interface NitroTimeProps
8
+ extends Omit<
9
+ NitroNumberProps,
10
+ | 'value'
11
+ | 'digits'
12
+ | 'groupingSizes'
13
+ | 'groupingSeparator'
14
+ | 'minimumIntegerDigits'
15
+ | 'fractionDigits'
16
+ | 'decimalSeparator'
17
+ | 'format'
18
+ > {
19
+ /** The time in whole seconds (a timer's elapsed time, a countdown's remaining one). Negatives show as 0. */
20
+ seconds: number
21
+ /** Default: `'m:ss'`. Without hours the minutes run past 59 (125:00). */
22
+ timeFormat?: NitroTimeFormat
23
+ /** Between the fields. Default: `':'`. */
24
+ separator?: string
25
+ }
26
+
27
+ const LAYOUT: Record<NitroTimeFormat, { hours: boolean; digits: number }> = {
28
+ 'm:ss': { hours: false, digits: 3 },
29
+ 'mm:ss': { hours: false, digits: 4 },
30
+ 'h:mm:ss': { hours: true, digits: 5 },
31
+ 'hh:mm:ss': { hours: true, digits: 6 },
32
+ }
33
+
34
+ // The tens of seconds, and of minutes when hours are shown, wrap after 5.
35
+ const SECONDS = { 1: { max: 5 } }
36
+ const MINUTES_AND_SECONDS = { 1: { max: 5 }, 3: { max: 5 } }
37
+ // One separator before the seconds: 125:00 is 125 minutes, not 1:25:00.
38
+ const MINUTES_ONLY = [2, 0]
39
+ const PAIRS = [2]
40
+
41
+ /**
42
+ * A clock, a timer or a countdown: `NitroNumber` with the time as its figure
43
+ * (12:34:56 is 123456), grouped in pairs, and the tens of seconds and minutes
44
+ * wrapping after 5, so 0:59 → 1:00 turns them one step, as a clock's wheels
45
+ * do, instead of rolling back through 4, 3, 2, 1.
46
+ */
47
+ export const NitroTime = forwardRef<NitroNumberHandle, NitroTimeProps>(function NitroTime(
48
+ { seconds, timeFormat = 'm:ss', separator = ':', ...props },
49
+ ref
50
+ ) {
51
+ const layout = LAYOUT[timeFormat]
52
+ const total = Math.max(0, Math.floor(Number.isFinite(seconds) ? seconds : 0))
53
+ const s = total % 60
54
+ const value = layout.hours
55
+ ? Math.floor(total / 3600) * 10000 + (Math.floor(total / 60) % 60) * 100 + s
56
+ : Math.floor(total / 60) * 100 + s
57
+ return (
58
+ <NitroNumber
59
+ ref={ref}
60
+ value={value}
61
+ minimumIntegerDigits={layout.digits}
62
+ groupingSeparator={separator}
63
+ groupingSizes={layout.hours ? PAIRS : MINUTES_ONLY}
64
+ digits={layout.hours ? MINUTES_AND_SECONDS : SECONDS}
65
+ {...props}
66
+ />
67
+ )
68
+ })