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/src/index.ts ADDED
@@ -0,0 +1,55 @@
1
+ export {
2
+ NitroInput,
3
+ NativeNitroInputView,
4
+ type NitroInputProps,
5
+ type NitroInputHandle,
6
+ type NitroInputRef,
7
+ type NitroInputTextEvent,
8
+ type NitroInputFocusEvent,
9
+ type NitroInputSelectionEvent,
10
+ type NitroInputKeyPressEvent,
11
+ type InputMode,
12
+ type EnterKeyHint,
13
+ } from './NitroInput'
14
+ export {
15
+ MorphInput,
16
+ type MorphInputProps,
17
+ type MorphInputHandle,
18
+ type MorphInputRef,
19
+ } from './MorphInput'
20
+ export {
21
+ isWorklet,
22
+ type NitroInputSelection,
23
+ type NitroInputTransform,
24
+ type WorkletTextEvent,
25
+ type WorkletFocusEvent,
26
+ type WorkletSelectionEvent,
27
+ type WorkletKeyPressEvent,
28
+ } from './worklets'
29
+ export {
30
+ useNitroInputState,
31
+ type NitroInputState,
32
+ type SharedValueLike,
33
+ } from './useNitroInputState'
34
+
35
+ export type {
36
+ NitroInputLabelBehavior,
37
+ NitroInputMode,
38
+ NitroInputNotation,
39
+ NitroInputVariant,
40
+ NitroInputEasing,
41
+ NitroInputEffect,
42
+ NitroInputTextAlign,
43
+ NitroInputTextAlignVertical,
44
+ NitroInputAffixAlign,
45
+ NitroInputSignPlacement,
46
+ NitroInputKeyboardType,
47
+ NitroInputReturnKeyType,
48
+ NitroInputAutoCapitalize,
49
+ NitroInputSubmitBehavior,
50
+ NitroInputKeyboardAppearance,
51
+ NitroInputMethods,
52
+ NitroInputProps as NativeNitroInputProps,
53
+ NitroInputView,
54
+ } from './specs/NitroInput.nitro'
55
+ export type { NitroInputWorklets } from './specs/NitroInputWorklets.nitro'
@@ -0,0 +1,436 @@
1
+ import type {
2
+ HybridView,
3
+ HybridViewMethods,
4
+ HybridViewProps,
5
+ } from 'react-native-nitro-modules'
6
+
7
+ /**
8
+ * What the field holds. `'number'` formats natively as you type (grouping,
9
+ * decimal, currency affixes); `'mask'` applies a fixed pattern (`mask`);
10
+ * `'text'` is a plain single-line field.
11
+ */
12
+ export type NitroInputMode = 'text' | 'number' | 'mask'
13
+
14
+ /**
15
+ * A caller-defined slot character for `mask`, beyond the built-in
16
+ * `0 9 A a _ - …`. `characterSet` lists every character the slot accepts.
17
+ */
18
+ export interface NitroInputNotation {
19
+ /** The character that stands for this slot in the mask, e.g. `'H'`. */
20
+ character: string
21
+ /** Every accepted character, e.g. `'0123456789abcdef'`. */
22
+ characterSet: string
23
+ /** An optional slot may be skipped; a mandatory one must be filled. */
24
+ isOptional: boolean
25
+ }
26
+
27
+ /**
28
+ * Timing curve of the morph. `'expo'` is Torph's default
29
+ * (`cubic-bezier(0.19, 1, 0.22, 1)`): a fast take-off that settles gently.
30
+ */
31
+ export type NitroInputEasing =
32
+ | 'expo'
33
+ | 'easeOut'
34
+ | 'easeInOut'
35
+ | 'linear'
36
+ | 'spring'
37
+
38
+ /**
39
+ * How characters enter and leave. `'auto'`: digits and separators slide
40
+ * vertically through the line box (digits from above, separators from
41
+ * below), other characters fade and scale. `'slide'` / `'fade'` force one style.
42
+ */
43
+ export type NitroInputEffect = 'auto' | 'slide' | 'fade'
44
+
45
+ /**
46
+ * The field's frame. `'none'` draws nothing, leaving the border to the host
47
+ * view's own `style` as before. `'outlined'` strokes a rounded rectangle whose
48
+ * top edge is notched around the floating label - a real hole in the path, so
49
+ * whatever is behind the field shows through it. `'filled'` tints the box and
50
+ * underlines it instead, with the label floating inside.
51
+ */
52
+ export type NitroInputVariant = 'none' | 'outlined' | 'filled'
53
+
54
+ /**
55
+ * Where the label sits. `'float'` is the Material behaviour: inline while the
56
+ * field is empty and unfocused, floating once it is focused or has text.
57
+ * `'always'` keeps it floated.
58
+ */
59
+ export type NitroInputLabelBehavior = 'float' | 'always'
60
+
61
+ /**
62
+ * Horizontal alignment of the text inside the view's frame. `'auto'` is the
63
+ * start edge of the layout direction - left in a left-to-right app, right in a
64
+ * right-to-left one - which is what `TextInput` does with no `textAlign`.
65
+ * `'left'` and `'right'` are absolute, whatever the direction.
66
+ */
67
+ export type NitroInputTextAlign = 'auto' | 'left' | 'center' | 'right'
68
+
69
+ /** Where the text sits in a field taller than one line. */
70
+ export type NitroInputTextAlignVertical = 'auto' | 'top' | 'center' | 'bottom'
71
+
72
+ /**
73
+ * Where a negative amount's sign sits relative to a `prefix`.
74
+ * `'beforeAffix'` (the default) reads `-$1,234.56`, which is how a locale that
75
+ * leads with its symbol writes it. `'afterAffix'` reads `$-1,234.56`, which
76
+ * suits a symbol styled as an ornament rather than read as part of the number -
77
+ * small, raised, in another colour. Only the morph honours it: a plain field's
78
+ * affixes are accessory views that sit outside the text, so it is always
79
+ * `'afterAffix'`.
80
+ */
81
+ export type NitroInputSignPlacement = 'beforeAffix' | 'afterAffix'
82
+
83
+ /** How a prefix/suffix drawn at a different size lines up with the text. */
84
+ export type NitroInputAffixAlign = 'baseline' | 'center' | 'top' | 'bottom'
85
+
86
+ export type NitroInputKeyboardType =
87
+ | 'default'
88
+ | 'number-pad'
89
+ | 'decimal-pad'
90
+ | 'numeric'
91
+ | 'email-address'
92
+ | 'phone-pad'
93
+ | 'url'
94
+ | 'ascii-capable'
95
+ | 'numbers-and-punctuation'
96
+
97
+ export type NitroInputReturnKeyType =
98
+ | 'default'
99
+ | 'done'
100
+ | 'go'
101
+ | 'next'
102
+ | 'search'
103
+ | 'send'
104
+
105
+ export type NitroInputAutoCapitalize =
106
+ | 'none'
107
+ | 'sentences'
108
+ | 'words'
109
+ | 'characters'
110
+
111
+ /**
112
+ * What the return key does. `'blurAndSubmit'` fires `onSubmitEditing` and
113
+ * dismisses the keyboard; `'submit'` fires it and keeps focus, which is what
114
+ * a form that moves to the next field needs; `'newline'` inserts a line break
115
+ * (multiline fields only, and their default, as with `TextInput`).
116
+ */
117
+ export type NitroInputSubmitBehavior = 'submit' | 'blurAndSubmit' | 'newline'
118
+
119
+ /** Light or dark keyboard (iOS). `'default'` follows the system appearance. */
120
+ export type NitroInputKeyboardAppearance = 'default' | 'light' | 'dark'
121
+
122
+ export interface NitroInputProps extends HybridViewProps {
123
+ /**
124
+ * The text the field should show. Applied natively (formatted in `'number'`
125
+ * mode) when it changes and `mostRecentEventCount` shows JS has seen every
126
+ * native edit, so a parent echoing `onChangeText` back never fights the
127
+ * user. The native side owns the text in between: typing never waits for JS.
128
+ */
129
+ text: string
130
+ /**
131
+ * The `eventCount` from the latest `onChangeText` JS has processed. A `text`
132
+ * update carrying a stale count is ignored (the user typed since), like
133
+ * React Native's own `TextInput`.
134
+ */
135
+ mostRecentEventCount: number
136
+ /** `'text'`, `'number'` or `'mask'`. Default: `'text'`. */
137
+ mode: NitroInputMode
138
+ /**
139
+ * Draw the text with the system field itself and skip the morph overlay
140
+ * entirely: no glyph engine, no per-glyph layers, no custom caret. This is
141
+ * what `NitroInput` renders — an ordinary native input that keeps the rest of
142
+ * the component (native formatting, the focus path, the text-input registry
143
+ * and keyboard-controller support) but costs no more to mount than a plain
144
+ * `UITextField` / `EditText`. Default: `false`.
145
+ */
146
+ plain: boolean
147
+ /** `'number'`: most digits allowed after the decimal separator (`0` disables the decimal). Default: `2`. */
148
+ fractionDigits: number
149
+ /** `'number'`: most integer digits accepted. Default: `15`. */
150
+ maxIntegerDigits: number
151
+ /**
152
+ * `'mask'`: the pattern, e.g. `'+1 ([000]) [000]-[0000]'`.
153
+ *
154
+ * `[0]` mandatory digit, `[9]` optional digit, `[A]` mandatory letter,
155
+ * `[a]` optional letter, `[_]` mandatory alphanumeric, `[-]` optional
156
+ * alphanumeric, `[…]` an unbounded run of the preceding type. `{…}` is a
157
+ * fixed block whose characters count towards the extracted value; a literal
158
+ * outside brackets is shown but not extracted. `\\` escapes.
159
+ *
160
+ * An invalid pattern leaves the field unmasked rather than breaking it.
161
+ * Default: `''`.
162
+ */
163
+ mask: string
164
+ /** `'mask'`: extra slot characters beyond the built-in ones. Default: none. */
165
+ maskNotations: NitroInputNotation[]
166
+ /**
167
+ * `'mask'`: fill in the pattern's constant characters as soon as the caret
168
+ * reaches them, so typing `212` into `'+1 ([000]) [000]'` leaves
169
+ * `'+1 (212) '`. Default: `true`.
170
+ */
171
+ maskAutocomplete: boolean
172
+ /**
173
+ * `'mask'`: backspacing at the end of a run walks back over the constants
174
+ * `maskAutocomplete` added, instead of stopping in front of them.
175
+ * Default: `false`.
176
+ */
177
+ maskAutoSkip: boolean
178
+ /** `'number'`: inserted between every three integer digits; empty disables grouping. Default: `','`. */
179
+ groupingSeparator: string
180
+ /** `'number'`: between the integer and fraction digits. Default: `'.'`. */
181
+ decimalSeparator: string
182
+ /** The field's frame. Default: `'none'` - the host view's `style` draws the border. */
183
+ variant: NitroInputVariant
184
+ /** Floating label. Empty draws none (and leaves the outline unbroken). Default: `''`. */
185
+ label: string
186
+ /** Whether the label floats on focus or stays floated. Default: `'float'`. */
187
+ labelBehavior: NitroInputLabelBehavior
188
+ /** Label colour at rest, as a processed ARGB integer; `NaN` follows `placeholderColor`. */
189
+ labelColor: number
190
+ /** Label colour while focused; `NaN` follows `focusedStrokeColor`. */
191
+ labelFocusedColor: number
192
+ /** Label size when floated, in points; `0` derives it from `fontSize`. */
193
+ labelFontSize: number
194
+ /**
195
+ * Frame colour, as a processed ARGB integer; `NaN` = a platform hairline grey.
196
+ *
197
+ * Not `outlineColor`: React Native owns that name as a CSS-outline style prop
198
+ * on every view, and would draw its own square outline over this one.
199
+ */
200
+ strokeColor: number
201
+ /** Outline colour while focused; `NaN` follows `strokeColor`. */
202
+ focusedStrokeColor: number
203
+ /** Outline stroke width in points. Widened while focused, as Material does. Default: `1`. */
204
+ strokeWidth: number
205
+ /** Corner radius of the frame, clamped to half the shorter side. Default: `8`. */
206
+ cornerRadius: number
207
+ /** `'filled'`: the box tint, as a processed ARGB integer; `NaN` = a platform default. */
208
+ fillColor: number
209
+ /** Static text drawn before the field's text (e.g. `'$'`). Default: `''`. */
210
+ prefix: string
211
+ /** Static text drawn after the field's text (e.g. `' USD'`). Default: `''`. */
212
+ suffix: string
213
+ /** Font size of `prefix` in points. Defaults to `fontSize`. */
214
+ prefixFontSize: number
215
+ /** Font size of `suffix` in points. Defaults to `fontSize`. */
216
+ suffixFontSize: number
217
+ /** Where a negative amount's sign sits relative to `prefix`. */
218
+ signPlacement: NitroInputSignPlacement
219
+ /** Vertical alignment of `prefix` relative to the text (the wrapper folds its `affixAlign` into this). */
220
+ prefixAlign: NitroInputAffixAlign
221
+ /** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
222
+ suffixAlign: NitroInputAffixAlign
223
+ /** Shown (and morphed away) while the field is empty. Default: `''`. */
224
+ placeholder: string
225
+ /** Color of the placeholder as a processed ARGB integer; `NaN` = platform default. */
226
+ placeholderColor: number
227
+ /** Duration in ms of the morph played on every change. `0` snaps. Default: `400`. */
228
+ duration: number
229
+ /** Timing curve of the morph. Default: `'expo'`. */
230
+ easing: NitroInputEasing
231
+ /** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15`. */
232
+ bounce: number
233
+ /** How characters enter and leave. Default: `'auto'`. */
234
+ effect: NitroInputEffect
235
+ /** Font size of the text in points. Default: `32`. */
236
+ fontSize: number
237
+ /**
238
+ * Height of the line box in points — the CSS meaning: the total height a
239
+ * line occupies, not extra leading. `0` (the default) uses the font's own.
240
+ *
241
+ * Both platforms add the difference *above* the line, so the glyphs have to
242
+ * be nudged back down by half of it or they ride high in the box. We apply
243
+ * that whatever the value, including a line height *tighter* than the font —
244
+ * which is the case React Native skips
245
+ * (`RCTApplyBaselineOffsetForRange` returns early when
246
+ * `lineHeight < font.lineHeight`), and the reason a compressed `lineHeight`
247
+ * renders off-centre on a `TextInput`.
248
+ */
249
+ lineHeight: number
250
+ /** Numeric font weight, `100`–`900`. Default: `400`. */
251
+ fontWeight: number
252
+ /** Font family name; empty = system font. */
253
+ fontFamily: string
254
+ /** Text color as a processed ARGB integer; `NaN` = platform label color. */
255
+ color: number
256
+ /** Where the text sits when the view is wider than it. Default: `'auto'`, the start edge. */
257
+ textAlign: NitroInputTextAlign
258
+ /**
259
+ * Lay the field out right-to-left: `'auto'` alignment resolves to the right
260
+ * edge, the prefix moves to the right and the suffix to the left, and a
261
+ * frame's label floats from the right. Fabric does not hand a Hybrid View
262
+ * its layout direction, so the JS side resolves it - from the field's
263
+ * `style.direction`, else `I18nManager.isRTL` - the way React Native
264
+ * resolves its own views. Default: `false`.
265
+ */
266
+ rightToLeft: boolean
267
+ /** Caret color as a processed ARGB integer; `NaN` = platform tint. */
268
+ caretColor: number
269
+ /** Selection highlight color as a processed ARGB integer; `NaN` = platform tint. */
270
+ selectionColor: number
271
+ /** Hides the caret. Default: `false`. */
272
+ caretHidden: boolean
273
+ /** Scale the text down when it is wider than the view (fixed `width` in style). Default: `false`. */
274
+ adjustsFontSizeToFit: boolean
275
+ /** Smallest scale `adjustsFontSizeToFit` may apply, `0`–`1`. Default: `0.5`. */
276
+ minimumFontScale: number
277
+ /** Scale the fonts with the system text size, like `Text`. Default: `false`. */
278
+ allowFontScaling: boolean
279
+ /** Upper bound for `allowFontScaling`; `0` = no cap. Default: `0`. */
280
+ maxFontSizeMultiplier: number
281
+ /** Keyboard to show. Default: `'default'` (`'decimal-pad'` / `'number-pad'` in `'number'` mode). */
282
+ keyboardType: NitroInputKeyboardType
283
+ /** Label of the return key. Default: `'default'`. */
284
+ returnKeyType: NitroInputReturnKeyType
285
+ /** Auto-capitalisation (`'text'` mode). Default: `'sentences'`. */
286
+ autoCapitalize: NitroInputAutoCapitalize
287
+ /** Auto-correction (`'text'` mode). Default: `true`. */
288
+ autoCorrect: boolean
289
+ /** Whether the user can edit the field. Default: `true`. */
290
+ editable: boolean
291
+ /**
292
+ * Let the text wrap onto more than one line.
293
+ *
294
+ * A multiline field is always drawn by the system view — the glyph engine
295
+ * lays one run out on one baseline, so it cannot morph wrapped text — and it
296
+ * is always `'text'` mode, since an amount and a mask are single-line ideas.
297
+ * Setting `morph`, `'number'` or `'mask'` alongside it is ignored, with a
298
+ * warning. Default: `false`.
299
+ */
300
+ multiline: boolean
301
+ /**
302
+ * `multiline`: how many lines tall the field is before it scrolls. `0` (the
303
+ * default) lets it grow with its content; the height it wants is reported
304
+ * through `onSizeChange`.
305
+ */
306
+ numberOfLines: number
307
+ /** `multiline`: where the text sits in the box. Default: `'auto'` (top). */
308
+ textAlignVertical: NitroInputTextAlignVertical
309
+ /**
310
+ * `multiline`: whether the field scrolls once the text is taller than it.
311
+ * Turning it off lets a growing field drive its own height. Default: `true`.
312
+ */
313
+ scrollEnabled: boolean
314
+ /** Focus the field when it mounts. Default: `false`. */
315
+ autoFocus: boolean
316
+ /**
317
+ * The `testID` / accessibility label to put on the *hidden system field*.
318
+ * React Native applies those to the wrapping host view, but the system field
319
+ * is the element VoiceOver, TalkBack and e2e tools actually interact with,
320
+ * so the wrapper forwards them explicitly. Empty leaves them unset.
321
+ */
322
+ fieldTestID: string
323
+ /** Accessibility label for the hidden system field. Empty leaves it unset. */
324
+ fieldAccessibilityLabel: string
325
+ /** What the return key does. Default: `'blurAndSubmit'`, `'newline'` when `multiline`. */
326
+ submitBehavior: NitroInputSubmitBehavior
327
+ /** Masks the text with bullets and opts the field out of autocorrect/autofill. Default: `false`. */
328
+ secureTextEntry: boolean
329
+ /** Light or dark keyboard (iOS). Default: `'default'`. */
330
+ keyboardAppearance: NitroInputKeyboardAppearance
331
+ /**
332
+ * iOS `UITextContentType` / Android autofill hint, as its React Native name
333
+ * (`'username'`, `'password'`, `'oneTimeCode'`, `'telephoneNumber'`, …).
334
+ * Empty disables autofill. Default: `''`.
335
+ */
336
+ textContentType: string
337
+ /** Disables the return key until the field has text. Default: `false`. */
338
+ enablesReturnKeyAutomatically: boolean
339
+ /** Show the soft keyboard when the field is focused. `false` keeps focus and caret without it. Default: `true`. */
340
+ showSoftInputOnFocus: boolean
341
+ /** Select all the text when the field gains focus. Default: `false`. */
342
+ selectTextOnFocus: boolean
343
+ /** Empty the field when it gains focus. Default: `false`. */
344
+ clearTextOnFocus: boolean
345
+ /** Hides the Cut/Copy/Paste menu. Default: `false`. */
346
+ contextMenuHidden: boolean
347
+ /** Spell checking (`'text'` mode). Defaults to `autoCorrect`. */
348
+ spellCheck: boolean
349
+ /** Caret/selection start to apply, in code points; `-1` leaves the selection alone. Default: `-1`. */
350
+ selectionStart: number
351
+ /** Caret/selection end to apply, in code points; `-1` leaves the selection alone. Default: `-1`. */
352
+ selectionEnd: number
353
+ /** `'text'` mode: most characters accepted; `0` = unlimited. Default: `0`. */
354
+ maxLength: number
355
+ /**
356
+ * Id of a `transform` worklet registered with `NitroInputWorklets` (`0` = none):
357
+ * run synchronously on the UI thread after every edit, it can rewrite the
358
+ * text and selection before a frame is drawn (masks, custom formats).
359
+ */
360
+ transformWorklet: number
361
+ /** Id of an `onChangeText` worklet run synchronously on the UI thread after every change (`0` = none). */
362
+ onChangeTextWorklet: number
363
+ /** Id of an `onChangeValue` worklet run synchronously on the UI thread after every change (`0` = none). */
364
+ onChangeValueWorklet: number
365
+ /** Id of an `onFocus`/`onBlur` worklet run on the UI thread when focus changes (`0` = none). */
366
+ onFocusChangeWorklet: number
367
+ /** Id of an `onSelectionChange` worklet run on the UI thread when the caret moves (`0` = none). */
368
+ onSelectionChangeWorklet: number
369
+ /** Id of an `onSubmitEditing` worklet run on the UI thread when the return key is pressed (`0` = none). */
370
+ onSubmitEditingWorklet: number
371
+ /** Id of an `onEndEditing` worklet run on the UI thread when editing finishes (`0` = none). */
372
+ onEndEditingWorklet: number
373
+ /** Id of an `onKeyPress` worklet run on the UI thread before the text changes (`0` = none). */
374
+ onKeyPressWorklet: number
375
+ /**
376
+ * Called after every native edit with the field's (formatted) text and a
377
+ * monotonically increasing event count. Feed the count back through
378
+ * `mostRecentEventCount`.
379
+ */
380
+ onChangeText?: (text: string, eventCount: number) => void
381
+ /**
382
+ * `'mask'` mode: called after every edit with the masked text, the characters
383
+ * the user actually contributed, what is still missing, and whether every
384
+ * mandatory slot is filled.
385
+ */
386
+ onChangeMask?: (formatted: string, extracted: string, tailPlaceholder: string, complete: boolean) => void
387
+ /** `'number'` mode: called after every edit with the numeric value, `NaN` when the field is empty. */
388
+ onChangeValue?: (value: number) => void
389
+ /**
390
+ * The field gained (`true`) or lost (`false`) focus. One callback rather
391
+ * than `onFocus` / `onBlur`: those names already exist on React Native's
392
+ * `ViewProps` with an event argument and would clash on the host component.
393
+ */
394
+ onFocusChange?: (focused: boolean) => void
395
+ /** The return key was pressed. */
396
+ onSubmitEditing?: (text: string) => void
397
+ /** Editing finished (focus lost or the keyboard was dismissed), like React Native's `onEndEditing`. */
398
+ onEndEditing?: (text: string) => void
399
+ /** The selection moved: code-point offsets into the (formatted) text. */
400
+ onSelectionChange?: (start: number, end: number) => void
401
+ /** A key was pressed: the character, or `'Backspace'`/`'Enter'`. Fires before the text changes. */
402
+ onKeyPress?: (key: string) => void
403
+ /**
404
+ * Called whenever the settled intrinsic size changes (first layout, text
405
+ * that grew or shrank, font change). `NitroInput` uses this to size itself
406
+ * when the style gives it no width.
407
+ */
408
+ onSizeChange?: (width: number, height: number) => void
409
+ }
410
+
411
+ export interface NitroInputMethods extends HybridViewMethods {
412
+ focus(): void
413
+ blur(): void
414
+ /** Empties the field (morphing the characters away). */
415
+ clear(): void
416
+ /**
417
+ * Replaces the text (formatted in `'number'` mode), caret at the end.
418
+ * (Not `setText`: Nitro generates `getText`/`setText` accessors for the
419
+ * `text` prop, and a method of the same name would collide with them.)
420
+ */
421
+ replaceText(text: string): void
422
+ /** `'number'` mode: shows `value` formatted; `NaN` empties the field. */
423
+ setValue(value: number): void
424
+ /** The field's current (formatted) text. */
425
+ currentText(): string
426
+ /** `'number'` mode: the field's numeric value, `NaN` when empty. */
427
+ getValue(): number
428
+ isFocused(): boolean
429
+ /**
430
+ * Moves the caret / selection, in code points into the (formatted) text.
431
+ * `end` defaults to `start` for a plain caret move; both are clamped.
432
+ */
433
+ setSelection(start: number, end: number): void
434
+ }
435
+
436
+ export type NitroInputView = HybridView<NitroInputProps, NitroInputMethods>
@@ -0,0 +1,13 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules'
2
+
3
+ /**
4
+ * Bridge to `react-native-worklets`, so the native input can run a worklet
5
+ * synchronously on the UI thread while it handles an edit. The native object
6
+ * also exposes a raw JSI method `install(runtimeHolder)` (not declared here:
7
+ * the holder is an opaque JSI object) that takes the result of
8
+ * `getUIRuntimeHolder()` from `react-native-worklets`.
9
+ */
10
+ export interface NitroInputWorklets extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
11
+ /** True when `react-native-worklets` was available when the native code was built. */
12
+ readonly isAvailable: boolean
13
+ }
@@ -0,0 +1,101 @@
1
+ import { useMemo } from 'react'
2
+ import type { NitroInputSelection } from './worklets'
3
+
4
+ // ---------------------------------------------------------------------------
5
+ // The field's state as shared values, so an animation can read it on the UI
6
+ // thread without a re-render.
7
+ //
8
+ // It is built out of the worklet callbacks rather than anything new: mark a
9
+ // handler `'worklet'` and it runs on the UI runtime, which is where a shared
10
+ // value must be written from. The hook just wires that up for you and hands
11
+ // back the handlers to spread onto the field.
12
+ // ---------------------------------------------------------------------------
13
+
14
+ /** The subset of Reanimated's `SharedValue` this needs; typed here so the library does not depend on it. */
15
+ export interface SharedValueLike<T> {
16
+ value: T
17
+ }
18
+
19
+ type MakeShared = <T>(initial: T) => SharedValueLike<T>
20
+
21
+ export interface NitroInputState {
22
+ /** The field's text, updated on the UI thread as it is typed. */
23
+ text: SharedValueLike<string>
24
+ /** `'number'` mode: the numeric value, `NaN` while empty. */
25
+ value: SharedValueLike<number>
26
+ /** Whether the field holds focus. */
27
+ focused: SharedValueLike<boolean>
28
+ /** The caret or selection, in code points. */
29
+ selection: SharedValueLike<NitroInputSelection>
30
+ /**
31
+ * Spread onto the field. Every handler is a worklet, so none of them
32
+ * re-renders; pass your own alongside if you also need JS.
33
+ */
34
+ handlers: {
35
+ onChangeText: (text: string) => void
36
+ onChangeValue: (value: number) => void
37
+ onFocus: () => void
38
+ onBlur: () => void
39
+ onSelectionChange: (event: { start: number; end: number }) => void
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Wires a field's state into shared values you can animate from.
45
+ *
46
+ * Reanimated is not a dependency of this library, so pass its `useSharedValue`
47
+ * in — it is the only thing needed, and taking it as an argument keeps the
48
+ * import out of the bundle of anyone who does not animate:
49
+ *
50
+ * ```tsx
51
+ * import { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated'
52
+ *
53
+ * const field = useNitroInputState(useSharedValue)
54
+ * const border = useAnimatedStyle(() => ({
55
+ * borderColor: withTiming(field.focused.value ? '#2563eb' : '#94a3b8'),
56
+ * }))
57
+ *
58
+ * <Animated.View style={border}>
59
+ * <NitroInput {...field.handlers} />
60
+ * </Animated.View>
61
+ * ```
62
+ *
63
+ * Nothing above re-renders while you type: the handlers run on the UI runtime,
64
+ * write to shared values there, and the style reads them there.
65
+ */
66
+ export function useNitroInputState(useSharedValue: MakeShared): NitroInputState {
67
+ const text = useSharedValue('')
68
+ const value = useSharedValue(Number.NaN)
69
+ const focused = useSharedValue(false)
70
+ const selection = useSharedValue<NitroInputSelection>({ start: 0, end: 0 })
71
+
72
+ // Stable for the field's lifetime: a new function identity would re-register
73
+ // the worklet on the UI runtime every render.
74
+ const handlers = useMemo(
75
+ () => ({
76
+ onChangeText: (next: string) => {
77
+ 'worklet'
78
+ text.value = next
79
+ },
80
+ onChangeValue: (next: number) => {
81
+ 'worklet'
82
+ value.value = next
83
+ },
84
+ onFocus: () => {
85
+ 'worklet'
86
+ focused.value = true
87
+ },
88
+ onBlur: () => {
89
+ 'worklet'
90
+ focused.value = false
91
+ },
92
+ onSelectionChange: (event: { start: number; end: number }) => {
93
+ 'worklet'
94
+ selection.value = { start: event.start, end: event.end }
95
+ },
96
+ }),
97
+ [text, value, focused, selection]
98
+ )
99
+
100
+ return { text, value, focused, selection, handlers }
101
+ }