react-native-nitro-input 0.3.0 → 0.3.2

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 (150) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +120 -5
  3. package/android/src/main/cpp/JMaskEngine.cpp +45 -0
  4. package/android/src/main/cpp/JMaskEngine.hpp +9 -0
  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 +42 -2
  8. package/android/src/main/cpp/JRollingEngine.hpp +9 -1
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +24 -0
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +76 -1
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +88 -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/MaskEngine.kt +16 -0
  15. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
  16. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +96 -6
  17. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +388 -136
  18. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroTextView.kt +868 -0
  19. package/android/src/main/java/com/margelo/nitro/nitroinput/ReflowEngine.kt +21 -0
  20. package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +13 -2
  21. package/cpp/MaskEngine.cpp +294 -33
  22. package/cpp/MaskEngine.hpp +68 -0
  23. package/cpp/RollingEngine.cpp +92 -8
  24. package/cpp/RollingEngine.hpp +36 -2
  25. package/ios/HybridNitroInputView.swift +18 -0
  26. package/ios/HybridNitroNumberFormatPlatform.swift +87 -9
  27. package/ios/HybridNitroNumberView.swift +82 -1
  28. package/ios/HybridNitroTextView.swift +134 -0
  29. package/ios/NitroInputView.swift +125 -7
  30. package/ios/NitroNumberView.swift +368 -135
  31. package/ios/NitroTextView.swift +583 -0
  32. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
  33. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
  34. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  35. package/lib/commonjs/src/NitroInput.js +15 -2
  36. package/lib/commonjs/src/NitroNumber.js +52 -3
  37. package/lib/commonjs/src/NitroText.js +138 -0
  38. package/lib/commonjs/src/NitroTime.js +65 -0
  39. package/lib/commonjs/src/formatProps.js +76 -16
  40. package/lib/commonjs/src/index.js +6 -1
  41. package/lib/commonjs/src/specs/NitroText.nitro.js +2 -0
  42. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
  43. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
  44. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  45. package/lib/module/src/NitroInput.js +15 -2
  46. package/lib/module/src/NitroNumber.js +53 -4
  47. package/lib/module/src/NitroText.js +98 -0
  48. package/lib/module/src/NitroTime.js +29 -0
  49. package/lib/module/src/formatProps.js +76 -17
  50. package/lib/module/src/index.js +2 -0
  51. package/lib/module/src/specs/NitroText.nitro.js +1 -0
  52. package/lib/typescript/src/NitroInput.d.ts +39 -1
  53. package/lib/typescript/src/NitroNumber.d.ts +79 -1
  54. package/lib/typescript/src/NitroText.d.ts +67 -0
  55. package/lib/typescript/src/NitroTime.d.ts +19 -0
  56. package/lib/typescript/src/formatProps.d.ts +30 -4
  57. package/lib/typescript/src/index.d.ts +5 -2
  58. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +43 -0
  59. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +67 -0
  60. package/lib/typescript/src/specs/NitroText.nitro.d.ts +60 -0
  61. package/nitro.json +20 -0
  62. package/nitrogen/generated/android/NitroInput+autolinking.cmake +6 -0
  63. package/nitrogen/generated/android/NitroInputOnLoad.cpp +34 -0
  64. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +102 -0
  65. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +12 -0
  66. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +243 -0
  67. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +40 -0
  68. package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp +58 -0
  69. package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.hpp +64 -0
  70. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +253 -0
  71. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +104 -0
  72. package/nitrogen/generated/android/c++/JNitroInputCharacterMapping.hpp +61 -0
  73. package/nitrogen/generated/android/c++/JNitroInputMaskAffinity.hpp +64 -0
  74. package/nitrogen/generated/android/c++/JNitroInputTextCase.hpp +61 -0
  75. package/nitrogen/generated/android/c++/JNitroNumberShimmerDirection.hpp +61 -0
  76. package/nitrogen/generated/android/c++/JNitroNumberSignDisplay.hpp +67 -0
  77. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +30 -0
  78. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +100 -0
  79. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +174 -0
  80. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.hpp +54 -0
  81. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +36 -0
  82. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +136 -0
  83. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextMeasureSpec.kt +60 -0
  84. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +179 -0
  85. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputCharacterMapping.kt +56 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputMaskAffinity.kt +25 -0
  87. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextCase.kt +24 -0
  88. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberShimmerDirection.kt +24 -0
  89. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberSignDisplay.kt +26 -0
  90. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewManager.kt +96 -0
  91. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewStateUpdater.kt +23 -0
  92. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +34 -0
  93. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +146 -11
  94. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +25 -0
  95. package/nitrogen/generated/ios/NitroInputAutolinking.mm +16 -0
  96. package/nitrogen/generated/ios/NitroInputAutolinking.swift +24 -0
  97. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +50 -0
  98. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +146 -0
  99. package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.cpp +11 -0
  100. package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.hpp +90 -0
  101. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.cpp +11 -0
  102. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +233 -0
  103. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +36 -0
  104. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +120 -0
  105. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +264 -0
  106. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +6 -0
  107. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +78 -0
  108. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +20 -0
  109. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +493 -0
  110. package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec.swift +56 -0
  111. package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec_cxx.swift +150 -0
  112. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +75 -0
  113. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +608 -0
  114. package/nitrogen/generated/ios/swift/NitroInputCharacterMapping.swift +34 -0
  115. package/nitrogen/generated/ios/swift/NitroInputMaskAffinity.swift +48 -0
  116. package/nitrogen/generated/ios/swift/NitroInputTextCase.swift +44 -0
  117. package/nitrogen/generated/ios/swift/NitroNumberShimmerDirection.swift +44 -0
  118. package/nitrogen/generated/ios/swift/NitroNumberSignDisplay.swift +52 -0
  119. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +12 -0
  120. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +21 -0
  121. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +40 -0
  122. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +46 -0
  123. package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.cpp +22 -0
  124. package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.hpp +63 -0
  125. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +62 -0
  126. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +115 -0
  127. package/nitrogen/generated/shared/c++/NitroInputCharacterMapping.hpp +87 -0
  128. package/nitrogen/generated/shared/c++/NitroInputMaskAffinity.hpp +84 -0
  129. package/nitrogen/generated/shared/c++/NitroInputTextCase.hpp +80 -0
  130. package/nitrogen/generated/shared/c++/NitroNumberShimmerDirection.hpp +80 -0
  131. package/nitrogen/generated/shared/c++/NitroNumberSignDisplay.hpp +88 -0
  132. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +12 -0
  133. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +21 -0
  134. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +40 -0
  135. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +62 -0
  136. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +74 -0
  137. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +149 -0
  138. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
  139. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
  140. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
  141. package/package.json +2 -2
  142. package/src/NitroInput.tsx +73 -0
  143. package/src/NitroNumber.tsx +183 -9
  144. package/src/NitroText.tsx +166 -0
  145. package/src/NitroTime.tsx +68 -0
  146. package/src/formatProps.ts +108 -18
  147. package/src/index.ts +8 -0
  148. package/src/specs/NitroInput.nitro.ts +46 -0
  149. package/src/specs/NitroNumber.nitro.ts +69 -0
  150. package/src/specs/NitroText.nitro.ts +65 -0
