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