react-native-nitro-input 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +21 -0
  3. package/NitroInput.podspec +54 -0
  4. package/README.md +524 -0
  5. package/android/CMakeLists.txt +52 -0
  6. package/android/build.gradle +158 -0
  7. package/android/fix-prefab.gradle +51 -0
  8. package/android/gradle.properties +4 -0
  9. package/android/src/main/AndroidManifest.xml +2 -0
  10. package/android/src/main/cpp/JAmountFormatter.cpp +70 -0
  11. package/android/src/main/cpp/JAmountFormatter.hpp +45 -0
  12. package/android/src/main/cpp/JMaskEngine.cpp +81 -0
  13. package/android/src/main/cpp/JMaskEngine.hpp +52 -0
  14. package/android/src/main/cpp/JMorphEngine.cpp +132 -0
  15. package/android/src/main/cpp/JMorphEngine.hpp +54 -0
  16. package/android/src/main/cpp/JNitroInputWorklets.cpp +83 -0
  17. package/android/src/main/cpp/JNitroInputWorklets.hpp +40 -0
  18. package/android/src/main/cpp/JOutlineGeometry.cpp +58 -0
  19. package/android/src/main/cpp/JOutlineGeometry.hpp +55 -0
  20. package/android/src/main/cpp/cpp-adapter.cpp +19 -0
  21. package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +35 -0
  22. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +730 -0
  23. package/android/src/main/java/com/margelo/nitro/nitroinput/MaskEngine.kt +50 -0
  24. package/android/src/main/java/com/margelo/nitro/nitroinput/MorphEngine.kt +47 -0
  25. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +24 -0
  26. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +2176 -0
  27. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputWorklets.kt +34 -0
  28. package/android/src/main/java/com/margelo/nitro/nitroinput/OutlineGeometry.kt +71 -0
  29. package/cpp/AmountFormatter.cpp +346 -0
  30. package/cpp/AmountFormatter.hpp +88 -0
  31. package/cpp/MaskEngine.cpp +596 -0
  32. package/cpp/MaskEngine.hpp +136 -0
  33. package/cpp/MorphEngine.cpp +904 -0
  34. package/cpp/MorphEngine.hpp +213 -0
  35. package/cpp/OutlineGeometry.cpp +159 -0
  36. package/cpp/OutlineGeometry.hpp +107 -0
  37. package/cpp/worklets/HybridNitroInputWorklets.cpp +30 -0
  38. package/cpp/worklets/HybridNitroInputWorklets.hpp +30 -0
  39. package/cpp/worklets/NitroInputWorkletsBridge.cpp +203 -0
  40. package/cpp/worklets/NitroInputWorkletsBridge.hpp +52 -0
  41. package/cpp/worklets/NitroInputWorkletsBridgeJSI.hpp +23 -0
  42. package/ios/HybridMorphInputView.swift +710 -0
  43. package/ios/NitroInputCommands.mm +66 -0
  44. package/ios/NitroInputView.swift +2600 -0
  45. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +101 -0
  46. package/lib/commonjs/src/MorphInput.js +42 -0
  47. package/lib/commonjs/src/NitroInput.js +623 -0
  48. package/lib/commonjs/src/index.js +12 -0
  49. package/lib/commonjs/src/specs/NitroInput.nitro.js +2 -0
  50. package/lib/commonjs/src/specs/NitroInputWorklets.nitro.js +2 -0
  51. package/lib/commonjs/src/useNitroInputState.js +58 -0
  52. package/lib/commonjs/src/worklets.js +226 -0
  53. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +101 -0
  54. package/lib/module/package.json +1 -0
  55. package/lib/module/src/MorphInput.js +6 -0
  56. package/lib/module/src/NitroInput.js +584 -0
  57. package/lib/module/src/index.js +4 -0
  58. package/lib/module/src/specs/NitroInput.nitro.js +1 -0
  59. package/lib/module/src/specs/NitroInputWorklets.nitro.js +1 -0
  60. package/lib/module/src/useNitroInputState.js +55 -0
  61. package/lib/module/src/worklets.js +214 -0
  62. package/lib/typescript/src/MorphInput.d.ts +18 -0
  63. package/lib/typescript/src/NitroInput.d.ts +411 -0
  64. package/lib/typescript/src/index.d.ts +6 -0
  65. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +390 -0
  66. package/lib/typescript/src/specs/NitroInputWorklets.nitro.d.ts +15 -0
  67. package/lib/typescript/src/useNitroInputState.d.ts +55 -0
  68. package/lib/typescript/src/worklets.d.ts +117 -0
  69. package/nitro.json +37 -0
  70. package/nitrogen/generated/.gitattributes +1 -0
  71. package/nitrogen/generated/android/NitroInput+autolinking.cmake +84 -0
  72. package/nitrogen/generated/android/NitroInput+autolinking.gradle +27 -0
  73. package/nitrogen/generated/android/NitroInputOnLoad.cpp +78 -0
  74. package/nitrogen/generated/android/NitroInputOnLoad.hpp +34 -0
  75. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  76. package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
  77. package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
  78. package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
  79. package/nitrogen/generated/android/c++/JFunc_void_std__string_double.hpp +76 -0
  80. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string_std__string_bool.hpp +76 -0
  81. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +1073 -0
  82. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +254 -0
  83. package/nitrogen/generated/android/c++/JNitroInputAffixAlign.hpp +64 -0
  84. package/nitrogen/generated/android/c++/JNitroInputAutoCapitalize.hpp +64 -0
  85. package/nitrogen/generated/android/c++/JNitroInputEasing.hpp +67 -0
  86. package/nitrogen/generated/android/c++/JNitroInputEffect.hpp +61 -0
  87. package/nitrogen/generated/android/c++/JNitroInputKeyboardAppearance.hpp +61 -0
  88. package/nitrogen/generated/android/c++/JNitroInputKeyboardType.hpp +79 -0
  89. package/nitrogen/generated/android/c++/JNitroInputLabelBehavior.hpp +58 -0
  90. package/nitrogen/generated/android/c++/JNitroInputMode.hpp +61 -0
  91. package/nitrogen/generated/android/c++/JNitroInputNotation.hpp +65 -0
  92. package/nitrogen/generated/android/c++/JNitroInputReturnKeyType.hpp +70 -0
  93. package/nitrogen/generated/android/c++/JNitroInputSignPlacement.hpp +58 -0
  94. package/nitrogen/generated/android/c++/JNitroInputSubmitBehavior.hpp +61 -0
  95. package/nitrogen/generated/android/c++/JNitroInputTextAlign.hpp +64 -0
  96. package/nitrogen/generated/android/c++/JNitroInputTextAlignVertical.hpp +64 -0
  97. package/nitrogen/generated/android/c++/JNitroInputVariant.hpp +61 -0
  98. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +529 -0
  99. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.hpp +54 -0
  100. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_bool.kt +78 -0
  101. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double.kt +78 -0
  102. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +78 -0
  103. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_std__string.kt +78 -0
  104. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_std__string_double.kt +78 -0
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_std__string_std__string_std__string_bool.kt +78 -0
  106. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +711 -0
  107. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputAffixAlign.kt +25 -0
  108. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputAutoCapitalize.kt +25 -0
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputEasing.kt +26 -0
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputEffect.kt +24 -0
  111. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputKeyboardAppearance.kt +24 -0
  112. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputKeyboardType.kt +30 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputLabelBehavior.kt +23 -0
  114. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputMode.kt +24 -0
  115. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputNotation.kt +61 -0
  116. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputOnLoad.kt +35 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputReturnKeyType.kt +27 -0
  118. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSignPlacement.kt +23 -0
  119. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSubmitBehavior.kt +24 -0
  120. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextAlign.kt +25 -0
  121. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextAlignVertical.kt +25 -0
  122. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputVariant.kt +24 -0
  123. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroInputViewManager.kt +96 -0
  124. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroInputViewStateUpdater.kt +23 -0
  125. package/nitrogen/generated/ios/NitroInput+autolinking.rb +62 -0
  126. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +81 -0
  127. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +348 -0
  128. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +92 -0
  129. package/nitrogen/generated/ios/NitroInputAutolinking.mm +43 -0
  130. package/nitrogen/generated/ios/NitroInputAutolinking.swift +26 -0
  131. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.cpp +11 -0
  132. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +769 -0
  133. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +690 -0
  134. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  135. package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
  136. package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
  137. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
  138. package/nitrogen/generated/ios/swift/Func_void_std__string_double.swift +46 -0
  139. package/nitrogen/generated/ios/swift/Func_void_std__string_std__string_std__string_bool.swift +46 -0
  140. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +154 -0
  141. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +1454 -0
  142. package/nitrogen/generated/ios/swift/NitroInputAffixAlign.swift +48 -0
  143. package/nitrogen/generated/ios/swift/NitroInputAutoCapitalize.swift +48 -0
  144. package/nitrogen/generated/ios/swift/NitroInputEasing.swift +52 -0
  145. package/nitrogen/generated/ios/swift/NitroInputEffect.swift +44 -0
  146. package/nitrogen/generated/ios/swift/NitroInputKeyboardAppearance.swift +44 -0
  147. package/nitrogen/generated/ios/swift/NitroInputKeyboardType.swift +68 -0
  148. package/nitrogen/generated/ios/swift/NitroInputLabelBehavior.swift +40 -0
  149. package/nitrogen/generated/ios/swift/NitroInputMode.swift +44 -0
  150. package/nitrogen/generated/ios/swift/NitroInputNotation.swift +39 -0
  151. package/nitrogen/generated/ios/swift/NitroInputReturnKeyType.swift +56 -0
  152. package/nitrogen/generated/ios/swift/NitroInputSignPlacement.swift +40 -0
  153. package/nitrogen/generated/ios/swift/NitroInputSubmitBehavior.swift +44 -0
  154. package/nitrogen/generated/ios/swift/NitroInputTextAlign.swift +48 -0
  155. package/nitrogen/generated/ios/swift/NitroInputTextAlignVertical.swift +48 -0
  156. package/nitrogen/generated/ios/swift/NitroInputVariant.swift +44 -0
  157. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +213 -0
  158. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +300 -0
  159. package/nitrogen/generated/shared/c++/HybridNitroInputWorkletsSpec.cpp +21 -0
  160. package/nitrogen/generated/shared/c++/HybridNitroInputWorkletsSpec.hpp +62 -0
  161. package/nitrogen/generated/shared/c++/NitroInputAffixAlign.hpp +84 -0
  162. package/nitrogen/generated/shared/c++/NitroInputAutoCapitalize.hpp +84 -0
  163. package/nitrogen/generated/shared/c++/NitroInputEasing.hpp +88 -0
  164. package/nitrogen/generated/shared/c++/NitroInputEffect.hpp +80 -0
  165. package/nitrogen/generated/shared/c++/NitroInputKeyboardAppearance.hpp +80 -0
  166. package/nitrogen/generated/shared/c++/NitroInputKeyboardType.hpp +104 -0
  167. package/nitrogen/generated/shared/c++/NitroInputLabelBehavior.hpp +76 -0
  168. package/nitrogen/generated/shared/c++/NitroInputMode.hpp +80 -0
  169. package/nitrogen/generated/shared/c++/NitroInputNotation.hpp +91 -0
  170. package/nitrogen/generated/shared/c++/NitroInputReturnKeyType.hpp +92 -0
  171. package/nitrogen/generated/shared/c++/NitroInputSignPlacement.hpp +76 -0
  172. package/nitrogen/generated/shared/c++/NitroInputSubmitBehavior.hpp +80 -0
  173. package/nitrogen/generated/shared/c++/NitroInputTextAlign.hpp +84 -0
  174. package/nitrogen/generated/shared/c++/NitroInputTextAlignVertical.hpp +84 -0
  175. package/nitrogen/generated/shared/c++/NitroInputVariant.hpp +80 -0
  176. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +216 -0
  177. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +374 -0
  178. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +101 -0
  179. package/package.json +141 -0
  180. package/react-native.config.js +16 -0
  181. package/src/MorphInput.tsx +30 -0
  182. package/src/NitroInput.tsx +1364 -0
  183. package/src/index.ts +55 -0
  184. package/src/specs/NitroInput.nitro.ts +436 -0
  185. package/src/specs/NitroInputWorklets.nitro.ts +13 -0
  186. package/src/useNitroInputState.ts +101 -0
  187. package/src/worklets.ts +300 -0
