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,623 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.NitroInput = exports.NativeNitroInputView = void 0;
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const react_native_1 = require("react-native");
|
|
42
|
+
const react_native_nitro_modules_1 = require("react-native-nitro-modules");
|
|
43
|
+
const NitroInputViewConfig_json_1 = __importDefault(require("../nitrogen/generated/shared/json/NitroInputViewConfig.json"));
|
|
44
|
+
const worklets_1 = require("./worklets");
|
|
45
|
+
const textInputRegistry = (() => {
|
|
46
|
+
try {
|
|
47
|
+
// The registry has no public surface: `TextInput.State` exposes the focus
|
|
48
|
+
// commands but not `registerInput`, and registering is the whole point -
|
|
49
|
+
// it is how `ref.focus()`, `Keyboard.dismiss()` and a ScrollView's
|
|
50
|
+
// `keyboardShouldPersistTaps` recognise a text input at all. React Native's
|
|
51
|
+
// Babel preset logs a deprecation for every *literal* `react-native/...`
|
|
52
|
+
// import, in every app that bundles this package, and the guard around
|
|
53
|
+
// this call already is the deprecation policy: a version that moves the
|
|
54
|
+
// module degrades to plain focus rather than throwing. A template literal
|
|
55
|
+
// says the same path; Metro evaluates it, the warning plugin only matches
|
|
56
|
+
// string literals.
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
58
|
+
const mod = require(`react-native/Libraries/Components/TextInput/TextInputState`);
|
|
59
|
+
const state = (mod?.default ?? mod);
|
|
60
|
+
return typeof state?.focusInput === 'function' && typeof state?.blurInput === 'function'
|
|
61
|
+
? state
|
|
62
|
+
: null;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
// Both tables are React Native's own (`TextInput.js`), so an app that swaps a
|
|
69
|
+
// `TextInput` for this gets the same keyboard from the same prop.
|
|
70
|
+
const INPUT_MODE_TO_KEYBOARD = {
|
|
71
|
+
none: 'default',
|
|
72
|
+
text: 'default',
|
|
73
|
+
decimal: 'decimal-pad',
|
|
74
|
+
numeric: 'number-pad',
|
|
75
|
+
tel: 'phone-pad',
|
|
76
|
+
// RN picks iOS `web-search` here; this component has no such keyboard type,
|
|
77
|
+
// and Android already falls back to `default`.
|
|
78
|
+
search: 'default',
|
|
79
|
+
email: 'email-address',
|
|
80
|
+
url: 'url',
|
|
81
|
+
};
|
|
82
|
+
const ENTER_KEY_HINT_TO_RETURN_KEY = {
|
|
83
|
+
enter: 'default',
|
|
84
|
+
done: 'done',
|
|
85
|
+
go: 'go',
|
|
86
|
+
next: 'next',
|
|
87
|
+
// RN maps `previous` to an Android-only return key this component does not
|
|
88
|
+
// expose, so it falls back to the default on both.
|
|
89
|
+
previous: 'default',
|
|
90
|
+
search: 'search',
|
|
91
|
+
send: 'send',
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The react tag of a host instance, or 0 when there is none. Fabric's
|
|
95
|
+
* `ReactNativeElement` keeps it on `__nativeTag`; the pre-Fabric name was
|
|
96
|
+
* `_nativeTag`. Android's Nitro view hands out no instance at all, so 0.
|
|
97
|
+
*/
|
|
98
|
+
function reactTagOf(host) {
|
|
99
|
+
const instance = host;
|
|
100
|
+
const tag = instance?.__nativeTag ?? instance?._nativeTag;
|
|
101
|
+
return typeof tag === 'number' ? tag : 0;
|
|
102
|
+
}
|
|
103
|
+
const EMPTY_NOTATIONS = [];
|
|
104
|
+
/** Mounted fields, by the host instance React Native's registry stores. */
|
|
105
|
+
const mountedFields = new WeakMap();
|
|
106
|
+
let patchedRegistry = false;
|
|
107
|
+
/**
|
|
108
|
+
* `TextInputState.focusTextInput` / `blurTextInput` — which is how
|
|
109
|
+
* `Keyboard.dismiss()`, `keyboardShouldPersistTaps` and a ScrollView's
|
|
110
|
+
* auto-blur reach the focused input — dispatch a codegen `focus` / `blur`
|
|
111
|
+
* *view command*. A Nitro view has no such command on Android, so the call
|
|
112
|
+
* would be dropped and the keyboard would stay up. The two functions are
|
|
113
|
+
* wrapped once, on the registry module, to route a NitroInput to its own
|
|
114
|
+
* native focus/blur; every other input is passed straight through untouched.
|
|
115
|
+
*
|
|
116
|
+
* The wrap reaches every caller that reads the two off the module at call
|
|
117
|
+
* time, which `Keyboard.dismiss()` and `ScrollView` do. It does not reach
|
|
118
|
+
* `TextInput.State.focusTextInput` / `blurTextInput`: `TextInput.js` copies
|
|
119
|
+
* those references when it is evaluated, before this runs, so a call through
|
|
120
|
+
* them still dispatches the view command. On iOS `ios/NitroInputCommands.mm`
|
|
121
|
+
* answers that command; on Android it is dropped.
|
|
122
|
+
*/
|
|
123
|
+
function patchRegistryOnce() {
|
|
124
|
+
if (patchedRegistry || textInputRegistry == null)
|
|
125
|
+
return;
|
|
126
|
+
patchedRegistry = true;
|
|
127
|
+
const registry = textInputRegistry;
|
|
128
|
+
const originalFocus = registry.focusTextInput;
|
|
129
|
+
const originalBlur = registry.blurTextInput;
|
|
130
|
+
if (typeof originalFocus === 'function') {
|
|
131
|
+
registry.focusTextInput = (input) => {
|
|
132
|
+
const field = input != null ? mountedFields.get(input) : undefined;
|
|
133
|
+
if (field)
|
|
134
|
+
return field.focus();
|
|
135
|
+
return originalFocus.call(registry, input);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (typeof originalBlur === 'function') {
|
|
139
|
+
registry.blurTextInput = (input) => {
|
|
140
|
+
const field = input != null ? mountedFields.get(input) : undefined;
|
|
141
|
+
if (field)
|
|
142
|
+
return field.blur();
|
|
143
|
+
return originalBlur.call(registry, input);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The raw Nitro host component. Prefer {@link NitroInput}, which adds the
|
|
149
|
+
* controlled-value handshake, auto-sizing, color/weight conversion and a
|
|
150
|
+
* convenient handle.
|
|
151
|
+
*/
|
|
152
|
+
exports.NativeNitroInputView = (0, react_native_nitro_modules_1.getHostComponent)('NitroInputView', () => NitroInputViewConfig_json_1.default);
|
|
153
|
+
// shared-helpers:start
|
|
154
|
+
// Kept byte-for-byte identical with packages/react-native-nitro-rolling-number/src/RollingNumber.tsx
|
|
155
|
+
// (a test compares the two blocks); change both together.
|
|
156
|
+
const FONT_WEIGHTS = {
|
|
157
|
+
normal: 400,
|
|
158
|
+
regular: 400,
|
|
159
|
+
bold: 700,
|
|
160
|
+
ultralight: 100,
|
|
161
|
+
thin: 200,
|
|
162
|
+
light: 300,
|
|
163
|
+
medium: 500,
|
|
164
|
+
semibold: 600,
|
|
165
|
+
condensedBold: 700,
|
|
166
|
+
condensed: 400,
|
|
167
|
+
heavy: 800,
|
|
168
|
+
black: 900,
|
|
169
|
+
};
|
|
170
|
+
function toNumericWeight(weight) {
|
|
171
|
+
if (weight == null)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (typeof weight === 'number')
|
|
174
|
+
return weight;
|
|
175
|
+
const parsed = Number(weight);
|
|
176
|
+
if (!Number.isNaN(parsed))
|
|
177
|
+
return parsed;
|
|
178
|
+
return FONT_WEIGHTS[weight];
|
|
179
|
+
}
|
|
180
|
+
function toProcessedColor(color) {
|
|
181
|
+
if (color == null)
|
|
182
|
+
return undefined;
|
|
183
|
+
const processed = (0, react_native_1.processColor)(color);
|
|
184
|
+
return typeof processed === 'number' ? processed : undefined;
|
|
185
|
+
}
|
|
186
|
+
const warnedIncompatible = new Set();
|
|
187
|
+
/** Once per offending prop, not once per render. */
|
|
188
|
+
function warnIncompatible(what) {
|
|
189
|
+
if (warnedIncompatible.has(what))
|
|
190
|
+
return;
|
|
191
|
+
warnedIncompatible.add(what);
|
|
192
|
+
console.warn(`[NitroInput] \`${what}\` is ignored on a multiline field: a wrapping ` +
|
|
193
|
+
'field is drawn by the system view, and an amount, a mask and their ' +
|
|
194
|
+
'affixes are single-line. Drop one of the two.');
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* A native text input: a system field (`UITextField` / `EditText`) that owns
|
|
198
|
+
* the keyboard, editing, selection, paste and accessibility, with native
|
|
199
|
+
* formatting (`mode="number"`), native masking (`mode="mask"`), an outlined
|
|
200
|
+
* or filled frame with a floating label, and optionally the glyph engine
|
|
201
|
+
* (`morph`), under which characters that stay glide to their new place, new
|
|
202
|
+
* ones slide or fade in and removed ones leave alongside their neighbours.
|
|
203
|
+
* In `'number'` mode every edit is formatted on the native side before a
|
|
204
|
+
* frame is drawn, with the caret kept in place, so there is never an
|
|
205
|
+
* unformatted frame and never a round trip through JS.
|
|
206
|
+
*
|
|
207
|
+
* Like a `TextInput`, it takes its width from its parent; `autoWidth`
|
|
208
|
+
* (`'auto'` in {@link MorphInput}) sizes it to its content instead.
|
|
209
|
+
*/
|
|
210
|
+
exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, morph, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
211
|
+
const nativeRef = (0, react_1.useRef)(null);
|
|
212
|
+
// What React Native's registry stores for this field. The React host
|
|
213
|
+
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
214
|
+
// on Android the Nitro host component hands out no instance, and the
|
|
215
|
+
// registry only ever compares identity or passes the value back to us.
|
|
216
|
+
const hostRef = (0, react_1.useRef)(null);
|
|
217
|
+
const registryKeyRef = (0, react_1.useRef)(null);
|
|
218
|
+
// The last text and edit counter the native side reported. `focus`, `blur`
|
|
219
|
+
// and `keyPress` carry both but are not themselves edits, so they have
|
|
220
|
+
// nothing of their own to read them from.
|
|
221
|
+
const textRef = (0, react_1.useRef)(defaultValue ?? '');
|
|
222
|
+
const eventCountRef = (0, react_1.useRef)(0);
|
|
223
|
+
const latest = (0, react_1.useRef)({
|
|
224
|
+
onNativeRef,
|
|
225
|
+
onChangeText,
|
|
226
|
+
onChange,
|
|
227
|
+
onChangeValue,
|
|
228
|
+
onChangeMask,
|
|
229
|
+
onFocus,
|
|
230
|
+
onBlur,
|
|
231
|
+
onSubmitEditing,
|
|
232
|
+
onEndEditing,
|
|
233
|
+
onSelectionChange,
|
|
234
|
+
onKeyPress,
|
|
235
|
+
});
|
|
236
|
+
latest.current = {
|
|
237
|
+
onNativeRef,
|
|
238
|
+
onChangeText,
|
|
239
|
+
onChange,
|
|
240
|
+
onChangeValue,
|
|
241
|
+
onChangeMask,
|
|
242
|
+
onFocus,
|
|
243
|
+
onBlur,
|
|
244
|
+
onSubmitEditing,
|
|
245
|
+
onEndEditing,
|
|
246
|
+
onSelectionChange,
|
|
247
|
+
onKeyPress,
|
|
248
|
+
};
|
|
249
|
+
// A controlled field's text is the prop, not the last edit this saw.
|
|
250
|
+
if (value != null)
|
|
251
|
+
textRef.current = value;
|
|
252
|
+
const [size, setSize] = (0, react_1.useState)(null);
|
|
253
|
+
// Worklets are registered on the UI runtime and referenced by id; a
|
|
254
|
+
// handler marked 'worklet' runs there instead of on the JS thread.
|
|
255
|
+
const transformId = useWorkletId(transform, worklets_1.registerTransform);
|
|
256
|
+
const onChangeTextWorklet = (0, worklets_1.isWorklet)(onChangeText) ? onChangeText : undefined;
|
|
257
|
+
const onChangeValueWorklet = (0, worklets_1.isWorklet)(onChangeValue) ? onChangeValue : undefined;
|
|
258
|
+
const onChangeTextId = useWorkletId(onChangeTextWorklet, worklets_1.registerCallback);
|
|
259
|
+
const onChangeValueId = useWorkletId(onChangeValueWorklet, worklets_1.registerCallback);
|
|
260
|
+
// Marking any of these `'worklet'` moves it to the UI thread; the JS
|
|
261
|
+
// handler is then skipped, exactly as `onChangeText` already worked.
|
|
262
|
+
const onFocusId = useWorkletPairId((0, worklets_1.isWorklet)(onFocus) ? onFocus : undefined, (0, worklets_1.isWorklet)(onBlur) ? onBlur : undefined, worklets_1.registerFocusChange);
|
|
263
|
+
const onSelectionChangeId = useWorkletId((0, worklets_1.isWorklet)(onSelectionChange) ? onSelectionChange : undefined, worklets_1.registerSelectionChange);
|
|
264
|
+
const onSubmitEditingId = useWorkletId((0, worklets_1.isWorklet)(onSubmitEditing) ? onSubmitEditing : undefined, worklets_1.registerTextEvent);
|
|
265
|
+
const onEndEditingId = useWorkletId((0, worklets_1.isWorklet)(onEndEditing) ? onEndEditing : undefined, worklets_1.registerTextEvent);
|
|
266
|
+
const onKeyPressId = useWorkletId((0, worklets_1.isWorklet)(onKeyPress) ? onKeyPress : undefined, worklets_1.registerKeyPress);
|
|
267
|
+
// The latest native event count JS has processed: sent back with `text` so
|
|
268
|
+
// native can tell a stale controlled value (the user typed since) from a
|
|
269
|
+
// deliberate change. It lives in `eventCountRef` and is read from there at
|
|
270
|
+
// render; only a controlled field takes the state update that forces one,
|
|
271
|
+
// because only a controlled field's `text` prop can ever change. So an
|
|
272
|
+
// uncontrolled (or worklet-driven) field never re-renders on a keystroke,
|
|
273
|
+
// and a field made controlled later reads the fresh count on that render.
|
|
274
|
+
const [, setEventCountState] = (0, react_1.useState)(0);
|
|
275
|
+
const controlledRef = (0, react_1.useRef)(value != null);
|
|
276
|
+
controlledRef.current = value != null;
|
|
277
|
+
// The initial text of an uncontrolled field never changes afterwards, so
|
|
278
|
+
// native applies it exactly once.
|
|
279
|
+
const [initialText] = (0, react_1.useState)(() => defaultValue ?? '');
|
|
280
|
+
// Nitro callbacks must be wrapped with `callback()` and the wrapper object
|
|
281
|
+
// has to be referentially stable, otherwise every render re-sets the prop.
|
|
282
|
+
// Handlers are read through a ref so inline arrows don't re-set them either.
|
|
283
|
+
// Commands sent before the native view attaches (from a ref callback, a
|
|
284
|
+
// layout effect or an effect on mount) are kept and replayed the moment it
|
|
285
|
+
// does, as React Native queues a `TextInput`'s view commands. Without this
|
|
286
|
+
// the common `useEffect(() => ref.current?.focus(), [])` was a silent no-op.
|
|
287
|
+
const pendingCommands = (0, react_1.useRef)([]);
|
|
288
|
+
const hybridRef = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((instance) => {
|
|
289
|
+
nativeRef.current = instance;
|
|
290
|
+
const queued = pendingCommands.current;
|
|
291
|
+
pendingCommands.current = [];
|
|
292
|
+
for (const command of queued)
|
|
293
|
+
command(instance);
|
|
294
|
+
latest.current.onNativeRef?.(instance);
|
|
295
|
+
}), []);
|
|
296
|
+
(0, react_1.useEffect)(() => {
|
|
297
|
+
if (textInputRegistry == null)
|
|
298
|
+
return;
|
|
299
|
+
const key = hostRef.current ?? { nitroInput: true };
|
|
300
|
+
registryKeyRef.current = key;
|
|
301
|
+
patchRegistryOnce();
|
|
302
|
+
mountedFields.set(key, {
|
|
303
|
+
focus: () => nativeRef.current?.focus(),
|
|
304
|
+
blur: () => nativeRef.current?.blur(),
|
|
305
|
+
});
|
|
306
|
+
textInputRegistry.registerInput(key);
|
|
307
|
+
return () => {
|
|
308
|
+
if (textInputRegistry.currentlyFocusedInput() === key)
|
|
309
|
+
textInputRegistry.blurInput(key);
|
|
310
|
+
textInputRegistry.unregisterInput(key);
|
|
311
|
+
mountedFields.delete(key);
|
|
312
|
+
registryKeyRef.current = null;
|
|
313
|
+
};
|
|
314
|
+
}, []);
|
|
315
|
+
// A field with a width of its own (the usual case) never needs a React
|
|
316
|
+
// commit per keystroke: only the height (font-dependent) is taken from native.
|
|
317
|
+
const flat = (0, react_1.useMemo)(() => react_native_1.StyleSheet.flatten(style), [style]);
|
|
318
|
+
// The layout direction, resolved the way React Native resolves it for its
|
|
319
|
+
// own views: the field's `style.direction` if it says, else the app's.
|
|
320
|
+
// Fabric does not hand a Hybrid View its resolved direction, so native is
|
|
321
|
+
// told outright.
|
|
322
|
+
const rightToLeft = flat?.direction === 'rtl' || (flat?.direction !== 'ltr' && react_native_1.I18nManager.isRTL);
|
|
323
|
+
// `TextInput` stretches to its parent; sizing to content is this
|
|
324
|
+
// component's own behaviour, and it is what stops it being a drop-in.
|
|
325
|
+
// `NitroInput` turns it off so flexbox gives it the parent's width, the
|
|
326
|
+
// way a `TextInput` gets one.
|
|
327
|
+
const inferredAutoWidth = flat?.width == null && flat?.flex == null;
|
|
328
|
+
const autoWidth = autoWidthProp === 'auto' ? inferredAutoWidth : (autoWidthProp ?? false);
|
|
329
|
+
const autoWidthRef = (0, react_1.useRef)(autoWidth);
|
|
330
|
+
autoWidthRef.current = autoWidth;
|
|
331
|
+
// When the style pins both axes, the measured size is never used: `style`
|
|
332
|
+
// is applied after `autoSize`, so it wins. Taking the state update anyway
|
|
333
|
+
// costs a React commit per field on mount, which is pure waste for the
|
|
334
|
+
// common "field in a styled box" case.
|
|
335
|
+
const measured = autoWidth || flat?.height == null;
|
|
336
|
+
const measuredRef = (0, react_1.useRef)(measured);
|
|
337
|
+
measuredRef.current = measured;
|
|
338
|
+
const onSizeChange = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((width, height) => {
|
|
339
|
+
if (!measuredRef.current)
|
|
340
|
+
return;
|
|
341
|
+
setSize((previous) => {
|
|
342
|
+
if (!autoWidthRef.current) {
|
|
343
|
+
return previous !== null && previous.height === height ? previous : { width: previous?.width ?? width, height };
|
|
344
|
+
}
|
|
345
|
+
return previous !== null && previous.width === width && previous.height === height
|
|
346
|
+
? previous
|
|
347
|
+
: { width, height };
|
|
348
|
+
});
|
|
349
|
+
}), []);
|
|
350
|
+
const onChangeTextCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((text, count) => {
|
|
351
|
+
textRef.current = text;
|
|
352
|
+
eventCountRef.current = count;
|
|
353
|
+
if (controlledRef.current)
|
|
354
|
+
setEventCountState(count);
|
|
355
|
+
const handler = latest.current.onChangeText;
|
|
356
|
+
// A worklet handler already ran on the UI thread.
|
|
357
|
+
if (handler && !(0, worklets_1.isWorklet)(handler))
|
|
358
|
+
handler(text);
|
|
359
|
+
// `onChange` fires alongside it with the same text, as in RN. The
|
|
360
|
+
// target is the host tag when there is one (iOS); Android's Nitro
|
|
361
|
+
// view hands out no instance, so it is 0 there.
|
|
362
|
+
latest.current.onChange?.({
|
|
363
|
+
nativeEvent: { text, eventCount: count, target: reactTagOf(hostRef.current) },
|
|
364
|
+
});
|
|
365
|
+
}), []);
|
|
366
|
+
const onChangeValueCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((next) => {
|
|
367
|
+
const handler = latest.current.onChangeValue;
|
|
368
|
+
if (handler && !(0, worklets_1.isWorklet)(handler))
|
|
369
|
+
handler(next);
|
|
370
|
+
}), []);
|
|
371
|
+
const onChangeMaskCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((formatted, extracted, tailPlaceholder, complete) => {
|
|
372
|
+
latest.current.onChangeMask?.(formatted, extracted, tailPlaceholder, complete);
|
|
373
|
+
}), []);
|
|
374
|
+
// Every event below carries `nativeEvent` for a handler written against a
|
|
375
|
+
// `TextInput`, and the same fields at the top level for one written against
|
|
376
|
+
// this. Built here rather than natively: the native side sends the values,
|
|
377
|
+
// and the shape is a JavaScript convention React Native owns.
|
|
378
|
+
const textEvent = (text) => {
|
|
379
|
+
const target = reactTagOf(hostRef.current);
|
|
380
|
+
return { text, target, nativeEvent: { text, target } };
|
|
381
|
+
};
|
|
382
|
+
const onFocusChangeCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((focused) => {
|
|
383
|
+
const key = registryKeyRef.current;
|
|
384
|
+
if (key != null) {
|
|
385
|
+
if (focused)
|
|
386
|
+
textInputRegistry?.focusInput(key);
|
|
387
|
+
else
|
|
388
|
+
textInputRegistry?.blurInput(key);
|
|
389
|
+
}
|
|
390
|
+
const text = textRef.current;
|
|
391
|
+
const target = reactTagOf(hostRef.current);
|
|
392
|
+
const count = eventCountRef.current;
|
|
393
|
+
const event = {
|
|
394
|
+
text,
|
|
395
|
+
target,
|
|
396
|
+
eventCount: count,
|
|
397
|
+
nativeEvent: { text, target, eventCount: count },
|
|
398
|
+
};
|
|
399
|
+
const handler = focused ? latest.current.onFocus : latest.current.onBlur;
|
|
400
|
+
if (handler && !(0, worklets_1.isWorklet)(handler))
|
|
401
|
+
handler(event);
|
|
402
|
+
}), []);
|
|
403
|
+
const onSubmitEditingCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((text) => {
|
|
404
|
+
const handler = latest.current.onSubmitEditing;
|
|
405
|
+
if (handler && !(0, worklets_1.isWorklet)(handler))
|
|
406
|
+
handler(textEvent(text));
|
|
407
|
+
}),
|
|
408
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
409
|
+
[]);
|
|
410
|
+
const onEndEditingCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((text) => {
|
|
411
|
+
const handler = latest.current.onEndEditing;
|
|
412
|
+
if (handler && !(0, worklets_1.isWorklet)(handler))
|
|
413
|
+
handler(textEvent(text));
|
|
414
|
+
}),
|
|
415
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
416
|
+
[]);
|
|
417
|
+
const onSelectionChangeCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((start, end) => {
|
|
418
|
+
const handler = latest.current.onSelectionChange;
|
|
419
|
+
if (!handler || (0, worklets_1.isWorklet)(handler))
|
|
420
|
+
return;
|
|
421
|
+
const selection = { start, end };
|
|
422
|
+
const target = reactTagOf(hostRef.current);
|
|
423
|
+
handler({ selection, start, end, target, nativeEvent: { selection, target } });
|
|
424
|
+
}), []);
|
|
425
|
+
const onKeyPressCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((key) => {
|
|
426
|
+
const handler = latest.current.onKeyPress;
|
|
427
|
+
if (!handler || (0, worklets_1.isWorklet)(handler))
|
|
428
|
+
return;
|
|
429
|
+
const target = reactTagOf(hostRef.current);
|
|
430
|
+
const count = eventCountRef.current;
|
|
431
|
+
handler({ key, eventCount: count, target, nativeEvent: { key, eventCount: count, target } });
|
|
432
|
+
}), []);
|
|
433
|
+
// One handle for the component's lifetime: everything it reads goes
|
|
434
|
+
// through a ref, so a value change never hands the parent a new object.
|
|
435
|
+
(0, react_1.useImperativeHandle)(ref, () => {
|
|
436
|
+
const send = (command) => {
|
|
437
|
+
const native = nativeRef.current;
|
|
438
|
+
if (native != null)
|
|
439
|
+
command(native);
|
|
440
|
+
else
|
|
441
|
+
pendingCommands.current.push(command);
|
|
442
|
+
};
|
|
443
|
+
return {
|
|
444
|
+
focus: () => send((native) => native.focus()),
|
|
445
|
+
blur: () => send((native) => native.blur()),
|
|
446
|
+
clear: () => send((native) => native.clear()),
|
|
447
|
+
setText: (text) => send((native) => native.replaceText(text)),
|
|
448
|
+
setValue: (next) => send((native) => native.setValue(next)),
|
|
449
|
+
// Before the native view attaches, `textRef` is a controlled field's
|
|
450
|
+
// `value` and an uncontrolled one's initial text.
|
|
451
|
+
getText: () => nativeRef.current?.currentText() ?? textRef.current,
|
|
452
|
+
getValue: () => nativeRef.current?.getValue() ?? NaN,
|
|
453
|
+
// The native view is the truth once there is one - it knows whether it
|
|
454
|
+
// actually holds first responder. Before it attaches, fall back to the
|
|
455
|
+
// registry this field already keeps up to date, which is the same place
|
|
456
|
+
// `TextInput.isFocused()` reads from.
|
|
457
|
+
isFocused: () => nativeRef.current?.isFocused() ??
|
|
458
|
+
(registryKeyRef.current != null &&
|
|
459
|
+
textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
|
|
460
|
+
setSelection: (start, end) => send((native) => native.setSelection(start, end ?? start)),
|
|
461
|
+
get native() {
|
|
462
|
+
return nativeRef.current;
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
}, []);
|
|
466
|
+
// Every native prop is sent with an explicit value: an optional prop that
|
|
467
|
+
// is *removed* reaches native as `null`, which Nitro's parser rejects and
|
|
468
|
+
// React Native turns into a fatal error. `Infinity` stands for "platform default"
|
|
469
|
+
// where there is no value to express it (colors), `''` for fonts.
|
|
470
|
+
// Not `NaN`: Nitro only calls a native setter when a prop's value changed,
|
|
471
|
+
// and NaN never equals itself, so a NaN sentinel re-applied the whole
|
|
472
|
+
// configuration on every render (every keystroke of a controlled field).
|
|
473
|
+
const processedColor = (0, react_1.useMemo)(() => toProcessedColor(color) ?? Infinity, [color]);
|
|
474
|
+
const processedPlaceholderColor = (0, react_1.useMemo)(() => toProcessedColor(placeholderTextColor) ?? Infinity, [placeholderTextColor]);
|
|
475
|
+
const processedCursorColor = (0, react_1.useMemo)(() => toProcessedColor(cursorColor) ?? Infinity, [cursorColor]);
|
|
476
|
+
const processedSelectionColor = (0, react_1.useMemo)(() => toProcessedColor(selectionColor) ?? Infinity, [selectionColor]);
|
|
477
|
+
const processedLabelColor = (0, react_1.useMemo)(() => toProcessedColor(labelColor) ?? Infinity, [labelColor]);
|
|
478
|
+
const processedLabelFocusedColor = (0, react_1.useMemo)(() => toProcessedColor(labelFocusedColor) ?? Infinity, [labelFocusedColor]);
|
|
479
|
+
const processedStrokeColor = (0, react_1.useMemo)(() => toProcessedColor(strokeColor) ?? Infinity, [strokeColor]);
|
|
480
|
+
const processedFocusedStrokeColor = (0, react_1.useMemo)(() => toProcessedColor(focusedStrokeColor) ?? Infinity, [focusedStrokeColor]);
|
|
481
|
+
const processedFillColor = (0, react_1.useMemo)(() => toProcessedColor(fillColor) ?? Infinity, [fillColor]);
|
|
482
|
+
const numericWeight = toNumericWeight(fontWeight) ?? 400;
|
|
483
|
+
const resolvedFontSize = fontSize ?? 32;
|
|
484
|
+
const resolvedAffixAlign = affixAlign ?? 'baseline';
|
|
485
|
+
// Multiline is drawn by the system view and is always text: the glyph
|
|
486
|
+
// engine lays one run out on one baseline, and an amount or a mask is a
|
|
487
|
+
// single-line idea. Rather than half-honour the combination, drop the part
|
|
488
|
+
// that cannot work and say so.
|
|
489
|
+
const isMultiline = multiline ?? false;
|
|
490
|
+
if (__DEV__ && isMultiline) {
|
|
491
|
+
if (mode != null && mode !== 'text') {
|
|
492
|
+
warnIncompatible(`mode="${mode}"`);
|
|
493
|
+
}
|
|
494
|
+
if (morph)
|
|
495
|
+
warnIncompatible('morph');
|
|
496
|
+
if (prefix)
|
|
497
|
+
warnIncompatible('prefix');
|
|
498
|
+
if (suffix)
|
|
499
|
+
warnIncompatible('suffix');
|
|
500
|
+
}
|
|
501
|
+
const resolvedMode = isMultiline ? 'text' : (mode ?? 'text');
|
|
502
|
+
const resolvedMorph = isMultiline ? false : (morph ?? false);
|
|
503
|
+
// The affixes are accessory views beside one line of text; a wrapping text
|
|
504
|
+
// view has no slot for them, so they go with the mode rather than being
|
|
505
|
+
// half-drawn on one platform and not the other.
|
|
506
|
+
const resolvedPrefix = isMultiline ? '' : (prefix ?? '');
|
|
507
|
+
const resolvedSuffix = isMultiline ? '' : (suffix ?? '');
|
|
508
|
+
// A new `maskNotations` literal each render must not re-set the native
|
|
509
|
+
// prop, so it is keyed on its contents. Always an array (empty = none):
|
|
510
|
+
// removing the prop would reach native as `null`, which Nitro's array
|
|
511
|
+
// parser rejects.
|
|
512
|
+
const notationsKey = maskNotations != null && maskNotations.length > 0 ? JSON.stringify(maskNotations) : '';
|
|
513
|
+
const stableNotations = (0, react_1.useMemo)(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
|
|
514
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
515
|
+
[notationsKey]);
|
|
516
|
+
const resolvedFractionDigits = fractionDigits ?? 2;
|
|
517
|
+
const resolvedKeyboardType = keyboardType ??
|
|
518
|
+
(inputMode != null
|
|
519
|
+
? INPUT_MODE_TO_KEYBOARD[inputMode]
|
|
520
|
+
: resolvedMode === 'number'
|
|
521
|
+
? resolvedFractionDigits > 0
|
|
522
|
+
? 'decimal-pad'
|
|
523
|
+
: 'number-pad'
|
|
524
|
+
: 'default');
|
|
525
|
+
const resolvedReturnKeyType = returnKeyType ?? (enterKeyHint != null ? ENTER_KEY_HINT_TO_RETURN_KEY[enterKeyHint] : 'default');
|
|
526
|
+
// `inputMode="none"` means "focus it but show no keyboard", as in RN.
|
|
527
|
+
const resolvedShowSoftInput = showSoftInputOnFocus ?? (inputMode != null ? inputMode !== 'none' : true);
|
|
528
|
+
// React Native resolves its HTML-flavoured aliases inside its own
|
|
529
|
+
// components; a Nitro view is handed the raw props, so `aria-label` and
|
|
530
|
+
// `id` would arrive unresolved and be dropped by the C++ parser. Both take
|
|
531
|
+
// precedence over the older spelling, as they do on a `TextInput`.
|
|
532
|
+
//
|
|
533
|
+
// The label goes on the hidden field (below), so leaving it on the host as
|
|
534
|
+
// well would put the same label on two accessibility elements. `testID`
|
|
535
|
+
// stays on the host too: it makes no accessibility element of its own, and
|
|
536
|
+
// a test that already queries the host must keep working.
|
|
537
|
+
const { accessibilityLabel, 'aria-label': ariaLabel, 'aria-busy': ariaBusy, 'aria-checked': ariaChecked, 'aria-disabled': ariaDisabled, 'aria-expanded': ariaExpanded, 'aria-selected': ariaSelected, 'aria-hidden': ariaHidden, 'aria-labelledby': ariaLabelledBy, accessibilityState, accessibilityElementsHidden, accessibilityLabelledBy, importantForAccessibility, id, nativeID, ...restViewProps } = viewProps;
|
|
538
|
+
const resolvedAccessibilityLabel = ariaLabel ?? accessibilityLabel;
|
|
539
|
+
const resolvedNativeID = id ?? nativeID;
|
|
540
|
+
// The `aria-*` state, hidden and labelled-by props, folded the way
|
|
541
|
+
// `TextInput` folds them: the aria spelling wins over the older one, and
|
|
542
|
+
// `aria-hidden` becomes the platform's own notion of hidden.
|
|
543
|
+
const hasState = accessibilityState != null ||
|
|
544
|
+
ariaBusy != null ||
|
|
545
|
+
ariaChecked != null ||
|
|
546
|
+
ariaDisabled != null ||
|
|
547
|
+
ariaExpanded != null ||
|
|
548
|
+
ariaSelected != null;
|
|
549
|
+
const resolvedAccessibilityState = hasState
|
|
550
|
+
? {
|
|
551
|
+
busy: ariaBusy ?? accessibilityState?.busy,
|
|
552
|
+
checked: ariaChecked ?? accessibilityState?.checked,
|
|
553
|
+
disabled: ariaDisabled ?? accessibilityState?.disabled,
|
|
554
|
+
expanded: ariaExpanded ?? accessibilityState?.expanded,
|
|
555
|
+
selected: ariaSelected ?? accessibilityState?.selected,
|
|
556
|
+
}
|
|
557
|
+
: undefined;
|
|
558
|
+
const resolvedElementsHidden = ariaHidden ?? accessibilityElementsHidden;
|
|
559
|
+
const resolvedImportance = ariaHidden === true ? 'no-hide-descendants' : importantForAccessibility;
|
|
560
|
+
const resolvedLabelledBy = ariaLabelledBy ?? accessibilityLabelledBy;
|
|
561
|
+
// Added only when there is one: a native prop is never sent `undefined`.
|
|
562
|
+
const hostViewProps = { ...restViewProps };
|
|
563
|
+
if (resolvedNativeID != null)
|
|
564
|
+
hostViewProps.nativeID = resolvedNativeID;
|
|
565
|
+
if (resolvedAccessibilityState != null)
|
|
566
|
+
hostViewProps.accessibilityState = resolvedAccessibilityState;
|
|
567
|
+
if (resolvedElementsHidden != null)
|
|
568
|
+
hostViewProps.accessibilityElementsHidden = resolvedElementsHidden;
|
|
569
|
+
if (resolvedImportance != null)
|
|
570
|
+
hostViewProps.importantForAccessibility = resolvedImportance;
|
|
571
|
+
if (resolvedLabelledBy != null)
|
|
572
|
+
hostViewProps.accessibilityLabelledBy = resolvedLabelledBy;
|
|
573
|
+
const autoSize = (0, react_1.useMemo)(() => size !== null
|
|
574
|
+
? autoWidth
|
|
575
|
+
? { width: size.width, height: size.height }
|
|
576
|
+
: { height: size.height }
|
|
577
|
+
: { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
|
|
578
|
+
return (react_1.default.createElement(exports.NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !resolvedMorph, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
|
|
579
|
+
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
580
|
+
// field's return key inserts a line break unless told to blur.
|
|
581
|
+
(multiline
|
|
582
|
+
? blurOnSubmit === true
|
|
583
|
+
? 'blurAndSubmit'
|
|
584
|
+
: 'newline'
|
|
585
|
+
: blurOnSubmit === false
|
|
586
|
+
? 'submit'
|
|
587
|
+
: 'blurAndSubmit'), secureTextEntry: secureTextEntry ?? false, keyboardAppearance: keyboardAppearance ?? 'default', textContentType: textContentType ?? autoComplete ?? '', enablesReturnKeyAutomatically: enablesReturnKeyAutomatically ?? false, showSoftInputOnFocus: resolvedShowSoftInput, selectTextOnFocus: selectTextOnFocus ?? false, clearTextOnFocus: clearTextOnFocus ?? false, contextMenuHidden: contextMenuHidden ?? false, spellCheck: spellCheck ?? autoCorrect ?? true, selectionStart: selection?.start ?? -1, selectionEnd: selection?.end ?? selection?.start ?? -1, maxLength: maxLength ?? 0, transformWorklet: transformId, onChangeTextWorklet: onChangeTextId, onChangeValueWorklet: onChangeValueId, onFocusChangeWorklet: onFocusId, onSelectionChangeWorklet: onSelectionChangeId, onSubmitEditingWorklet: onSubmitEditingId, onEndEditingWorklet: onEndEditingId, onKeyPressWorklet: onKeyPressId, onChangeText: onChangeTextCallback, onChangeValue: onChangeValueCallback, onFocusChange: onFocusChangeCallback, onSubmitEditing: onSubmitEditingCallback, onEndEditing: onEndEditingCallback, onSelectionChange: onSelectionChangeCallback, onKeyPress: onKeyPressCallback, onSizeChange: onSizeChange }));
|
|
588
|
+
});
|
|
589
|
+
// The name DevTools and error stacks show, as `TextInput` names itself.
|
|
590
|
+
exports.NitroInput.displayName = 'NitroInput';
|
|
591
|
+
/**
|
|
592
|
+
* Registers `fn` on the UI runtime for as long as it stays the same function
|
|
593
|
+
* and returns its id (`0` while there is none or worklets are unavailable).
|
|
594
|
+
*
|
|
595
|
+
* The id is reserved during render so the first commit already carries it, but
|
|
596
|
+
* the registration itself happens in the effect: a render React discards (under
|
|
597
|
+
* StrictMode, or a concurrent render that loses) would otherwise leave an entry
|
|
598
|
+
* on the UI runtime that no cleanup ever removes.
|
|
599
|
+
*/
|
|
600
|
+
function useWorkletId(fn, register) {
|
|
601
|
+
const id = (0, react_1.useMemo)(() => (fn ? (0, worklets_1.allocateWorkletId)() : 0), [fn]);
|
|
602
|
+
(0, react_1.useEffect)(() => {
|
|
603
|
+
if (id === 0 || !fn)
|
|
604
|
+
return;
|
|
605
|
+
register(fn, id);
|
|
606
|
+
return () => (0, worklets_1.unregisterWorklet)(id);
|
|
607
|
+
}, [id, fn, register]);
|
|
608
|
+
return id;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* The same, for the focus pair: native reports one focus change, so the two
|
|
612
|
+
* handlers share an id and the wrapper picks between them.
|
|
613
|
+
*/
|
|
614
|
+
function useWorkletPairId(onFocus, onBlur, register) {
|
|
615
|
+
const id = (0, react_1.useMemo)(() => (onFocus || onBlur ? (0, worklets_1.allocateWorkletId)() : 0), [onFocus, onBlur]);
|
|
616
|
+
(0, react_1.useEffect)(() => {
|
|
617
|
+
if (id === 0)
|
|
618
|
+
return;
|
|
619
|
+
register(onFocus, onBlur, id);
|
|
620
|
+
return () => (0, worklets_1.unregisterWorklet)(id);
|
|
621
|
+
}, [id, onFocus, onBlur, register]);
|
|
622
|
+
return id;
|
|
623
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNitroInputState = exports.isWorklet = exports.MorphInput = exports.NativeNitroInputView = exports.NitroInput = void 0;
|
|
4
|
+
var NitroInput_1 = require("./NitroInput");
|
|
5
|
+
Object.defineProperty(exports, "NitroInput", { enumerable: true, get: function () { return NitroInput_1.NitroInput; } });
|
|
6
|
+
Object.defineProperty(exports, "NativeNitroInputView", { enumerable: true, get: function () { return NitroInput_1.NativeNitroInputView; } });
|
|
7
|
+
var MorphInput_1 = require("./MorphInput");
|
|
8
|
+
Object.defineProperty(exports, "MorphInput", { enumerable: true, get: function () { return MorphInput_1.MorphInput; } });
|
|
9
|
+
var worklets_1 = require("./worklets");
|
|
10
|
+
Object.defineProperty(exports, "isWorklet", { enumerable: true, get: function () { return worklets_1.isWorklet; } });
|
|
11
|
+
var useNitroInputState_1 = require("./useNitroInputState");
|
|
12
|
+
Object.defineProperty(exports, "useNitroInputState", { enumerable: true, get: function () { return useNitroInputState_1.useNitroInputState; } });
|