react-native-nitro-input 0.1.0 → 0.2.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 +305 -3
- package/NitroInput.podspec +4 -4
- package/README.md +378 -53
- package/android/CMakeLists.txt +5 -3
- package/android/src/main/cpp/JOutlineGeometry.hpp +1 -1
- package/android/src/main/cpp/JReflowEngine.cpp +132 -0
- package/android/src/main/cpp/{JMorphEngine.hpp → JReflowEngine.hpp} +7 -7
- package/android/src/main/cpp/JRollingEngine.cpp +222 -0
- package/android/src/main/cpp/JRollingEngine.hpp +68 -0
- package/android/src/main/cpp/cpp-adapter.cpp +4 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +471 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +38 -16
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1741 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/{MorphEngine.kt → ReflowEngine.kt} +2 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +59 -0
- package/cpp/AmountFormatter.cpp +5 -0
- package/cpp/AmountFormatter.hpp +10 -2
- package/cpp/{MorphEngine.cpp → ReflowEngine.cpp} +52 -47
- package/cpp/{MorphEngine.hpp → ReflowEngine.hpp} +12 -4
- package/cpp/RollingEngine.cpp +1224 -0
- package/cpp/RollingEngine.hpp +468 -0
- package/cpp/SwiftNonCopyable.hpp +22 -0
- package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
- package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
- package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +1 -1
- package/ios/HybridNitroNumberView.swift +439 -0
- package/ios/NitroInputView.swift +69 -45
- package/ios/NitroNumberView.swift +1934 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/lib/commonjs/src/NitroInput.js +21 -52
- package/lib/commonjs/src/NitroNumber.js +139 -0
- package/lib/commonjs/src/index.js +4 -3
- package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
- package/lib/commonjs/src/styleHelpers.js +36 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/lib/module/src/NitroInput.js +12 -43
- package/lib/module/src/NitroNumber.js +100 -0
- package/lib/module/src/index.js +1 -1
- package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
- package/lib/module/src/styleHelpers.js +32 -0
- package/lib/typescript/src/NitroInput.d.ts +28 -21
- package/lib/typescript/src/NitroNumber.d.ts +211 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +9 -9
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +238 -0
- package/lib/typescript/src/styleHelpers.d.ts +3 -0
- package/nitro.json +10 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +4 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +20 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +10 -10
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +536 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +156 -0
- package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberEasing.hpp +67 -0
- package/nitrogen/generated/android/c++/JNitroNumberRevealStyle.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroNumberTextAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberTransition.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +299 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +9 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +363 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberAffixAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberEasing.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberRevealStyle.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTextAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTransition.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +248 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +23 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +432 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +414 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +5 -5
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +102 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1243 -0
- package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberEasing.swift +52 -0
- package/nitrogen/generated/ios/swift/NitroNumberRevealStyle.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroNumberTextAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberTransition.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +115 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +175 -0
- package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberEasing.hpp +88 -0
- package/nitrogen/generated/shared/c++/NitroNumberRevealStyle.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroNumberTextAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberTransition.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +124 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +227 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/package.json +15 -7
- package/src/NitroInput.tsx +37 -60
- package/src/NitroNumber.tsx +481 -0
- package/src/index.ts +20 -6
- package/src/specs/NitroInput.nitro.ts +9 -9
- package/src/specs/NitroNumber.nitro.ts +259 -0
- package/src/styleHelpers.ts +32 -0
- package/android/src/main/cpp/JMorphEngine.cpp +0 -132
- package/lib/commonjs/src/MorphInput.js +0 -42
- package/lib/module/src/MorphInput.js +0 -6
- package/lib/typescript/src/MorphInput.d.ts +0 -18
- package/src/MorphInput.tsx +0 -30
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"uiViewClassName": "NitroNumberView",
|
|
3
|
+
"supportsRawText": false,
|
|
4
|
+
"bubblingEventTypes": {},
|
|
5
|
+
"directEventTypes": {},
|
|
6
|
+
"validAttributes": {
|
|
7
|
+
"value": true,
|
|
8
|
+
"fractionDigits": true,
|
|
9
|
+
"minimumIntegerDigits": true,
|
|
10
|
+
"groupingSeparator": true,
|
|
11
|
+
"decimalSeparator": true,
|
|
12
|
+
"prefix": true,
|
|
13
|
+
"suffix": true,
|
|
14
|
+
"duration": true,
|
|
15
|
+
"easing": true,
|
|
16
|
+
"bounce": true,
|
|
17
|
+
"stagger": true,
|
|
18
|
+
"transition": true,
|
|
19
|
+
"flashUpColor": true,
|
|
20
|
+
"flashDownColor": true,
|
|
21
|
+
"flashDuration": true,
|
|
22
|
+
"popOnChange": true,
|
|
23
|
+
"rollDirection": true,
|
|
24
|
+
"revealState": true,
|
|
25
|
+
"revealStyle": true,
|
|
26
|
+
"revealDuration": true,
|
|
27
|
+
"revealBounce": true,
|
|
28
|
+
"revealGrow": true,
|
|
29
|
+
"revealStagger": true,
|
|
30
|
+
"revealMilestones": true,
|
|
31
|
+
"revealMilestoneHold": true,
|
|
32
|
+
"loading": true,
|
|
33
|
+
"shimmerColor": true,
|
|
34
|
+
"shimmerDuration": true,
|
|
35
|
+
"fontSize": true,
|
|
36
|
+
"prefixFontSize": true,
|
|
37
|
+
"suffixFontSize": true,
|
|
38
|
+
"affixAlign": true,
|
|
39
|
+
"prefixAlign": true,
|
|
40
|
+
"suffixAlign": true,
|
|
41
|
+
"adjustsFontSizeToFit": true,
|
|
42
|
+
"minimumFontScale": true,
|
|
43
|
+
"allowFontScaling": true,
|
|
44
|
+
"maxFontSizeMultiplier": true,
|
|
45
|
+
"fontWeight": true,
|
|
46
|
+
"fontFamily": true,
|
|
47
|
+
"color": true,
|
|
48
|
+
"textAlign": true,
|
|
49
|
+
"rightToLeft": true,
|
|
50
|
+
"onSizeChange": true,
|
|
51
|
+
"onRevealEnd": true,
|
|
52
|
+
"onRevealMilestone": true,
|
|
53
|
+
"hybridRef": true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -42,6 +42,7 @@ const react_native_1 = require("react-native");
|
|
|
42
42
|
const react_native_nitro_modules_1 = require("react-native-nitro-modules");
|
|
43
43
|
const NitroInputViewConfig_json_1 = __importDefault(require("../nitrogen/generated/shared/json/NitroInputViewConfig.json"));
|
|
44
44
|
const worklets_1 = require("./worklets");
|
|
45
|
+
const styleHelpers_1 = require("./styleHelpers");
|
|
45
46
|
const textInputRegistry = (() => {
|
|
46
47
|
try {
|
|
47
48
|
// The registry has no public surface: `TextInput.State` exposes the focus
|
|
@@ -150,39 +151,6 @@ function patchRegistryOnce() {
|
|
|
150
151
|
* convenient handle.
|
|
151
152
|
*/
|
|
152
153
|
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
154
|
const warnedIncompatible = new Set();
|
|
187
155
|
/** Once per offending prop, not once per render. */
|
|
188
156
|
function warnIncompatible(what) {
|
|
@@ -198,16 +166,16 @@ function warnIncompatible(what) {
|
|
|
198
166
|
* the keyboard, editing, selection, paste and accessibility, with native
|
|
199
167
|
* formatting (`mode="number"`), native masking (`mode="mask"`), an outlined
|
|
200
168
|
* or filled frame with a floating label, and optionally the glyph engine
|
|
201
|
-
* (`
|
|
169
|
+
* (`transition="reflow"`), under which characters that stay glide to their new place, new
|
|
202
170
|
* ones slide or fade in and removed ones leave alongside their neighbours.
|
|
203
171
|
* In `'number'` mode every edit is formatted on the native side before a
|
|
204
172
|
* frame is drawn, with the caret kept in place, so there is never an
|
|
205
173
|
* unformatted frame and never a round trip through JS.
|
|
206
174
|
*
|
|
207
|
-
* Like a `TextInput`, it takes its width from its parent; `autoWidth`
|
|
208
|
-
*
|
|
175
|
+
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
176
|
+
* it to its content instead, and is on by default when the text reflows.
|
|
209
177
|
*/
|
|
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,
|
|
178
|
+
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, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
211
179
|
const nativeRef = (0, react_1.useRef)(null);
|
|
212
180
|
// What React Native's registry stores for this field. The React host
|
|
213
181
|
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
@@ -325,7 +293,8 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
325
293
|
// `NitroInput` turns it off so flexbox gives it the parent's width, the
|
|
326
294
|
// way a `TextInput` gets one.
|
|
327
295
|
const inferredAutoWidth = flat?.width == null && flat?.flex == null;
|
|
328
|
-
const
|
|
296
|
+
const autoWidthSetting = autoWidthProp ?? (transition === 'reflow' && !multiline ? 'auto' : false);
|
|
297
|
+
const autoWidth = autoWidthSetting === 'auto' ? inferredAutoWidth : autoWidthSetting;
|
|
329
298
|
const autoWidthRef = (0, react_1.useRef)(autoWidth);
|
|
330
299
|
autoWidthRef.current = autoWidth;
|
|
331
300
|
// When the style pins both axes, the measured size is never used: `style`
|
|
@@ -470,16 +439,16 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
470
439
|
// Not `NaN`: Nitro only calls a native setter when a prop's value changed,
|
|
471
440
|
// and NaN never equals itself, so a NaN sentinel re-applied the whole
|
|
472
441
|
// 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;
|
|
442
|
+
const processedColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(color) ?? Infinity, [color]);
|
|
443
|
+
const processedPlaceholderColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(placeholderTextColor) ?? Infinity, [placeholderTextColor]);
|
|
444
|
+
const processedCursorColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(cursorColor) ?? Infinity, [cursorColor]);
|
|
445
|
+
const processedSelectionColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(selectionColor) ?? Infinity, [selectionColor]);
|
|
446
|
+
const processedLabelColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(labelColor) ?? Infinity, [labelColor]);
|
|
447
|
+
const processedLabelFocusedColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(labelFocusedColor) ?? Infinity, [labelFocusedColor]);
|
|
448
|
+
const processedStrokeColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(strokeColor) ?? Infinity, [strokeColor]);
|
|
449
|
+
const processedFocusedStrokeColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(focusedStrokeColor) ?? Infinity, [focusedStrokeColor]);
|
|
450
|
+
const processedFillColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(fillColor) ?? Infinity, [fillColor]);
|
|
451
|
+
const numericWeight = (0, styleHelpers_1.toNumericWeight)(fontWeight) ?? 400;
|
|
483
452
|
const resolvedFontSize = fontSize ?? 32;
|
|
484
453
|
const resolvedAffixAlign = affixAlign ?? 'baseline';
|
|
485
454
|
// Multiline is drawn by the system view and is always text: the glyph
|
|
@@ -491,15 +460,15 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
491
460
|
if (mode != null && mode !== 'text') {
|
|
492
461
|
warnIncompatible(`mode="${mode}"`);
|
|
493
462
|
}
|
|
494
|
-
if (
|
|
495
|
-
warnIncompatible('
|
|
463
|
+
if (transition === 'reflow')
|
|
464
|
+
warnIncompatible('transition="reflow"');
|
|
496
465
|
if (prefix)
|
|
497
466
|
warnIncompatible('prefix');
|
|
498
467
|
if (suffix)
|
|
499
468
|
warnIncompatible('suffix');
|
|
500
469
|
}
|
|
501
470
|
const resolvedMode = isMultiline ? 'text' : (mode ?? 'text');
|
|
502
|
-
const
|
|
471
|
+
const reflows = !isMultiline && transition === 'reflow';
|
|
503
472
|
// The affixes are accessory views beside one line of text; a wrapping text
|
|
504
473
|
// view has no slot for them, so they go with the mode rather than being
|
|
505
474
|
// half-drawn on one platform and not the other.
|
|
@@ -575,7 +544,7 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
575
544
|
? { width: size.width, height: size.height }
|
|
576
545
|
: { height: size.height }
|
|
577
546
|
: { 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: !
|
|
547
|
+
return (react_1.default.createElement(exports.NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? ',', 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
548
|
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
580
549
|
// field's return key inserts a line break unless told to blur.
|
|
581
550
|
(multiline
|
|
@@ -0,0 +1,139 @@
|
|
|
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.NitroNumber = exports.NativeNitroNumberView = 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 NitroNumberViewConfig_json_1 = __importDefault(require("../nitrogen/generated/shared/json/NitroNumberViewConfig.json"));
|
|
44
|
+
const styleHelpers_1 = require("./styleHelpers");
|
|
45
|
+
/**
|
|
46
|
+
* The raw Nitro host component. Prefer {@link NitroNumber}, which adds
|
|
47
|
+
* auto-sizing, color/weight conversion and a convenient handle.
|
|
48
|
+
*/
|
|
49
|
+
exports.NativeNitroNumberView = (0, react_native_nitro_modules_1.getHostComponent)('NitroNumberView', () => NitroNumberViewConfig_json_1.default);
|
|
50
|
+
/** Each transition's own timing, used when the props leave it unsaid. */
|
|
51
|
+
const TRANSITION_DEFAULTS = {
|
|
52
|
+
roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
|
|
53
|
+
numeric: { duration: 480, easing: 'spring', stagger: 150 },
|
|
54
|
+
scramble: { duration: 500, easing: 'linear', stagger: 60 },
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* A number that animates its changes natively: an odometer roll, SwiftUI's
|
|
58
|
+
* numeric transition or a scramble.
|
|
59
|
+
*
|
|
60
|
+
* Change `value` and every digit rolls to its new glyph on the native side.
|
|
61
|
+
* Use the ref's `animateTo` / `jumpTo` for imperative updates.
|
|
62
|
+
*
|
|
63
|
+
* The view sizes itself to its content unless you pass an explicit `width` /
|
|
64
|
+
* `height` in `style`.
|
|
65
|
+
*/
|
|
66
|
+
exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, onNativeRef, style, ...viewProps }, ref) {
|
|
67
|
+
const nativeRef = (0, react_1.useRef)(null);
|
|
68
|
+
const latestOnNativeRef = (0, react_1.useRef)(onNativeRef);
|
|
69
|
+
latestOnNativeRef.current = onNativeRef;
|
|
70
|
+
const latestOnRevealEnd = (0, react_1.useRef)(onRevealEnd);
|
|
71
|
+
latestOnRevealEnd.current = onRevealEnd;
|
|
72
|
+
const latestOnRevealMilestone = (0, react_1.useRef)(onRevealMilestone);
|
|
73
|
+
latestOnRevealMilestone.current = onRevealMilestone;
|
|
74
|
+
const latestValue = (0, react_1.useRef)(value);
|
|
75
|
+
latestValue.current = value;
|
|
76
|
+
const [size, setSize] = (0, react_1.useState)(null);
|
|
77
|
+
// Nitro callbacks must be wrapped with `callback()` and the wrapper object
|
|
78
|
+
// has to be referentially stable, otherwise every render re-sets the prop.
|
|
79
|
+
const hybridRef = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((instance) => {
|
|
80
|
+
nativeRef.current = instance;
|
|
81
|
+
latestOnNativeRef.current?.(instance);
|
|
82
|
+
}), []);
|
|
83
|
+
const onSizeChange = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((width, height) => {
|
|
84
|
+
setSize((previous) => previous !== null &&
|
|
85
|
+
previous.width === width &&
|
|
86
|
+
previous.height === height
|
|
87
|
+
? previous
|
|
88
|
+
: { width, height });
|
|
89
|
+
}), []);
|
|
90
|
+
// Stable like the others; the latest handler is read through a ref so a
|
|
91
|
+
// caller passing an inline arrow doesn't re-set the native prop each render.
|
|
92
|
+
const onRevealEndCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)(() => {
|
|
93
|
+
latestOnRevealEnd.current?.();
|
|
94
|
+
}), []);
|
|
95
|
+
const onRevealMilestoneCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((index, milestone) => {
|
|
96
|
+
latestOnRevealMilestone.current?.(index, milestone);
|
|
97
|
+
}), []);
|
|
98
|
+
// A new array literal each render must not re-set the native prop. Always an
|
|
99
|
+
// array (empty = no tiers): removing the prop would reach native as `null`,
|
|
100
|
+
// which Nitro's array parser rejects ("Value is null, expected an Object").
|
|
101
|
+
const milestonesKey = revealMilestones?.join(',') ?? '';
|
|
102
|
+
const stableMilestones = (0, react_1.useMemo)(() => (revealMilestones ? [...revealMilestones] : []),
|
|
103
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
104
|
+
[milestonesKey]);
|
|
105
|
+
// One handle for the component's lifetime: `getValue` reads the latest
|
|
106
|
+
// prop through a ref, so a value change doesn't hand the parent a new object.
|
|
107
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
108
|
+
jumpTo: (next) => nativeRef.current?.jumpTo(next),
|
|
109
|
+
animateTo: (next) => nativeRef.current?.animateTo(next),
|
|
110
|
+
revealTo: (next) => nativeRef.current?.revealTo(next),
|
|
111
|
+
getValue: () => nativeRef.current?.value ?? latestValue.current,
|
|
112
|
+
get native() {
|
|
113
|
+
return nativeRef.current;
|
|
114
|
+
},
|
|
115
|
+
}), []);
|
|
116
|
+
// Every native prop is sent with an explicit value: an optional prop that
|
|
117
|
+
// is *removed* reaches native as `null`, which Nitro's parser rejects and
|
|
118
|
+
// React Native turns into a fatal error. `Infinity` stands for "platform
|
|
119
|
+
// default" where there is no value to express it (colors), `''` for fonts.
|
|
120
|
+
// Not `NaN`: Nitro only calls a native setter when a prop's value changed,
|
|
121
|
+
// and NaN never equals itself, so a NaN sentinel re-set the colour on every
|
|
122
|
+
// render and had the whole configuration re-applied on every value change.
|
|
123
|
+
const processedColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(color) ?? Infinity, [color]);
|
|
124
|
+
const processedShimmerColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(shimmerColor) ?? Infinity, [shimmerColor]);
|
|
125
|
+
const processedFlashUp = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(flashUpColor) ?? Infinity, [flashUpColor]);
|
|
126
|
+
const processedFlashDown = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(flashDownColor) ?? Infinity, [flashDownColor]);
|
|
127
|
+
const numericWeight = (0, styleHelpers_1.toNumericWeight)(fontWeight) ?? 400;
|
|
128
|
+
const resolvedFontSize = fontSize ?? 32;
|
|
129
|
+
const resolvedAffixAlign = affixAlign ?? 'baseline';
|
|
130
|
+
const autoSize = (0, react_1.useMemo)(() => size !== null
|
|
131
|
+
? { width: size.width, height: size.height }
|
|
132
|
+
: { height: (fontSize ?? 32) * 1.25 }, [size, fontSize]);
|
|
133
|
+
// The layout direction, resolved the way React Native resolves it for its
|
|
134
|
+
// own views: the view's `style.direction` if it says, else the app's. Fabric
|
|
135
|
+
// does not hand a Hybrid View its resolved direction, so native is told.
|
|
136
|
+
const layoutDirection = (0, react_1.useMemo)(() => react_native_1.StyleSheet.flatten(style)?.direction, [style]);
|
|
137
|
+
const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && react_native_1.I18nManager.isRTL);
|
|
138
|
+
return (react_1.default.createElement(exports.NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: value, fractionDigits: fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? '.', prefix: prefix ?? '', suffix: suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
|
|
139
|
+
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NativeNitroNumberView = exports.NitroNumber = exports.useNitroInputState = exports.isWorklet = exports.NativeNitroInputView = exports.NitroInput = void 0;
|
|
4
4
|
var NitroInput_1 = require("./NitroInput");
|
|
5
5
|
Object.defineProperty(exports, "NitroInput", { enumerable: true, get: function () { return NitroInput_1.NitroInput; } });
|
|
6
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
7
|
var worklets_1 = require("./worklets");
|
|
10
8
|
Object.defineProperty(exports, "isWorklet", { enumerable: true, get: function () { return worklets_1.isWorklet; } });
|
|
11
9
|
var useNitroInputState_1 = require("./useNitroInputState");
|
|
12
10
|
Object.defineProperty(exports, "useNitroInputState", { enumerable: true, get: function () { return useNitroInputState_1.useNitroInputState; } });
|
|
11
|
+
var NitroNumber_1 = require("./NitroNumber");
|
|
12
|
+
Object.defineProperty(exports, "NitroNumber", { enumerable: true, get: function () { return NitroNumber_1.NitroNumber; } });
|
|
13
|
+
Object.defineProperty(exports, "NativeNitroNumberView", { enumerable: true, get: function () { return NitroNumber_1.NativeNitroNumberView; } });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toNumericWeight = toNumericWeight;
|
|
4
|
+
exports.toProcessedColor = toProcessedColor;
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
// Style resolution shared by `NitroNumber` and `NitroInput`.
|
|
7
|
+
const FONT_WEIGHTS = {
|
|
8
|
+
normal: 400,
|
|
9
|
+
regular: 400,
|
|
10
|
+
bold: 700,
|
|
11
|
+
ultralight: 100,
|
|
12
|
+
thin: 200,
|
|
13
|
+
light: 300,
|
|
14
|
+
medium: 500,
|
|
15
|
+
semibold: 600,
|
|
16
|
+
condensedBold: 700,
|
|
17
|
+
condensed: 400,
|
|
18
|
+
heavy: 800,
|
|
19
|
+
black: 900,
|
|
20
|
+
};
|
|
21
|
+
function toNumericWeight(weight) {
|
|
22
|
+
if (weight == null)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (typeof weight === 'number')
|
|
25
|
+
return weight;
|
|
26
|
+
const parsed = Number(weight);
|
|
27
|
+
if (!Number.isNaN(parsed))
|
|
28
|
+
return parsed;
|
|
29
|
+
return FONT_WEIGHTS[weight];
|
|
30
|
+
}
|
|
31
|
+
function toProcessedColor(color) {
|
|
32
|
+
if (color == null)
|
|
33
|
+
return undefined;
|
|
34
|
+
const processed = (0, react_native_1.processColor)(color);
|
|
35
|
+
return typeof processed === 'number' ? processed : undefined;
|
|
36
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"uiViewClassName": "NitroNumberView",
|
|
3
|
+
"supportsRawText": false,
|
|
4
|
+
"bubblingEventTypes": {},
|
|
5
|
+
"directEventTypes": {},
|
|
6
|
+
"validAttributes": {
|
|
7
|
+
"value": true,
|
|
8
|
+
"fractionDigits": true,
|
|
9
|
+
"minimumIntegerDigits": true,
|
|
10
|
+
"groupingSeparator": true,
|
|
11
|
+
"decimalSeparator": true,
|
|
12
|
+
"prefix": true,
|
|
13
|
+
"suffix": true,
|
|
14
|
+
"duration": true,
|
|
15
|
+
"easing": true,
|
|
16
|
+
"bounce": true,
|
|
17
|
+
"stagger": true,
|
|
18
|
+
"transition": true,
|
|
19
|
+
"flashUpColor": true,
|
|
20
|
+
"flashDownColor": true,
|
|
21
|
+
"flashDuration": true,
|
|
22
|
+
"popOnChange": true,
|
|
23
|
+
"rollDirection": true,
|
|
24
|
+
"revealState": true,
|
|
25
|
+
"revealStyle": true,
|
|
26
|
+
"revealDuration": true,
|
|
27
|
+
"revealBounce": true,
|
|
28
|
+
"revealGrow": true,
|
|
29
|
+
"revealStagger": true,
|
|
30
|
+
"revealMilestones": true,
|
|
31
|
+
"revealMilestoneHold": true,
|
|
32
|
+
"loading": true,
|
|
33
|
+
"shimmerColor": true,
|
|
34
|
+
"shimmerDuration": true,
|
|
35
|
+
"fontSize": true,
|
|
36
|
+
"prefixFontSize": true,
|
|
37
|
+
"suffixFontSize": true,
|
|
38
|
+
"affixAlign": true,
|
|
39
|
+
"prefixAlign": true,
|
|
40
|
+
"suffixAlign": true,
|
|
41
|
+
"adjustsFontSizeToFit": true,
|
|
42
|
+
"minimumFontScale": true,
|
|
43
|
+
"allowFontScaling": true,
|
|
44
|
+
"maxFontSizeMultiplier": true,
|
|
45
|
+
"fontWeight": true,
|
|
46
|
+
"fontFamily": true,
|
|
47
|
+
"color": true,
|
|
48
|
+
"textAlign": true,
|
|
49
|
+
"rightToLeft": true,
|
|
50
|
+
"onSizeChange": true,
|
|
51
|
+
"onRevealEnd": true,
|
|
52
|
+
"onRevealMilestone": true,
|
|
53
|
+
"hybridRef": true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
2
|
-
import { I18nManager,
|
|
2
|
+
import { I18nManager, StyleSheet, } from 'react-native';
|
|
3
3
|
import { callback, getHostComponent, } from 'react-native-nitro-modules';
|
|
4
4
|
import NitroInputViewConfig from '../nitrogen/generated/shared/json/NitroInputViewConfig.json';
|
|
5
5
|
import { allocateWorkletId, isWorklet, registerFocusChange, registerKeyPress, registerSelectionChange, registerTextEvent, registerCallback, registerTransform, unregisterWorklet, } from './worklets';
|
|
6
|
+
import { toNumericWeight, toProcessedColor } from './styleHelpers';
|
|
6
7
|
const textInputRegistry = (() => {
|
|
7
8
|
try {
|
|
8
9
|
// The registry has no public surface: `TextInput.State` exposes the focus
|
|
@@ -111,39 +112,6 @@ function patchRegistryOnce() {
|
|
|
111
112
|
* convenient handle.
|
|
112
113
|
*/
|
|
113
114
|
export const NativeNitroInputView = getHostComponent('NitroInputView', () => NitroInputViewConfig);
|
|
114
|
-
// shared-helpers:start
|
|
115
|
-
// Kept byte-for-byte identical with packages/react-native-nitro-rolling-number/src/RollingNumber.tsx
|
|
116
|
-
// (a test compares the two blocks); change both together.
|
|
117
|
-
const FONT_WEIGHTS = {
|
|
118
|
-
normal: 400,
|
|
119
|
-
regular: 400,
|
|
120
|
-
bold: 700,
|
|
121
|
-
ultralight: 100,
|
|
122
|
-
thin: 200,
|
|
123
|
-
light: 300,
|
|
124
|
-
medium: 500,
|
|
125
|
-
semibold: 600,
|
|
126
|
-
condensedBold: 700,
|
|
127
|
-
condensed: 400,
|
|
128
|
-
heavy: 800,
|
|
129
|
-
black: 900,
|
|
130
|
-
};
|
|
131
|
-
function toNumericWeight(weight) {
|
|
132
|
-
if (weight == null)
|
|
133
|
-
return undefined;
|
|
134
|
-
if (typeof weight === 'number')
|
|
135
|
-
return weight;
|
|
136
|
-
const parsed = Number(weight);
|
|
137
|
-
if (!Number.isNaN(parsed))
|
|
138
|
-
return parsed;
|
|
139
|
-
return FONT_WEIGHTS[weight];
|
|
140
|
-
}
|
|
141
|
-
function toProcessedColor(color) {
|
|
142
|
-
if (color == null)
|
|
143
|
-
return undefined;
|
|
144
|
-
const processed = processColor(color);
|
|
145
|
-
return typeof processed === 'number' ? processed : undefined;
|
|
146
|
-
}
|
|
147
115
|
const warnedIncompatible = new Set();
|
|
148
116
|
/** Once per offending prop, not once per render. */
|
|
149
117
|
function warnIncompatible(what) {
|
|
@@ -159,16 +127,16 @@ function warnIncompatible(what) {
|
|
|
159
127
|
* the keyboard, editing, selection, paste and accessibility, with native
|
|
160
128
|
* formatting (`mode="number"`), native masking (`mode="mask"`), an outlined
|
|
161
129
|
* or filled frame with a floating label, and optionally the glyph engine
|
|
162
|
-
* (`
|
|
130
|
+
* (`transition="reflow"`), under which characters that stay glide to their new place, new
|
|
163
131
|
* ones slide or fade in and removed ones leave alongside their neighbours.
|
|
164
132
|
* In `'number'` mode every edit is formatted on the native side before a
|
|
165
133
|
* frame is drawn, with the caret kept in place, so there is never an
|
|
166
134
|
* unformatted frame and never a round trip through JS.
|
|
167
135
|
*
|
|
168
|
-
* Like a `TextInput`, it takes its width from its parent; `autoWidth`
|
|
169
|
-
*
|
|
136
|
+
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
137
|
+
* it to its content instead, and is on by default when the text reflows.
|
|
170
138
|
*/
|
|
171
|
-
export const NitroInput = 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,
|
|
139
|
+
export const NitroInput = 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, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
172
140
|
const nativeRef = useRef(null);
|
|
173
141
|
// What React Native's registry stores for this field. The React host
|
|
174
142
|
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
@@ -286,7 +254,8 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
286
254
|
// `NitroInput` turns it off so flexbox gives it the parent's width, the
|
|
287
255
|
// way a `TextInput` gets one.
|
|
288
256
|
const inferredAutoWidth = flat?.width == null && flat?.flex == null;
|
|
289
|
-
const
|
|
257
|
+
const autoWidthSetting = autoWidthProp ?? (transition === 'reflow' && !multiline ? 'auto' : false);
|
|
258
|
+
const autoWidth = autoWidthSetting === 'auto' ? inferredAutoWidth : autoWidthSetting;
|
|
290
259
|
const autoWidthRef = useRef(autoWidth);
|
|
291
260
|
autoWidthRef.current = autoWidth;
|
|
292
261
|
// When the style pins both axes, the measured size is never used: `style`
|
|
@@ -452,15 +421,15 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
452
421
|
if (mode != null && mode !== 'text') {
|
|
453
422
|
warnIncompatible(`mode="${mode}"`);
|
|
454
423
|
}
|
|
455
|
-
if (
|
|
456
|
-
warnIncompatible('
|
|
424
|
+
if (transition === 'reflow')
|
|
425
|
+
warnIncompatible('transition="reflow"');
|
|
457
426
|
if (prefix)
|
|
458
427
|
warnIncompatible('prefix');
|
|
459
428
|
if (suffix)
|
|
460
429
|
warnIncompatible('suffix');
|
|
461
430
|
}
|
|
462
431
|
const resolvedMode = isMultiline ? 'text' : (mode ?? 'text');
|
|
463
|
-
const
|
|
432
|
+
const reflows = !isMultiline && transition === 'reflow';
|
|
464
433
|
// The affixes are accessory views beside one line of text; a wrapping text
|
|
465
434
|
// view has no slot for them, so they go with the mode rather than being
|
|
466
435
|
// half-drawn on one platform and not the other.
|
|
@@ -536,7 +505,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
536
505
|
? { width: size.width, height: size.height }
|
|
537
506
|
: { height: size.height }
|
|
538
507
|
: { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
|
|
539
|
-
return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !
|
|
508
|
+
return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? ',', 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 ??
|
|
540
509
|
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
541
510
|
// field's return key inserts a line break unless told to blur.
|
|
542
511
|
(multiline
|