package/README.md ADDED
@@ -0,0 +1,524 @@
1
+ # react-native-nitro-input
2
+
3
+ A native **text input** for React Native, built with
4
+ [Nitro Modules](https://nitro.margelo.com). `NitroInput` is the component: a
5
+ system text field (`UITextField` / `EditText`) that owns the keyboard, editing,
6
+ selection, paste and accessibility, with native formatting, native masking and
7
+ an outlined or filled frame with a floating label on top of it.
8
+
9
+ ```tsx
10
+ import { NitroInput } from 'react-native-nitro-input'
11
+
12
+ <NitroInput variant="outlined" label="Email address" keyboardType="email-address" />
13
+ ```
14
+
15
+ `MorphInput` is the same component with `morph` on, for the one case
16
+ where animating the characters is the point — an amount. It is not the default,
17
+ and for an ordinary form field you do not want it.
18
+
19
+ - **It is a real input.** Focus, blur, return key, keyboard types,
20
+ auto-capitalisation, max length, selection, the text-input registry, all the
21
+ usual. Not a re-implementation of text editing.
22
+ - **Masks are native.** `mode="mask"` compiles the pattern once into a state
23
+ machine in C++ and applies it below the keystroke — no JS round trip, no
24
+ caret fighting.
25
+ - **The outlined frame's notch is a real hole** in the stroked path, not
26
+ background paint over the line, so whatever is behind the field shows through
27
+ it. No Skia.
28
+ - **Amounts are formatted natively as you type.** In `mode="number"` every
29
+ keystroke is formatted on the native side before the field shows a frame:
30
+ grouping separators, one decimal separator, at most `fractionDigits`
31
+ decimals, a currency `prefix` / `suffix`, the caret kept where you typed. No
32
+ JS round trip, so none of the flicker, caret jumps or dropped keystrokes of a
33
+ controlled `TextInput` that formats in `onChangeText`.
34
+ - **Same formatting model as [`react-native-nitro-rolling-number`](https://www.npmjs.com/package/react-native-nitro-rolling-number)**:
35
+ prefix/suffix at their own font sizes, pinned to the top, bottom, baseline or
36
+ centre of the digits; grouping and decimal separators of your choice.
37
+ - **One C++ engine per concern** drives both platforms — formatting, masking,
38
+ the frame geometry, and (with `morph`) the glyph matching and curves. Swift
39
+ and Kotlin only measure, draw and talk to the keyboard.
40
+ - Fabric only (new architecture), React Native ≥ 0.78, Nitro Modules ≥ 0.37.
41
+
42
+ Docs: **https://ronickg.github.io/react-native-nitro-rolling-number/input**
43
+
44
+ ## Install
45
+
46
+ ```sh
47
+ bun add react-native-nitro-input react-native-nitro-modules
48
+ cd ios && pod install
49
+ ```
50
+
51
+ > **Android and Nitro 0.37:** Nitro never hands a Hybrid View its `backgroundColor`, `border*`, `opacity`, `transform`, `testID` or accessibility props on Android with React Native 0.86+ — the `style` on every example below would be dropped. Fixed upstream in [margelo/nitro#1655](https://github.com/margelo/nitro/pull/1655); until it ships, apply the [patch from this repository](https://github.com/ronickg/react-native-nitro-rolling-number/blob/main/patches/react-native-nitro-modules@0.37.1.patch) with `patchedDependencies` (Bun) or patch-package.
52
+
53
+ ## Usage
54
+
55
+ ### A text field
56
+
57
+ ```tsx
58
+ <NitroInput
59
+ placeholder="Your name"
60
+ fontSize={22}
61
+ autoCapitalize="words"
62
+ returnKeyType="done"
63
+ onSubmitEditing={({ text }) => save(text)}
64
+ style={{ width: '100%', height: 44, paddingHorizontal: 12, backgroundColor: '#F2F2F7', borderRadius: 10 }}
65
+ />
66
+ ```
67
+
68
+ `NitroInput` does not animate its characters: they appear the instant you type
69
+ them, the way a `TextInput` does. Pass `morph` (or use `MorphInput`, which is
70
+ that plus content sizing) to turn the glyph engine on — see
71
+ [An amount field](#an-amount-field-the-morph), which is where it earns itself.
72
+
73
+ ### A masked field
74
+
75
+ ```tsx
76
+ <NitroInput
77
+ mode="mask"
78
+ mask="+1 ([000]) [000]-[0000]"
79
+ placeholder="+1 (000) 000-0000"
80
+ keyboardType="number-pad"
81
+ maskAutoSkip
82
+ onChangeMask={(formatted, extracted, tail, complete) => {
83
+ setPhone(extracted) // "5551234567" — the characters the user gave
84
+ setDone(complete) // every mandatory slot filled
85
+ }}
86
+ />
87
+ ```
88
+
89
+ The pattern is compiled once into a linked state machine in C++ and shared by
90
+ both platforms, so the formatting, the caret and the "what is still missing"
91
+ tail all come from one place and cannot drift apart. `[…]` is an editable
92
+ block, `{…}` a literal the engine inserts for you. Built-in slots: `0` a
93
+ required digit, `9` an optional one, `A`/`a` letters, `_` any character, `…`
94
+ repeats the previous slot.
95
+
96
+ Add your own with `maskNotations`:
97
+
98
+ ```tsx
99
+ <NitroInput
100
+ mode="mask"
101
+ mask="#[HHHHHH]"
102
+ maskNotations={[{ character: 'H', characterSet: '0123456789ABCDEFabcdef', isOptional: false }]}
103
+ />
104
+ ```
105
+
106
+ `maskAutocomplete` (default `true`) fills in literals as soon as the slot
107
+ before them is satisfied; `maskAutoSkip` (default `false`) lets a backspace
108
+ step back over them. Autocompletion only runs when the caret is at the end, so
109
+ editing in the middle of a value does not fight you.
110
+
111
+ ### Outlined and filled frames
112
+
113
+ ```tsx
114
+ <NitroInput
115
+ variant="outlined"
116
+ label="Email address"
117
+ placeholder="you@example.com"
118
+ strokeColor="#94a3b8"
119
+ focusedStrokeColor="#2563eb"
120
+ cornerRadius={10}
121
+ keyboardType="email-address"
122
+ style={{ width: '100%', height: 52 }}
123
+ />
124
+ ```
125
+
126
+ The label floats onto the top edge when the field is focused or holds text, and
127
+ the outline opens a notch for it. The notch is a **real hole in the stroked
128
+ path**, not a patch of background colour painted over the line, so whatever is
129
+ behind the field shows through it — no Skia, no masking, and it works over a
130
+ photo or a gradient. The geometry is shared C++ (`OutlineGeometry`) that both
131
+ platforms replay as the same move / line / arc commands, and every path has the
132
+ same verbs at every progress so Core Animation and `ValueAnimator` can
133
+ interpolate between them.
134
+
135
+ `variant="filled"` gives a filled field instead: a `fillColor`
136
+ background with a square bottom and an indicator rule along it.
137
+
138
+ The label runs 200 ms on a decelerate curve, and the notch is staggered 50 ms behind it opening and closes in 50 ms,
139
+ so the gap is never open under a label that has not arrived. All of it runs
140
+ inside the view, off a native focus callback — there is no React state to
141
+ declare and nothing crosses into JS per frame. That is the point of doing it
142
+ natively: a floating label built in React Native is an `Animated.Text` over a
143
+ `TextInput`, moved from focus and text state that reach JS after the field has
144
+ changed, so it lands a frame late and stutters when the JS thread is busy.
145
+
146
+ ### A multiline field
147
+
148
+ ```tsx
149
+ <NitroInput
150
+ multiline
151
+ numberOfLines={4}
152
+ placeholder="Tell us what happened"
153
+ style={{ width: '100%' }}
154
+ />
155
+ ```
156
+
157
+ `multiline` lets the text wrap. With `numberOfLines` (or `rows`) the field is
158
+ that many lines tall and scrolls past it; without it the field grows with its
159
+ content, and `scrollEnabled={false}` hands the height to the content entirely.
160
+ `textAlignVertical` says where the text sits in a taller box. A multiline field
161
+ is always drawn by the system view and is always `mode="text"`: the glyph
162
+ engine lays one run out on one baseline, and an amount, a mask and their
163
+ affixes are single-line ideas, so `morph`, `mode="number"`, `mode="mask"`,
164
+ `prefix` and `suffix` are ignored alongside it, with one warning each in
165
+ development. Its return key inserts a line break, as a `TextInput`'s does;
166
+ `submitBehavior="blurAndSubmit"` (or `blurOnSubmit`) makes it submit instead.
167
+
168
+ ### An amount field (the morph)
169
+
170
+ This is the one case the morph is for, so it uses `MorphInput` — `NitroInput`
171
+ with `morph` on, and with the box sized to its content so it grows as digits
172
+ arrive.
173
+
174
+ With the engine running, `mode="text"` fades and scales characters in and out
175
+ (Torph's text morph) while digits and separators slide in `mode="number"`,
176
+ unless you force one style with `effect="slide"` / `effect="fade"`.
177
+
178
+ ```tsx
179
+ import { MorphInput } from 'react-native-nitro-input'
180
+
181
+ const [amount, setAmount] = useState(NaN)
182
+
183
+ <MorphInput
184
+ mode="number"
185
+ prefix="$"
186
+ prefixFontSize={28}
187
+ affixAlign="top"
188
+ placeholder="0"
189
+ fractionDigits={2}
190
+ fontSize={48}
191
+ fontWeight="700"
192
+ textAlign="center"
193
+ style={{ width: '100%' }}
194
+ onChangeValue={setAmount} // 1234.5, or NaN while empty
195
+ onChangeText={(text) => {}} // "1,234.5"
196
+ />
197
+ ```
198
+
199
+ Type `1234` and the field shows `$1,234`: the `1` slides over to make room as
200
+ the comma arrives from below, the `4` drops in from above. Type `.5` and the
201
+ decimal point and the `5` follow. Backspace over the comma and it takes the
202
+ digit before it with it. A third decimal is rejected without a flicker.
203
+
204
+ Everything the user sees is formatted on the native side, synchronously, so
205
+ the JS thread only ever learns about the result. State the value in whatever
206
+ shape suits you (`onChangeValue` for the number, `onChangeText` for the
207
+ formatted string) and keep the field uncontrolled, or pass `value` to drive it:
208
+
209
+ ```tsx
210
+ const [text, setText] = useState('')
211
+
212
+ <MorphInput mode="number" value={text} onChangeText={setText} prefix="$" />
213
+ ```
214
+
215
+ A `value` that merely echoes `onChangeText` back never fights the user: native
216
+ already shows it. A `value` that differs (a "Max" button, a clamp) is applied
217
+ and morphs in.
218
+
219
+ ### Currency layouts
220
+
221
+ ```tsx
222
+ // "$" smaller than the amount, aligned to the top of the digits
223
+ <MorphInput mode="number" prefix="$" prefixFontSize={22} affixAlign="top" fontSize={44} />
224
+
225
+ // currency code after the amount, smaller and sitting on the baseline of the digits' ink
226
+ <MorphInput mode="number" suffix=" USD" suffixFontSize={18} suffixAlign="bottom" />
227
+
228
+ // European separators: 1.234,56
229
+ <MorphInput mode="number" groupingSeparator="." decimalSeparator="," />
230
+
231
+ // whole numbers only (no decimal key accepted), at most six digits
232
+ <MorphInput mode="number" fractionDigits={0} maxIntegerDigits={6} />
233
+
234
+ // a big centred amount that shrinks when it gets long
235
+ <MorphInput mode="number" fontSize={64} adjustsFontSizeToFit minimumFontScale={0.4} textAlign="center" style={{ width: '100%' }} />
236
+ ```
237
+
238
+ In a right-to-left layout the prefix sits at the right edge and the suffix at
239
+ the left, plain or morphed; the digits keep reading left to right.
240
+
241
+ Whatever the keyboard's decimal key produces (`.` or `,`) counts as the
242
+ decimal separator; nobody types a grouping separator on purpose. The rules
243
+ follow what a well-behaved amount field does: a decimal typed in the integer
244
+ part moves the decimal point (`1,234.5` with the caret after the `1` becomes
245
+ `1.23`), one typed inside the fraction is ignored, a leading `.5` stays `.5`
246
+ while typing (`setValue(0.5)` shows `0.5`), a digit typed in front of a lone
247
+ `0` replaces it, and deleting the decimal point merges the fraction into the
248
+ integer part (`1,234.56` → `123,456`).
249
+
250
+ ### Worklets: masks in JS and shared values, synchronously
251
+
252
+ With [`react-native-worklets`](https://docs.swmansion.com/react-native-worklets/)
253
+ installed (it comes with Reanimated 4), two things run on the UI thread while
254
+ the native input handles the keystroke, before a frame is drawn:
255
+
256
+ ```tsx
257
+ import { useSharedValue, useAnimatedStyle } from 'react-native-reanimated'
258
+
259
+ // A mask written in JS: lowercase, no symbols, always led by "@".
260
+ const usernameTransform: NitroInputTransform = ({ text }) => {
261
+ 'worklet'
262
+ const cleaned = text.replace(/[^0-9a-zA-Z_]/g, '').toLowerCase()
263
+ return { text: cleaned ? '@' + cleaned : '' }
264
+ }
265
+
266
+ <NitroInput placeholder="@username" autoCapitalize="none" transform={usernameTransform} />
267
+
268
+ // A shared value fed on every keystroke, no JS thread in between.
269
+ const progress = useSharedValue(0)
270
+ <NitroInput
271
+ mode="number"
272
+ onChangeValue={(value) => {
273
+ 'worklet'
274
+ progress.value = Number.isNaN(value) ? 0 : value / 10
275
+ }}
276
+ />
277
+ ```
278
+
279
+ - `transform` receives `{ text, previousText, selection, previousSelection }`
280
+ (code point offsets) and returns `{ text?, selection? }` or `null` to keep
281
+ the edit as is. Without a `selection` the caret keeps its place relative to
282
+ the edit. In `mode="number"` it runs after the native formatter. Create it
283
+ once (module scope or `useCallback`); a new function re-registers the worklet.
284
+ - **Every event callback** marked `'worklet'` runs on the UI thread instead of
285
+ the JS thread: `onChangeText`, `onChangeValue`, `onFocus`, `onBlur`,
286
+ `onSelectionChange`, `onSubmitEditing`, `onEndEditing` and `onKeyPress`. A
287
+ worklet handler is not also called on the JS thread. Plain functions keep
288
+ working as before, so this is opt-in per handler.
289
+ - Worklet handlers get the same event objects as the JS ones, except `target`
290
+ is always `0` and `eventCount` `0` where native does not send one: both are
291
+ JS-thread bookkeeping with nothing to read on the UI runtime.
292
+ - Everything degrades cleanly: without `react-native-worklets` the props are
293
+ ignored with one console warning, and the native code compiles without it.
294
+
295
+ ### The field's state as shared values
296
+
297
+ `useNitroInputState` wires those worklet callbacks into shared values, so an
298
+ animation can read the field on the UI thread without a single re-render.
299
+ Reanimated is not a dependency — pass its `useSharedValue` in:
300
+
301
+ ```tsx
302
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'
303
+ import { NitroInput, useNitroInputState } from 'react-native-nitro-input'
304
+
305
+ function Field() {
306
+ const field = useNitroInputState(useSharedValue)
307
+ const ring = useAnimatedStyle(() => ({
308
+ borderColor: withTiming(field.focused.value ? '#16a34a' : 'transparent'),
309
+ }))
310
+ return (
311
+ <Animated.View style={[styles.ring, ring]}>
312
+ <NitroInput variant="outlined" label="Worklet driven" {...field.handlers} />
313
+ </Animated.View>
314
+ )
315
+ }
316
+ ```
317
+
318
+ `field.text`, `field.value`, `field.focused` and `field.selection` are shared
319
+ values; `field.handlers` are the worklets that keep them current. Typing in
320
+ that field runs nothing on the JS thread and re-renders nothing.
321
+
322
+ A worklet can only reach what it closes over, unless worklets run in
323
+ [Bundle Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode/),
324
+ which gives them the whole bundle. That is what lets a `transform` use a real
325
+ library, here libphonenumber-js formatting a number as it is typed:
326
+
327
+ ```tsx
328
+ import { AsYouType } from 'libphonenumber-js/min'
329
+
330
+ const phoneTransform: NitroInputTransform = ({ text }) => {
331
+ 'worklet'
332
+ return { text: new AsYouType('US').input(text) }
333
+ }
334
+
335
+ <NitroInput placeholder="(555) 555-5555" keyboardType="phone-pad" transform={phoneTransform} />
336
+ ```
337
+
338
+ Bundle Mode is `['react-native-worklets/plugin', { bundleMode: true,
339
+ importForwarding: { moduleNames: ['libphonenumber-js/min'] } }]` in
340
+ `babel.config.js` (every library a worklet imports has to be listed by its
341
+ exact module name, or it is captured as a remote function the UI thread
342
+ cannot call), `getBundleModeMetroConfig(config)` from
343
+ `react-native-worklets/bundleMode` in `metro.config.js`, and the small Metro
344
+ patch Software Mansion publishes next to it (the Babel plugin writes worklet
345
+ modules while bundling, and unpatched Metro fails with "Failed to get the
346
+ SHA-1"). The example app in this repo has all three (`example/babel.config.js`,
347
+ `example/metro.config.js`, `patches/`).
348
+
349
+ This is the same mechanism as [react-native-transformer-text-input](https://github.com/AppAndFlow/react-native-transformer-text-input):
350
+ the worklets UI runtime is handed to native once, the worklet is called with
351
+ `runSync` inside the edit, so there is no bridge hop and no caret flicker.
352
+
353
+ ### Imperative
354
+
355
+ ```tsx
356
+ const ref = useRef<MorphInputHandle>(null)
357
+
358
+ <MorphInput ref={ref} mode="number" />
359
+
360
+ ref.current?.focus()
361
+ ref.current?.blur()
362
+ ref.current?.setValue(1234.56) // shows "1,234.56", morphing from whatever was there
363
+ ref.current?.setText('98,765') // same, from a string in the field's format
364
+ ref.current?.clear()
365
+ ref.current?.getText() // "1,234.56"
366
+ ref.current?.getValue() // 1234.56, NaN when empty
367
+ ref.current?.isFocused()
368
+ ref.current?.setSelection(4, 7) // code point offsets; equal values place the caret
369
+ ```
370
+
371
+ `setValue` / `setText` / `clear` use **place matching**: `1,204` → `1,318`
372
+ keeps the thousands and the comma, swaps the hundreds, tens and units in
373
+ place. Typing uses **caret matching**: the characters on either side of the
374
+ caret keep their identity, so inserting a `9` into `12|34` slides `34` over
375
+ rather than renumbering the columns.
376
+
377
+ ## Props
378
+
379
+ | Prop | Type | Default | Description |
380
+ | --- | --- | --- | --- |
381
+ | `value` | `string` | – | Controlled text, applied when it differs from what the field shows and JS has seen every native edit. |
382
+ | `defaultValue` | `string` | `''` | Initial text (uncontrolled). |
383
+ | `mode` | `'text' \| 'number' \| 'mask'` | `'text'` | `number` formats as you type; `mask` applies a fixed pattern. |
384
+ | `fractionDigits` | `number` | `2` | `number`: most decimals accepted; `0` disables the decimal key. |
385
+ | `maxIntegerDigits` | `number` | `15` | `number`: most integer digits accepted; further digits are rejected. |
386
+ | `groupingSeparator` | `string` | `','` | `number`: every three integer digits; `''` disables grouping. |
387
+ | `decimalSeparator` | `string` | `'.'` | `number`: between integer and fraction digits. |
388
+ | `mask` | `string` | `''` | `mask`: the pattern. `[…]` an editable block, `{…}` a literal the engine inserts. Slots: `0` required digit, `9` optional digit, `A`/`a` letter, `_` any, `…` repeat. |
389
+ | `maskNotations` | `{ character, characterSet, isOptional }[]` | `[]` | `mask`: caller-defined slots beyond the built-ins. |
390
+ | `maskAutocomplete` | `boolean` | `true` | `mask`: insert literals as soon as the slot before them is filled. Only while the caret is at the end. |
391
+ | `maskAutoSkip` | `boolean` | `false` | `mask`: let a backspace step back over inserted literals. |
392
+ | `variant` | `'none' \| 'outlined' \| 'filled'` | `'none'` | Draws a frame for itself. The outlined notch is a real hole in the stroke. |
393
+ | `label` | `string` | `''` | Floating label. Also becomes the field's accessible name when nothing else gives it one. |
394
+ | `labelBehavior` | `'float' \| 'always'` | `'float'` | `always` keeps it floated even when empty and blurred. |
395
+ | `labelColor` / `labelFocusedColor` | `ColorValue` | placeholder / `focusedStrokeColor` | Label colors. |
396
+ | `labelFontSize` | `number` | `fontSize * 0.75` | Floated label size. |
397
+ | `strokeColor` / `focusedStrokeColor` | `ColorValue` | separator / `strokeColor` | Outline color. Named `stroke*`, not `outline*`: React Native 0.76 added CSS `outlineColor` to every view, and a Hybrid View's props derive from `ViewProps`, so both parsers would run. |
398
+ | `strokeWidth` | `number` | `1` | Doubles while focused. |
399
+ | `cornerRadius` | `number` | `8` | Clamped to half the shorter side. `filled` squares its bottom so the indicator meets the fill. |
400
+ | `fillColor` | `ColorValue` | secondary fill | `filled` background. |
401
+ | `prefix` / `suffix` | `string` | `''` | Static text drawn around the field's text (`$`, ` USD`). Not part of the editable text. |
402
+ | `prefixFontSize` / `suffixFontSize` | `number` | `fontSize` | Their own sizes. |
403
+ | `affixAlign` | `'baseline' \| 'center' \| 'top' \| 'bottom'` | `'baseline'` | How they line up with the text: `top` pins glyph tops, `bottom` the bottom of the ink (a currency code sits on the digits' baseline). |
404
+ | `prefixAlign` / `suffixAlign` | same | `affixAlign` | Per-affix override. |
405
+ | `placeholder` | `string` | `''` | Shown while empty; the first character morphs it away. `'0'` reads well for amounts. |
406
+ | `placeholderTextColor` | `ColorValue` | platform | Placeholder color. |
407
+ | `morph` | `boolean` | `false` | Run the glyph engine, so text morphs as it changes. `MorphInput` is this plus content sizing. |
408
+ | `autoWidth` | `boolean \| 'auto'` | `false` | `false` takes no width, so flexbox stretches it like a `TextInput`; `'auto'` infers it from `style` (what `MorphInput` uses). |
409
+ | `duration` | `number` | `400` | ms of the morph; `0` snaps. |
410
+ | `easing` | `'expo' \| 'easeOut' \| 'easeInOut' \| 'linear' \| 'spring'` | `'expo'` | Timing curve. `expo` is Torph's `cubic-bezier(0.19, 1, 0.22, 1)`. |
411
+ | `bounce` | `number` | `0.15` | Overshoot of the `spring` easing (0–1). |
412
+ | `effect` | `'auto' \| 'slide' \| 'fade'` | `'auto'` | `auto`: digits and separators slide through the line box (digits from above, separators from below), other characters fade and scale. |
413
+ | `fontSize` | `number` | `32` | Points. |
414
+ | `fontWeight` | `TextStyle['fontWeight']` | `'normal'` | |
415
+ | `fontFamily` | `string` | system | Resolved like `Text`. |
416
+ | `color` | `ColorValue` | label color | Text color. |
417
+ | `textAlign` | `'auto' \| 'left' \| 'center' \| 'right'` | `'auto'` | Alignment inside a wider frame. `'auto'` is the start edge of the layout direction, as `TextInput`; `'left'` and `'right'` are absolute. |
418
+ | `lineHeight` | `number` | the font's own | The CSS meaning: the total height a line occupies. Honoured in both directions, including tighter than the font. |
419
+ | `multiline` | `boolean` | `false` | Wraps. Always drawn by the system view and always `'text'` mode; `morph`, `'number'`, `'mask'` and the affixes are ignored with it, and the return key inserts a line break unless `submitBehavior` says otherwise. |
420
+ | `numberOfLines` / `rows` | `number` | `0` | `multiline`: lines tall before it scrolls; `0` grows with the content. |
421
+ | `textAlignVertical` | `'auto' \| 'top' \| 'center' \| 'bottom'` | `'auto'` | `multiline`: where the text sits in a taller box. |
422
+ | `scrollEnabled` | `boolean` | `true` | `multiline`: scroll once the text outgrows the field; `false` lets a growing field drive its own height. |
423
+ | `cursorColor` | `ColorValue` | platform tint | Caret color. |
424
+ | `selectionColor` | `ColorValue` | platform tint | Selection highlight. |
425
+ | `caretHidden` | `boolean` | `false` | |
426
+ | `adjustsFontSizeToFit` | `boolean` | `false` | Scale the text down when it is wider than the view's fixed `width`. |
427
+ | `minimumFontScale` | `number` | `0.5` | Lower bound for `adjustsFontSizeToFit`. |
428
+ | `allowFontScaling` | `boolean` | `false` | Follow the system text size like `Text`. |
429
+ | `maxFontSizeMultiplier` | `number` | `0` | Cap for `allowFontScaling`; `0` = none. |
430
+ | `keyboardType` | see below | mode-dependent | `number` mode defaults to `decimal-pad` (`number-pad` when `fractionDigits` is `0`). |
431
+ | `inputMode` | `'none' \| 'text' \| 'decimal' \| 'numeric' \| 'tel' \| 'search' \| 'email' \| 'url'` | – | React Native's HTML-style alias for `keyboardType`, mapped with its table; `keyboardType` wins. `'none'` focuses without a keyboard. `'search'` falls back to the default keyboard. |
432
+ | `returnKeyType` | `'default' \| 'done' \| 'go' \| 'next' \| 'search' \| 'send'` | `'default'` | |
433
+ | `enterKeyHint` | `'enter' \| 'done' \| 'go' \| 'next' \| 'previous' \| 'search' \| 'send'` | – | HTML-style alias for `returnKeyType`; `returnKeyType` wins. `'previous'` falls back to the default key. |
434
+ | `submitBehavior` | `'blurAndSubmit' \| 'submit' \| 'newline'` | `'blurAndSubmit'`, `'newline'` when `multiline` | What the return key does: fire `onSubmitEditing` and dismiss the keyboard, fire it and keep focus (a form moving to its next field), or insert a line break (`multiline` only). Defaults as `TextInput`'s. |
435
+ | `blurOnSubmit` | `boolean` | – | Deprecated alias, resolved like `TextInput`'s: `false` means `'submit'` on one line, `true` means `'blurAndSubmit'` on many. `submitBehavior` wins. |
436
+ | `enablesReturnKeyAutomatically` | `boolean` | `false` | Disables the return key until the field has text. |
437
+ | `autoCapitalize` | `'none' \| 'sentences' \| 'words' \| 'characters'` | `'sentences'` | `text` mode. |
438
+ | `autoCorrect` | `boolean` | `true` | `text` mode. |
439
+ | `spellCheck` | `boolean` | `autoCorrect` | `text` mode. |
440
+ | `secureTextEntry` | `boolean` | `false` | Draws bullets and turns off autocorrect; the field keeps the real text for autofill. |
441
+ | `keyboardAppearance` | `'default' \| 'light' \| 'dark'` | `'default'` | iOS: a light or dark keyboard. |
442
+ | `textContentType` / `autoComplete` | `string` | `''` | Autofill: iOS content types and Android hints by their React Native names (`'username'`, `'password'`, `'oneTimeCode'`, `'telephoneNumber'`, …). `textContentType` wins. |
443
+ | `showSoftInputOnFocus` | `boolean` | `true` | `false` focuses, with the caret, but shows no keyboard. |
444
+ | `selectTextOnFocus` | `boolean` | `false` | Select everything when the field gains focus. |
445
+ | `clearTextOnFocus` | `boolean` | `false` | Empty the field when it gains focus. |
446
+ | `contextMenuHidden` | `boolean` | `false` | Hides the Cut / Copy / Paste menu. |
447
+ | `editable` | `boolean` | `true` | |
448
+ | `readOnly` | `boolean` | `false` | Alias of `editable={false}`, as on `TextInput`. |
449
+ | `autoFocus` | `boolean` | `false` | |
450
+ | `selection` | `{ start, end? }` | – | The caret or selection to apply, in code points into the (formatted) text. |
451
+ | `maxLength` | `number` | unlimited | `text` mode. |
452
+ | `transform` | `NitroInputTransform` | – | A `'worklet'` that rewrites text and selection after every edit, synchronously on the UI thread (needs `react-native-worklets`). |
453
+ | `onChangeText` | `(text) => void` | – | After every edit, the formatted text. A `'worklet'` runs on the UI thread. |
454
+ | `onChange` | `(event) => void` | – | Fired alongside `onChangeText` with the same text; `nativeEvent.eventCount` is the native edit counter, as on `TextInput`. |
455
+ | `onChangeValue` | `(value) => void` | – | `number` mode: the numeric value, `NaN` while empty. A `'worklet'` runs on the UI thread. |
456
+ | `onChangeMask` | `(formatted, extracted, tail, complete) => void` | – | `mask` mode: the formatted text, the characters the user contributed, what is still missing, and whether every mandatory slot is filled. |
457
+ | `signPlacement` | `'beforeAffix' \| 'afterAffix'` | `'beforeAffix'` | Where a negative amount's sign sits relative to `prefix`: `-$1,234.56` or `$-1,234.56`. Morph only — a plain field's affixes are accessory views outside the text. |
458
+ | `onFocus` / `onBlur` | `(event) => void` | – | Carries `text`, `eventCount` and `target`. |
459
+ | `onSubmitEditing` | `(event) => void` | – | Return key pressed; what happens next is `submitBehavior`. |
460
+ | `onEndEditing` | `(event) => void` | – | Editing finished. |
461
+ | `onSelectionChange` | `(event) => void` | – | The caret or selection moved, in code points. |
462
+ | `onKeyPress` | `(event) => void` | – | Before the text changes: the character, `'Backspace'` or `'Enter'`. |
463
+ | `onNativeRef` | `(ref) => void` | – | Receives the Nitro object on mount. |
464
+ | `id` / `aria-label` | `string` | – | React Native's HTML-style aliases for `nativeID` / `accessibilityLabel`, resolved here because a Nitro view is handed the raw props; each wins over the older spelling. |
465
+ | `style`, `testID`, … | `ViewProps` | – | Regular view props. `testID` and the accessibility label are forwarded to the system field, the element VoiceOver, TalkBack and e2e tools interact with. The field takes its width from its parent like a `TextInput`; see `autoWidth`. |
466
+
467
+ `keyboardType`: `'default' | 'number-pad' | 'decimal-pad' | 'numeric' | 'email-address' | 'phone-pad' | 'url' | 'ascii-capable' | 'numbers-and-punctuation'`.
468
+
469
+ Every `event` above is a superset of the one `TextInput` passes: `nativeEvent`
470
+ is there with the same fields under the same names, so a handler written for a
471
+ `TextInput` works unchanged, and those fields are repeated at the top level so
472
+ new code can destructure instead of reaching through it.
473
+
474
+ ```tsx
475
+ onSubmitEditing={e => search(e.nativeEvent.text)} // as on a TextInput
476
+ onSubmitEditing={({ text }) => search(text)} // or just this
477
+ ```
478
+
479
+ ## How the morph decides what moves
480
+
481
+ Each update pairs the old characters with the new ones (Torph's rules,
482
+ implemented in `cpp/MorphEngine.cpp`):
483
+
484
+ - **Typing** (a caret is known): everything before the caret pairs by
485
+ position from the left, everything after it from the right, so the edit is
486
+ exactly the characters that entered or left. Grouping separators are kept out
487
+ of that walk, because a comma reflows with the magnitude rather than with the
488
+ keystroke; they pair from the units end instead, so the thousands comma stays
489
+ the thousands comma and glides.
490
+ - **A value set from code** (no caret): digits pair by their column from the
491
+ decimal point, so `1,204 → 1,318` swaps the three low columns in place. When
492
+ the integer part gained or lost columns the digits pair by subsequence from
493
+ the units end and the separators, which would have to cross them, leave.
494
+ Plain text pairs by longest common subsequence (`Continue → Confirm` keeps
495
+ `Con`).
496
+
497
+ A character that persists eases to its new x. A new digit drops in from above
498
+ (a separator rises from below) through the clipped line box, fading in over the
499
+ first quarter of the morph; a leaving digit drops out the same way, fading over
500
+ the first 45 %. Text characters fade and scale (0.95×) instead. Characters that
501
+ enter or leave ride along with their nearest persisting neighbour, so a word
502
+ that grows or shrinks stays one shape. All of it is Reduce Motion aware.
503
+
504
+ ## Accessibility and threading
505
+
506
+ - The system field remains the accessibility element, with the formatted text
507
+ (`$1,234.50 USD` reads as such); VoiceOver / TalkBack, autofill, the paste
508
+ menu and selection all work as in a plain input.
509
+ - Reduce Motion (iOS) and "Remove animations" (Android) snap.
510
+ - The view implements Nitro's `RecyclableView`.
511
+ - Every keystroke is handled on the main thread: the formatter runs, the field
512
+ is updated, the morph starts. `onChangeText` reaches JS afterwards; nothing
513
+ the user sees waits for it. A `value` prop carrying a stale
514
+ `mostRecentEventCount` (the user typed since) is ignored, like React
515
+ Native's own `TextInput`.
516
+
517
+ ## Credits
518
+
519
+ The morph is based on [Torph](https://torph.lochie.me) by
520
+ [Lochie Axon](https://github.com/lochie). Thanks for building it.
521
+
522
+ ## License
523
+
524
+ MIT
@@ -0,0 +1,52 @@
1
+ cmake_minimum_required(VERSION 3.22.1)
2
+ project(NitroInput)
3
+
4
+ set (PACKAGE_NAME NitroInput)
5
+ set (CMAKE_VERBOSE_MAKEFILE ON)
6
+ set (CMAKE_CXX_STANDARD 20)
7
+
8
+ # Define C++ library and add all sources
9
+ add_library(${PACKAGE_NAME} SHARED
10
+ src/main/cpp/cpp-adapter.cpp
11
+ src/main/cpp/JMorphEngine.cpp
12
+ src/main/cpp/JAmountFormatter.cpp
13
+ src/main/cpp/JMaskEngine.cpp
14
+ src/main/cpp/JOutlineGeometry.cpp
15
+ src/main/cpp/JNitroInputWorklets.cpp
16
+ ../cpp/MorphEngine.cpp
17
+ ../cpp/AmountFormatter.cpp
18
+ ../cpp/MaskEngine.cpp
19
+ ../cpp/OutlineGeometry.cpp
20
+ ../cpp/worklets/NitroInputWorkletsBridge.cpp
21
+ ../cpp/worklets/HybridNitroInputWorklets.cpp
22
+ )
23
+
24
+ # Add Nitrogen specs :)
25
+ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroInput+autolinking.cmake)
26
+
27
+ # Set up local includes
28
+ include_directories(
29
+ "src/main/cpp"
30
+ "../cpp"
31
+ "../cpp/worklets"
32
+ )
33
+
34
+ # Worklets are optional: with react-native-worklets installed the views can
35
+ # run `transform` / `onChangeText` worklets synchronously on the UI thread.
36
+ find_package(react-native-worklets CONFIG QUIET)
37
+ if(react-native-worklets_FOUND)
38
+ target_compile_definitions(${PACKAGE_NAME} PRIVATE MORPH_INPUT_WORKLETS=1)
39
+ target_link_libraries(${PACKAGE_NAME} react-native-worklets::worklets)
40
+ message(STATUS "NitroInput: react-native-worklets found, worklet support enabled")
41
+ else()
42
+ message(STATUS "NitroInput: react-native-worklets not found, worklet support disabled")
43
+ endif()
44
+
45
+ find_library(LOG_LIB log)
46
+
47
+ # Link all libraries together
48
+ target_link_libraries(
49
+ ${PACKAGE_NAME}
50
+ ${LOG_LIB}
51
+ android # <-- Android core
52
+ )