@@ -64,6 +64,8 @@ function reactTagOf(host) {
64
64
  return typeof tag === 'number' ? tag : 0;
65
65
  }
66
66
  const EMPTY_NOTATIONS = [];
67
+ const EMPTY_STRINGS = [];
68
+ const EMPTY_MAPPINGS = [];
67
69
  /** Mounted fields, by the host instance React Native's registry stores. */
68
70
  const mountedFields = new WeakMap();
69
71
  let patchedRegistry = false;
@@ -137,7 +139,7 @@ function warnIncompatible(what) {
137
139
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
138
140
  * it to its content instead, and is on by default when the text reflows.
139
141
  */
140
- export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
142
+ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
141
143
  const nativeRef = useRef(null);
142
144
  // What React Native's registry stores for this field. The React host
143
145
  // instance when there is one (iOS), otherwise a stable per-instance token:
@@ -445,6 +447,17 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
445
447
  const stableNotations = useMemo(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
446
448
  // eslint-disable-next-line react-hooks/exhaustive-deps
447
449
  [notationsKey]);
450
+ // The same for the affinity formats and the character map.
451
+ const affinityKey = maskAffinityFormats != null && maskAffinityFormats.length > 0 ? JSON.stringify(maskAffinityFormats) : '';
452
+ const stableAffinityFormats = useMemo(() => (affinityKey !== '' && maskAffinityFormats ? [...maskAffinityFormats] : EMPTY_STRINGS),
453
+ // eslint-disable-next-line react-hooks/exhaustive-deps
454
+ [affinityKey]);
455
+ const characterMapKey = maskCharacterMap != null && Object.keys(maskCharacterMap).length > 0 ? JSON.stringify(maskCharacterMap) : '';
456
+ const stableCharacterMap = useMemo(() => characterMapKey !== '' && maskCharacterMap
457
+ ? Object.entries(maskCharacterMap).map(([from, to]) => ({ from, to }))
458
+ : EMPTY_MAPPINGS,
459
+ // eslint-disable-next-line react-hooks/exhaustive-deps
460
+ [characterMapKey]);
448
461
  const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
449
462
  const resolvedKeyboardType = keyboardType ??
450
463
  (inputMode != null
@@ -507,7 +520,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
507
520
  ? { width: size.width, height: size.height }
508
521
  : { height: size.height }
509
522
  : { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
510
- return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
523
+ return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
511
524
  // As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
512
525
  // field's return key inserts a line break unless told to blur.
513
526
  (multiline
@@ -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 { NitroInputAffixAlign, NitroInputAutoCapitalize, NitroInputEasing, NitroInputEffect, NitroInputKeyboardAppearance, NitroInputKeyboardType, NitroInputLabelBehavior, NitroInputMethods, NitroInputMode, NitroInputProps as NativeNitroInputProps, NitroInputReturnKeyType, NitroInputSubmitBehavior, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputSignPlacement, NitroInputVariant, NitroInputNotation } from './specs/NitroInput.nitro';
4
+ import type { NitroInputAffixAlign, NitroInputAutoCapitalize, NitroInputEasing, NitroInputEffect, NitroInputKeyboardAppearance, NitroInputKeyboardType, NitroInputLabelBehavior, NitroInputMethods, NitroInputMode, NitroInputProps as NativeNitroInputProps, NitroInputReturnKeyType, NitroInputSubmitBehavior, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputSignPlacement, NitroInputVariant, NitroInputNotation, NitroInputMaskAffinity, NitroInputTextCase } from './specs/NitroInput.nitro';
5
5
  import { type NitroInputSelection, type NitroInputTransform } from './worklets';
6
6
  import type { NumberFormat } from './NumberFormat';
7
7
  /** React Native's `inputMode`, the HTML-aligned alias for `keyboardType`. */
@@ -136,6 +136,44 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
136
136
  maskAutocomplete?: boolean;
137
137
  /** `'mask'`: backspace walks back over autocompleted constants. Default: `false`. */
138
138
  maskAutoSkip?: boolean;
139
+ /**
140
+ * `'mask'`: more patterns the text may take, e.g. a 4-6-5 Amex card beside
141
+ * a 4-4-4-4 `mask`: `['{34}[00] [000000] [00000]', '{37}[00] [000000] [00000]']`.
142
+ * Every edit is masked with each and the best, by `maskAffinityStrategy`, is
143
+ * kept; `mask` wins ties.
144
+ */
145
+ maskAffinityFormats?: string[];
146
+ /**
147
+ * `'mask'`: how the best of `maskAffinityFormats` is chosen. `'wholeString'`
148
+ * the format that accepts the most characters and inserts the fewest,
149
+ * `'prefix'` the one whose output starts most like what was typed,
150
+ * `'capacity'` / `'extractedValueCapacity'` the fullest format that still
151
+ * holds all of the text / all of its value characters. Default: `'wholeString'`.
152
+ */
153
+ maskAffinityStrategy?: NitroInputMaskAffinity;
154
+ /** `'mask'`: uppercases or lowercases letters as they are typed or pasted. Default: `'none'`. */
155
+ maskTextCase?: NitroInputTextCase;
156
+ /**
157
+ * `'mask'`: characters replaced before masking, one character each:
158
+ * `{ 'С': 'C' }` turns a Cyrillic look-alike into a Latin letter,
159
+ * `{ ',': '.' }` lets a comma through to a dot-decimal mask. An empty
160
+ * replacement drops the character.
161
+ */
162
+ maskCharacterMap?: Record<string, string>;
163
+ /**
164
+ * `'mask'`: the character each empty slot shows in the kept placeholder and
165
+ * in `onChangeMask`'s tail. Default: `'_'` with `keepPlaceholder`, otherwise
166
+ * the slot's own notation character.
167
+ */
168
+ maskSlotPlaceholder?: string;
169
+ /**
170
+ * `'mask'`: keeps the rest of the placeholder visible after what has been
171
+ * typed: with `placeholder="1234 5678 9012"`, typing "12345" shows
172
+ * "1234 5" and then "678 9012" greyed. Without a `placeholder` the mask
173
+ * itself is shown, its empty slots as `maskSlotPlaceholder`:
174
+ * `+1 (212) ___-____`. Default: `false`.
175
+ */
176
+ keepPlaceholder?: boolean;
139
177
  /**
140
178
  * `'mask'` mode: called whenever the text changes, from a keystroke,
141
179
  * `setText` / `clear` or the `value` prop alike, with the masked text, the
@@ -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
  }