react-native-nitro-input 0.3.1 → 0.3.2
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 +31 -0
- package/README.md +30 -3
- package/android/src/main/cpp/JMaskEngine.cpp +45 -0
- package/android/src/main/cpp/JMaskEngine.hpp +9 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/MaskEngine.kt +16 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +96 -6
- package/cpp/MaskEngine.cpp +294 -33
- package/cpp/MaskEngine.hpp +68 -0
- package/ios/HybridNitroInputView.swift +18 -0
- package/ios/NitroInputView.swift +125 -7
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
- package/lib/commonjs/src/NitroInput.js +15 -2
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
- package/lib/module/src/NitroInput.js +15 -2
- package/lib/typescript/src/NitroInput.d.ts +39 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +43 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +102 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +12 -0
- package/nitrogen/generated/android/c++/JNitroInputCharacterMapping.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputMaskAffinity.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroInputTextCase.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputCharacterMapping.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputMaskAffinity.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextCase.kt +24 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +25 -11
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +9 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +50 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +36 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +6 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +78 -0
- package/nitrogen/generated/ios/swift/NitroInputCharacterMapping.swift +34 -0
- package/nitrogen/generated/ios/swift/NitroInputMaskAffinity.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroInputTextCase.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +12 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +21 -0
- package/nitrogen/generated/shared/c++/NitroInputCharacterMapping.hpp +87 -0
- package/nitrogen/generated/shared/c++/NitroInputMaskAffinity.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroInputTextCase.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +12 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +21 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
- package/package.json +2 -2
- package/src/NitroInput.tsx +73 -0
- package/src/index.ts +3 -0
- package/src/specs/NitroInput.nitro.ts +46 -0
package/ios/NitroInputView.swift
CHANGED
|
@@ -44,6 +44,12 @@ final class NitroInputView: UIView {
|
|
|
44
44
|
var isOptional: Bool
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/// One character replaced by another before masking.
|
|
48
|
+
struct MaskMapping: Equatable {
|
|
49
|
+
var from: String
|
|
50
|
+
var to: String
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
struct Format: Equatable {
|
|
48
54
|
var mode: Mode = .text
|
|
49
55
|
/// Mask mode: the pattern, e.g. "+1 ([000]) [000]-[0000]".
|
|
@@ -51,6 +57,17 @@ final class NitroInputView: UIView {
|
|
|
51
57
|
var maskNotations: [MaskNotation] = []
|
|
52
58
|
var maskAutocomplete: Bool = true
|
|
53
59
|
var maskAutoSkip: Bool = false
|
|
60
|
+
/// Mask mode: alternative patterns and how the best is chosen (MaskEngine's
|
|
61
|
+
/// `kAffinity…` constants).
|
|
62
|
+
var maskAffinityFormats: [String] = []
|
|
63
|
+
var maskAffinityStrategy: Int = 0
|
|
64
|
+
/// Mask mode: MaskEngine's `kTextCase…` constants.
|
|
65
|
+
var maskTextCase: Int = 0
|
|
66
|
+
var maskCharacterMap: [MaskMapping] = []
|
|
67
|
+
/// Mask mode: what an empty slot shows in the tail; empty = its notation.
|
|
68
|
+
var maskSlotPlaceholder: String = ""
|
|
69
|
+
/// Mask mode: keep the rest of the placeholder after the typed text.
|
|
70
|
+
var keepPlaceholder: Bool = false
|
|
54
71
|
var fractionDigits: Int = 2
|
|
55
72
|
var maxIntegerDigits: Int = 15
|
|
56
73
|
var groupingSeparator: String = ","
|
|
@@ -755,6 +772,7 @@ final class NitroInputView: UIView {
|
|
|
755
772
|
}
|
|
756
773
|
field.frame = bounds
|
|
757
774
|
if didBuildTextView { textView.frame = bounds }
|
|
775
|
+
updateGhostLabel()
|
|
758
776
|
// Where the text wraps - and so how tall the box is - depends on the width,
|
|
759
777
|
// and layout is the first thing to know it. Measuring from inside the pass
|
|
760
778
|
// would re-enter it, so the report goes out after this one lands.
|
|
@@ -997,13 +1015,28 @@ final class NitroInputView: UIView {
|
|
|
997
1015
|
formatter.setFormat(Int32(max(0, format.fractionDigits)), Int32(max(1, format.maxIntegerDigits)),
|
|
998
1016
|
std.string(format.groupingSeparator), std.string(format.decimalSeparator))
|
|
999
1017
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1018
|
+
let maskChanged = format.mask != previous.mask || format.maskNotations != previous.maskNotations
|
|
1019
|
+
|| format.maskAffinityFormats != previous.maskAffinityFormats
|
|
1020
|
+
|| format.maskAffinityStrategy != previous.maskAffinityStrategy
|
|
1021
|
+
|| format.maskTextCase != previous.maskTextCase || format.maskCharacterMap != previous.maskCharacterMap
|
|
1022
|
+
|| format.maskSlotPlaceholder != previous.maskSlotPlaceholder
|
|
1023
|
+
if format.mode == .mask, maskChanged || previous.mode != .mask {
|
|
1002
1024
|
maskEngine.clearNotations()
|
|
1003
1025
|
for notation in format.maskNotations {
|
|
1004
1026
|
maskEngine.addNotation(std.string(notation.character), std.string(notation.characterSet),
|
|
1005
1027
|
notation.isOptional)
|
|
1006
1028
|
}
|
|
1029
|
+
maskEngine.clearAffinityFormats()
|
|
1030
|
+
for alternative in format.maskAffinityFormats {
|
|
1031
|
+
maskEngine.addAffinityFormat(std.string(alternative))
|
|
1032
|
+
}
|
|
1033
|
+
maskEngine.setAffinityStrategy(Int32(format.maskAffinityStrategy))
|
|
1034
|
+
maskEngine.setTextCase(Int32(format.maskTextCase))
|
|
1035
|
+
maskEngine.clearCharacterMap()
|
|
1036
|
+
for mapping in format.maskCharacterMap {
|
|
1037
|
+
maskEngine.addCharacterMapping(std.string(mapping.from), std.string(mapping.to))
|
|
1038
|
+
}
|
|
1039
|
+
maskEngine.setSlotPlaceholder(std.string(format.maskSlotPlaceholder))
|
|
1007
1040
|
// A bad pattern leaves the engine inactive; the field then behaves as
|
|
1008
1041
|
// plain text rather than refusing every keystroke.
|
|
1009
1042
|
_ = maskEngine.setFormat(std.string(format.mask))
|
|
@@ -1014,18 +1047,26 @@ final class NitroInputView: UIView {
|
|
|
1014
1047
|
let formatChanged = format.mode != previous.mode || format.fractionDigits != previous.fractionDigits
|
|
1015
1048
|
|| format.maxIntegerDigits != previous.maxIntegerDigits || format.groupingSeparator != previous.groupingSeparator
|
|
1016
1049
|
|| format.decimalSeparator != previous.decimalSeparator || format.maxLength != previous.maxLength
|
|
1017
|
-
||
|
|
1050
|
+
|| maskChanged
|
|
1051
|
+
var reformatted = false
|
|
1018
1052
|
if formatChanged {
|
|
1019
1053
|
let normalizedText = normalized(text)
|
|
1020
1054
|
if normalizedText != text {
|
|
1021
1055
|
isSettingText = true
|
|
1022
1056
|
field.text = normalizedText
|
|
1023
1057
|
isSettingText = false
|
|
1058
|
+
reformatted = true
|
|
1024
1059
|
}
|
|
1025
1060
|
}
|
|
1026
1061
|
applyKeyboardTraitsForMode()
|
|
1027
|
-
|
|
1028
|
-
|
|
1062
|
+
if reformatted {
|
|
1063
|
+
// The text itself changed ("123-456" is "12 34 56" under a new mask), so
|
|
1064
|
+
// it is reported like `setText`, as Android does: without that, JS -
|
|
1065
|
+
// getText(), onChangeText, onChangeMask and a controlled parent - kept
|
|
1066
|
+
// the old text while the field showed the new one.
|
|
1067
|
+
textDidChange(caret: text.unicodeScalars.count, reason: .method)
|
|
1068
|
+
} else if engine.hasText() || traits.plain {
|
|
1069
|
+
// A plain field has nothing in the engine and still has a width to report.
|
|
1029
1070
|
feedEngine(caret: -1)
|
|
1030
1071
|
}
|
|
1031
1072
|
}
|
|
@@ -1400,6 +1441,7 @@ final class NitroInputView: UIView {
|
|
|
1400
1441
|
// Plain mode has no overlay to feed: the field draws its own text. Its
|
|
1401
1442
|
// width still has to reach React for `autoWidth`, and this is the one
|
|
1402
1443
|
// place every text, font, affix and placeholder change comes through.
|
|
1444
|
+
updateGhostLabel()
|
|
1403
1445
|
guard !traits.plain else { reportIntrinsicSize(); return }
|
|
1404
1446
|
engine.setReduceMotion(UIAccessibility.isReduceMotionEnabled)
|
|
1405
1447
|
engine.beginText()
|
|
@@ -1441,6 +1483,14 @@ final class NitroInputView: UIView {
|
|
|
1441
1483
|
let after = hasSuffix && i == rest.count - 1 ? (fonts.suffixSeam ?? fonts.bodySpacing) : fonts.bodySpacing
|
|
1442
1484
|
engine.addGlyph(scalar.value, Role.body, kind, Double(fonts.width(of: String(scalar), role: .body) + after), showPlaceholder)
|
|
1443
1485
|
}
|
|
1486
|
+
// `keepPlaceholder`: the rest of the mask trails the text as placeholder
|
|
1487
|
+
// glyphs. They come after every typed glyph, so the caret - which counts
|
|
1488
|
+
// body glyphs in order - never lands among them.
|
|
1489
|
+
if !showPlaceholder {
|
|
1490
|
+
for scalar in ghostTail.unicodeScalars {
|
|
1491
|
+
engine.addGlyph(scalar.value, Role.body, Kind.text, Double(fonts.width(of: String(scalar), role: .body) + fonts.bodySpacing), true)
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1444
1494
|
for scalar in format.suffix.unicodeScalars {
|
|
1445
1495
|
engine.addGlyph(scalar.value, Role.suffix, Kind.text, Double(fonts.width(of: String(scalar), role: .suffix) + fonts.suffixLetterSpacing), false)
|
|
1446
1496
|
}
|
|
@@ -1625,11 +1675,49 @@ final class NitroInputView: UIView {
|
|
|
1625
1675
|
/// The width the content asks for: the engine's layout in reflow mode; in
|
|
1626
1676
|
/// plain mode, which never feeds the engine, the text (or the placeholder)
|
|
1627
1677
|
/// and the affixes measured with the same fonts the field draws them in.
|
|
1678
|
+
/// Plain mode has no overlay to draw `keepPlaceholder`'s tail, so it is a
|
|
1679
|
+
/// label pinned inside the field to where the field's own text ends, in the
|
|
1680
|
+
/// same font and kerning and the placeholder colour.
|
|
1681
|
+
private lazy var ghostLabel: UILabel = {
|
|
1682
|
+
let label = UILabel()
|
|
1683
|
+
label.isUserInteractionEnabled = false
|
|
1684
|
+
label.isAccessibilityElement = false
|
|
1685
|
+
label.lineBreakMode = .byClipping
|
|
1686
|
+
return label
|
|
1687
|
+
}()
|
|
1688
|
+
|
|
1689
|
+
private func updateGhostLabel() {
|
|
1690
|
+
let tail = traits.plain ? ghostTail : ""
|
|
1691
|
+
guard !tail.isEmpty, !isRTL else {
|
|
1692
|
+
if ghostLabel.superview != nil { ghostLabel.isHidden = true }
|
|
1693
|
+
return
|
|
1694
|
+
}
|
|
1695
|
+
if ghostLabel.superview !== field { field.addSubview(ghostLabel) }
|
|
1696
|
+
var attributes = field.defaultTextAttributes
|
|
1697
|
+
attributes[.foregroundColor] = typography.placeholderColor.resolvedColor(with: traitCollection)
|
|
1698
|
+
ghostLabel.attributedText = NSAttributedString(string: tail, attributes: attributes)
|
|
1699
|
+
let box = field.textRect(forBounds: field.bounds)
|
|
1700
|
+
let typed = fonts.width(of: text, role: .body) + fonts.bodySpacing * CGFloat(text.unicodeScalars.count)
|
|
1701
|
+
let tailWidth = fonts.width(of: tail, role: .body) + fonts.bodySpacing * CGFloat(tail.unicodeScalars.count)
|
|
1702
|
+
// Where UIKit starts the text: the box's leading edge, or centred / right
|
|
1703
|
+
// aligned without the tail - the tail then trails off the typed text.
|
|
1704
|
+
let start: CGFloat
|
|
1705
|
+
switch field.textAlignment {
|
|
1706
|
+
case .center: start = box.midX - typed / 2
|
|
1707
|
+
case .right: start = box.maxX - typed
|
|
1708
|
+
default: start = box.minX
|
|
1709
|
+
}
|
|
1710
|
+
let end = start + typed
|
|
1711
|
+
// Text wider than the box scrolls inside the field; the tail has no place then.
|
|
1712
|
+
ghostLabel.isHidden = typed > box.width
|
|
1713
|
+
ghostLabel.frame = CGRect(x: end, y: box.minY, width: min(tailWidth + 1, max(0, box.maxX - end)), height: box.height)
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1628
1716
|
private func contentWidth() -> CGFloat {
|
|
1629
1717
|
guard traits.plain else { return CGFloat(engine.targetWidth()) }
|
|
1630
1718
|
let body = text.isEmpty
|
|
1631
1719
|
? effectivePlaceholder
|
|
1632
|
-
: traits.secureTextEntry ? String(repeating: "\u{2022}", count: text.unicodeScalars.count) : text
|
|
1720
|
+
: traits.secureTextEntry ? String(repeating: "\u{2022}", count: text.unicodeScalars.count) : text + ghostTail
|
|
1633
1721
|
// The field's own kerning follows every glyph; the affixes take their room with their seams.
|
|
1634
1722
|
return fonts.affixRoom(format.prefix, role: .prefix)
|
|
1635
1723
|
+ fonts.width(of: body, role: .body) + fonts.bodySpacing * CGFloat(body.unicodeScalars.count)
|
|
@@ -2368,10 +2456,40 @@ extension NitroInputView {
|
|
|
2368
2456
|
/// A label resting inside the field already labels it, so the placeholder
|
|
2369
2457
|
/// waits until the label has floated clear rather than printing over it.
|
|
2370
2458
|
var effectivePlaceholder: String {
|
|
2371
|
-
guard inputFrame.hasLabel, !labelShouldFloat else { return
|
|
2459
|
+
guard inputFrame.hasLabel, !labelShouldFloat else { return basePlaceholder }
|
|
2372
2460
|
return ""
|
|
2373
2461
|
}
|
|
2374
2462
|
|
|
2463
|
+
/// `keepPlaceholder` without a `placeholder` shows the mask itself, empty
|
|
2464
|
+
/// slots as `maskSlotPlaceholder`: "+1 (___) ___-____".
|
|
2465
|
+
private var basePlaceholder: String {
|
|
2466
|
+
if format.placeholder.isEmpty, format.mode == .mask, format.keepPlaceholder, maskEngine.isActive() {
|
|
2467
|
+
return String(maskEngine.apply(std.string(""), 0, true, false, false).tailPlaceholder)
|
|
2468
|
+
}
|
|
2469
|
+
return format.placeholder
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
/// `keepPlaceholder`: what is still to come after the typed text, drawn in
|
|
2473
|
+
/// the placeholder colour. The caller's placeholder from where the text ends
|
|
2474
|
+
/// - "1234 5" leaves "678 9012" of "1234 5678 9012" - or, without one, the
|
|
2475
|
+
/// rest of the mask. The placeholder is written for `mask`, so when one of
|
|
2476
|
+
/// `maskAffinityFormats` has taken over (a 4-6-5 Amex under a 4-4-4-4
|
|
2477
|
+
/// placeholder) its characters no longer line up, and that format's own
|
|
2478
|
+
/// tail is shown instead. A complete text has nothing to come.
|
|
2479
|
+
var ghostTail: String {
|
|
2480
|
+
guard format.mode == .mask, format.keepPlaceholder, !text.isEmpty, !traits.secureTextEntry,
|
|
2481
|
+
maskEngine.isActive() else { return "" }
|
|
2482
|
+
let typed = text.unicodeScalars.count
|
|
2483
|
+
let result = maskEngine.apply(std.string(text), Int32(typed), true, false, false)
|
|
2484
|
+
if result.complete { return "" }
|
|
2485
|
+
let placeholder = Array(format.placeholder.unicodeScalars)
|
|
2486
|
+
if placeholder.isEmpty || result.formatIndex != 0 { return String(result.tailPlaceholder) }
|
|
2487
|
+
guard typed < placeholder.count else { return "" }
|
|
2488
|
+
var rest = String.UnicodeScalarView()
|
|
2489
|
+
rest.append(contentsOf: placeholder[typed...])
|
|
2490
|
+
return String(rest)
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2375
2493
|
/// The label floats once the field is focused or holds text - or always, if
|
|
2376
2494
|
/// the caller asked for that.
|
|
2377
2495
|
private var labelShouldFloat: Bool {
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
"maskNotations": true,
|
|
15
15
|
"maskAutocomplete": true,
|
|
16
16
|
"maskAutoSkip": true,
|
|
17
|
+
"maskAffinityFormats": true,
|
|
18
|
+
"maskAffinityStrategy": true,
|
|
19
|
+
"maskTextCase": true,
|
|
20
|
+
"maskCharacterMap": true,
|
|
21
|
+
"maskSlotPlaceholder": true,
|
|
22
|
+
"keepPlaceholder": true,
|
|
17
23
|
"groupingSeparator": true,
|
|
18
24
|
"decimalSeparator": true,
|
|
19
25
|
"variant": true,
|
|
@@ -103,6 +103,8 @@ function reactTagOf(host) {
|
|
|
103
103
|
return typeof tag === 'number' ? tag : 0;
|
|
104
104
|
}
|
|
105
105
|
const EMPTY_NOTATIONS = [];
|
|
106
|
+
const EMPTY_STRINGS = [];
|
|
107
|
+
const EMPTY_MAPPINGS = [];
|
|
106
108
|
/** Mounted fields, by the host instance React Native's registry stores. */
|
|
107
109
|
const mountedFields = new WeakMap();
|
|
108
110
|
let patchedRegistry = false;
|
|
@@ -176,7 +178,7 @@ function warnIncompatible(what) {
|
|
|
176
178
|
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
177
179
|
* it to its content instead, and is on by default when the text reflows.
|
|
178
180
|
*/
|
|
179
|
-
exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, 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) {
|
|
181
|
+
exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, 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, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, 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) {
|
|
180
182
|
const nativeRef = (0, react_1.useRef)(null);
|
|
181
183
|
// What React Native's registry stores for this field. The React host
|
|
182
184
|
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
@@ -484,6 +486,17 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
484
486
|
const stableNotations = (0, react_1.useMemo)(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
|
|
485
487
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
486
488
|
[notationsKey]);
|
|
489
|
+
// The same for the affinity formats and the character map.
|
|
490
|
+
const affinityKey = maskAffinityFormats != null && maskAffinityFormats.length > 0 ? JSON.stringify(maskAffinityFormats) : '';
|
|
491
|
+
const stableAffinityFormats = (0, react_1.useMemo)(() => (affinityKey !== '' && maskAffinityFormats ? [...maskAffinityFormats] : EMPTY_STRINGS),
|
|
492
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
493
|
+
[affinityKey]);
|
|
494
|
+
const characterMapKey = maskCharacterMap != null && Object.keys(maskCharacterMap).length > 0 ? JSON.stringify(maskCharacterMap) : '';
|
|
495
|
+
const stableCharacterMap = (0, react_1.useMemo)(() => characterMapKey !== '' && maskCharacterMap
|
|
496
|
+
? Object.entries(maskCharacterMap).map(([from, to]) => ({ from, to }))
|
|
497
|
+
: EMPTY_MAPPINGS,
|
|
498
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
499
|
+
[characterMapKey]);
|
|
487
500
|
const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
|
|
488
501
|
const resolvedKeyboardType = keyboardType ??
|
|
489
502
|
(inputMode != null
|
|
@@ -546,7 +559,7 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
546
559
|
? { width: size.width, height: size.height }
|
|
547
560
|
: { height: size.height }
|
|
548
561
|
: { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
|
|
549
|
-
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 ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, 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 ??
|
|
562
|
+
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 ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, 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, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? 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 ??
|
|
550
563
|
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
551
564
|
// field's return key inserts a line break unless told to blur.
|
|
552
565
|
(multiline
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
"maskNotations": true,
|
|
15
15
|
"maskAutocomplete": true,
|
|
16
16
|
"maskAutoSkip": true,
|
|
17
|
+
"maskAffinityFormats": true,
|
|
18
|
+
"maskAffinityStrategy": true,
|
|
19
|
+
"maskTextCase": true,
|
|
20
|
+
"maskCharacterMap": true,
|
|
21
|
+
"maskSlotPlaceholder": true,
|
|
22
|
+
"keepPlaceholder": true,
|
|
17
23
|
"groupingSeparator": true,
|
|
18
24
|
"decimalSeparator": true,
|
|
19
25
|
"variant": true,
|
|
@@ -64,6 +64,8 @@ function reactTagOf(host) {
|
|
|
64
64
|
return typeof tag === 'number' ? tag : 0;
|
|
65
65
|
}
|
|
66
66
|
const EMPTY_NOTATIONS = [];
|
|
67
|
+
const EMPTY_STRINGS = [];
|
|
68
|
+
const EMPTY_MAPPINGS = [];
|
|
67
69
|
/** Mounted fields, by the host instance React Native's registry stores. */
|
|
68
70
|
const mountedFields = new WeakMap();
|
|
69
71
|
let patchedRegistry = false;
|
|
@@ -137,7 +139,7 @@ function warnIncompatible(what) {
|
|
|
137
139
|
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
138
140
|
* it to its content instead, and is on by default when the text reflows.
|
|
139
141
|
*/
|
|
140
|
-
export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, 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) {
|
|
142
|
+
export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, 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, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, 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) {
|
|
141
143
|
const nativeRef = useRef(null);
|
|
142
144
|
// What React Native's registry stores for this field. The React host
|
|
143
145
|
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
@@ -445,6 +447,17 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
445
447
|
const stableNotations = useMemo(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
|
|
446
448
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
447
449
|
[notationsKey]);
|
|
450
|
+
// The same for the affinity formats and the character map.
|
|
451
|
+
const affinityKey = maskAffinityFormats != null && maskAffinityFormats.length > 0 ? JSON.stringify(maskAffinityFormats) : '';
|
|
452
|
+
const stableAffinityFormats = useMemo(() => (affinityKey !== '' && maskAffinityFormats ? [...maskAffinityFormats] : EMPTY_STRINGS),
|
|
453
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
454
|
+
[affinityKey]);
|
|
455
|
+
const characterMapKey = maskCharacterMap != null && Object.keys(maskCharacterMap).length > 0 ? JSON.stringify(maskCharacterMap) : '';
|
|
456
|
+
const stableCharacterMap = useMemo(() => characterMapKey !== '' && maskCharacterMap
|
|
457
|
+
? Object.entries(maskCharacterMap).map(([from, to]) => ({ from, to }))
|
|
458
|
+
: EMPTY_MAPPINGS,
|
|
459
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
460
|
+
[characterMapKey]);
|
|
448
461
|
const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
|
|
449
462
|
const resolvedKeyboardType = keyboardType ??
|
|
450
463
|
(inputMode != null
|
|
@@ -507,7 +520,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
507
520
|
? { width: size.width, height: size.height }
|
|
508
521
|
: { height: size.height }
|
|
509
522
|
: { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
|
|
510
|
-
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 ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, 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 ??
|
|
523
|
+
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 ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, 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, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? 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 ??
|
|
511
524
|
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
512
525
|
// field's return key inserts a line break unless told to blur.
|
|
513
526
|
(multiline
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type ColorValue, type TextStyle, type ViewProps } from 'react-native';
|
|
3
3
|
import { type HybridRef } from 'react-native-nitro-modules';
|
|
4
|
-
import type { NitroInputAffixAlign, NitroInputAutoCapitalize, NitroInputEasing, NitroInputEffect, NitroInputKeyboardAppearance, NitroInputKeyboardType, NitroInputLabelBehavior, NitroInputMethods, NitroInputMode, NitroInputProps as NativeNitroInputProps, NitroInputReturnKeyType, NitroInputSubmitBehavior, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputSignPlacement, NitroInputVariant, NitroInputNotation } from './specs/NitroInput.nitro';
|
|
4
|
+
import type { NitroInputAffixAlign, NitroInputAutoCapitalize, NitroInputEasing, NitroInputEffect, NitroInputKeyboardAppearance, NitroInputKeyboardType, NitroInputLabelBehavior, NitroInputMethods, NitroInputMode, NitroInputProps as NativeNitroInputProps, NitroInputReturnKeyType, NitroInputSubmitBehavior, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputSignPlacement, NitroInputVariant, NitroInputNotation, NitroInputMaskAffinity, NitroInputTextCase } from './specs/NitroInput.nitro';
|
|
5
5
|
import { type NitroInputSelection, type NitroInputTransform } from './worklets';
|
|
6
6
|
import type { NumberFormat } from './NumberFormat';
|
|
7
7
|
/** React Native's `inputMode`, the HTML-aligned alias for `keyboardType`. */
|
|
@@ -136,6 +136,44 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
|
|
|
136
136
|
maskAutocomplete?: boolean;
|
|
137
137
|
/** `'mask'`: backspace walks back over autocompleted constants. Default: `false`. */
|
|
138
138
|
maskAutoSkip?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* `'mask'`: more patterns the text may take, e.g. a 4-6-5 Amex card beside
|
|
141
|
+
* a 4-4-4-4 `mask`: `['{34}[00] [000000] [00000]', '{37}[00] [000000] [00000]']`.
|
|
142
|
+
* Every edit is masked with each and the best, by `maskAffinityStrategy`, is
|
|
143
|
+
* kept; `mask` wins ties.
|
|
144
|
+
*/
|
|
145
|
+
maskAffinityFormats?: string[];
|
|
146
|
+
/**
|
|
147
|
+
* `'mask'`: how the best of `maskAffinityFormats` is chosen. `'wholeString'`
|
|
148
|
+
* the format that accepts the most characters and inserts the fewest,
|
|
149
|
+
* `'prefix'` the one whose output starts most like what was typed,
|
|
150
|
+
* `'capacity'` / `'extractedValueCapacity'` the fullest format that still
|
|
151
|
+
* holds all of the text / all of its value characters. Default: `'wholeString'`.
|
|
152
|
+
*/
|
|
153
|
+
maskAffinityStrategy?: NitroInputMaskAffinity;
|
|
154
|
+
/** `'mask'`: uppercases or lowercases letters as they are typed or pasted. Default: `'none'`. */
|
|
155
|
+
maskTextCase?: NitroInputTextCase;
|
|
156
|
+
/**
|
|
157
|
+
* `'mask'`: characters replaced before masking, one character each:
|
|
158
|
+
* `{ 'С': 'C' }` turns a Cyrillic look-alike into a Latin letter,
|
|
159
|
+
* `{ ',': '.' }` lets a comma through to a dot-decimal mask. An empty
|
|
160
|
+
* replacement drops the character.
|
|
161
|
+
*/
|
|
162
|
+
maskCharacterMap?: Record<string, string>;
|
|
163
|
+
/**
|
|
164
|
+
* `'mask'`: the character each empty slot shows in the kept placeholder and
|
|
165
|
+
* in `onChangeMask`'s tail. Default: `'_'` with `keepPlaceholder`, otherwise
|
|
166
|
+
* the slot's own notation character.
|
|
167
|
+
*/
|
|
168
|
+
maskSlotPlaceholder?: string;
|
|
169
|
+
/**
|
|
170
|
+
* `'mask'`: keeps the rest of the placeholder visible after what has been
|
|
171
|
+
* typed: with `placeholder="1234 5678 9012"`, typing "12345" shows
|
|
172
|
+
* "1234 5" and then "678 9012" greyed. Without a `placeholder` the mask
|
|
173
|
+
* itself is shown, its empty slots as `maskSlotPlaceholder`:
|
|
174
|
+
* `+1 (212) ___-____`. Default: `false`.
|
|
175
|
+
*/
|
|
176
|
+
keepPlaceholder?: boolean;
|
|
139
177
|
/**
|
|
140
178
|
* `'mask'` mode: called whenever the text changes, from a keystroke,
|
|
141
179
|
* `setText` / `clear` or the `value` prop alike, with the masked text, the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { NitroInput, NativeNitroInputView, type NitroInputProps, type NitroInputHandle, type NitroInputRef, type NitroInputTextEvent, type NitroInputFocusEvent, type NitroInputSelectionEvent, type NitroInputKeyPressEvent, type NitroInputTransition, type InputMode, type EnterKeyHint, } from './NitroInput';
|
|
2
2
|
export { isWorklet, type NitroInputSelection, type NitroInputTransform, type WorkletTextEvent, type WorkletFocusEvent, type WorkletSelectionEvent, type WorkletKeyPressEvent, } from './worklets';
|
|
3
3
|
export { useNitroInputState, type NitroInputState, type SharedValueLike, } from './useNitroInputState';
|
|
4
|
-
export type { NitroInputLabelBehavior, NitroInputMode, NitroInputNotation, NitroInputVariant, NitroInputEasing, NitroInputEffect, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputAffixAlign, NitroInputSignPlacement, NitroInputKeyboardType, NitroInputReturnKeyType, NitroInputAutoCapitalize, NitroInputSubmitBehavior, NitroInputKeyboardAppearance, NitroInputMethods, NitroInputProps as NativeNitroInputProps, NitroInputView, } from './specs/NitroInput.nitro';
|
|
4
|
+
export type { NitroInputLabelBehavior, NitroInputMode, NitroInputNotation, NitroInputMaskAffinity, NitroInputTextCase, NitroInputCharacterMapping, NitroInputVariant, NitroInputEasing, NitroInputEffect, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputAffixAlign, NitroInputSignPlacement, NitroInputKeyboardType, NitroInputReturnKeyType, NitroInputAutoCapitalize, NitroInputSubmitBehavior, NitroInputKeyboardAppearance, NitroInputMethods, NitroInputProps as NativeNitroInputProps, NitroInputView, } from './specs/NitroInput.nitro';
|
|
5
5
|
export type { NitroInputWorklets } from './specs/NitroInputWorklets.nitro';
|
|
6
6
|
export { NitroNumber, NativeNitroNumberView, type NitroNumberProps, type NitroNumberHandle, type NitroNumberRef, } from './NitroNumber';
|
|
7
7
|
export { NitroTime, type NitroTimeProps, type NitroTimeFormat } from './NitroTime';
|
|
@@ -5,6 +5,21 @@ import type { HybridView, HybridViewMethods, HybridViewProps } from 'react-nativ
|
|
|
5
5
|
* `'text'` is a plain single-line field.
|
|
6
6
|
*/
|
|
7
7
|
export type NitroInputMode = 'text' | 'number' | 'mask';
|
|
8
|
+
/**
|
|
9
|
+
* How the best of `maskAffinityFormats` is chosen for the text in the field:
|
|
10
|
+
* `'wholeString'` the format that accepts the most characters and inserts the
|
|
11
|
+
* fewest, `'prefix'` the one whose output starts most like what was typed,
|
|
12
|
+
* `'capacity'` / `'extractedValueCapacity'` the fullest format that still
|
|
13
|
+
* holds all of the text / all of its value characters.
|
|
14
|
+
*/
|
|
15
|
+
export type NitroInputMaskAffinity = 'wholeString' | 'prefix' | 'capacity' | 'extractedValueCapacity';
|
|
16
|
+
/** How letters are cased as they are typed into a mask. */
|
|
17
|
+
export type NitroInputTextCase = 'none' | 'upper' | 'lower';
|
|
18
|
+
/** One character replaced by another before masking; an empty `to` drops it. */
|
|
19
|
+
export interface NitroInputCharacterMapping {
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
}
|
|
8
23
|
/**
|
|
9
24
|
* A caller-defined slot character for `mask`, beyond the built-in
|
|
10
25
|
* `0 9 A a _ - …`. `characterSet` lists every character the slot accepts.
|
|
@@ -131,6 +146,34 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
131
146
|
* Default: `false`.
|
|
132
147
|
*/
|
|
133
148
|
maskAutoSkip: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* `'mask'`: more patterns the text may take, e.g. a 4-6-5 Amex card beside
|
|
151
|
+
* a 4-4-4-4 `mask`. Every edit is masked with each and the best, by
|
|
152
|
+
* `maskAffinityStrategy`, is kept; `mask` wins ties. Default: none.
|
|
153
|
+
*/
|
|
154
|
+
maskAffinityFormats: string[];
|
|
155
|
+
/** `'mask'`: how the best of `maskAffinityFormats` is chosen. Default: `'wholeString'`. */
|
|
156
|
+
maskAffinityStrategy: NitroInputMaskAffinity;
|
|
157
|
+
/** `'mask'`: uppercases or lowercases letters as they are typed or pasted. Default: `'none'`. */
|
|
158
|
+
maskTextCase: NitroInputTextCase;
|
|
159
|
+
/**
|
|
160
|
+
* `'mask'`: characters replaced before masking, e.g. a Cyrillic "С" with a
|
|
161
|
+
* Latin "C", or "," with "." for a decimal mask. Default: none.
|
|
162
|
+
*/
|
|
163
|
+
maskCharacterMap: NitroInputCharacterMapping[];
|
|
164
|
+
/**
|
|
165
|
+
* `'mask'`: the character each empty slot shows in the kept placeholder and
|
|
166
|
+
* in `onChangeMask`'s tail, e.g. `'_'`. Empty: the slot's own notation
|
|
167
|
+
* character. Default: `''`.
|
|
168
|
+
*/
|
|
169
|
+
maskSlotPlaceholder: string;
|
|
170
|
+
/**
|
|
171
|
+
* `'mask'`: keeps the rest of the placeholder visible after what has been
|
|
172
|
+
* typed, so "1234 5" shows "678 9012" greyed after it. Without a
|
|
173
|
+
* `placeholder`, the mask itself is shown, empty slots as
|
|
174
|
+
* `maskSlotPlaceholder`: `+1 (212) ___-____`. Default: `false`.
|
|
175
|
+
*/
|
|
176
|
+
keepPlaceholder: boolean;
|
|
134
177
|
/** `'number'`: inserted between every three integer digits; empty disables grouping. Default: `','`. */
|
|
135
178
|
groupingSeparator: string;
|
|
136
179
|
/** `'number'`: between the integer and fraction digits. Default: `'.'`. */
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
namespace margelo::nitro::nitroinput { enum class NitroInputMode; }
|
|
12
12
|
// Forward declaration of `NitroInputNotation` to properly resolve imports.
|
|
13
13
|
namespace margelo::nitro::nitroinput { struct NitroInputNotation; }
|
|
14
|
+
// Forward declaration of `NitroInputMaskAffinity` to properly resolve imports.
|
|
15
|
+
namespace margelo::nitro::nitroinput { enum class NitroInputMaskAffinity; }
|
|
16
|
+
// Forward declaration of `NitroInputTextCase` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitroinput { enum class NitroInputTextCase; }
|
|
18
|
+
// Forward declaration of `NitroInputCharacterMapping` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::nitroinput { struct NitroInputCharacterMapping; }
|
|
14
20
|
// Forward declaration of `NitroInputVariant` to properly resolve imports.
|
|
15
21
|
namespace margelo::nitro::nitroinput { enum class NitroInputVariant; }
|
|
16
22
|
// Forward declaration of `NitroInputLabelBehavior` to properly resolve imports.
|
|
@@ -44,6 +50,12 @@ namespace margelo::nitro::nitroinput { enum class NitroInputKeyboardAppearance;
|
|
|
44
50
|
#include "NitroInputNotation.hpp"
|
|
45
51
|
#include <vector>
|
|
46
52
|
#include "JNitroInputNotation.hpp"
|
|
53
|
+
#include "NitroInputMaskAffinity.hpp"
|
|
54
|
+
#include "JNitroInputMaskAffinity.hpp"
|
|
55
|
+
#include "NitroInputTextCase.hpp"
|
|
56
|
+
#include "JNitroInputTextCase.hpp"
|
|
57
|
+
#include "NitroInputCharacterMapping.hpp"
|
|
58
|
+
#include "JNitroInputCharacterMapping.hpp"
|
|
47
59
|
#include "NitroInputVariant.hpp"
|
|
48
60
|
#include "JNitroInputVariant.hpp"
|
|
49
61
|
#include "NitroInputLabelBehavior.hpp"
|
|
@@ -218,6 +230,96 @@ namespace margelo::nitro::nitroinput {
|
|
|
218
230
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* maskAutoSkip */)>("setMaskAutoSkip");
|
|
219
231
|
method(_javaPart, maskAutoSkip);
|
|
220
232
|
}
|
|
233
|
+
std::vector<std::string> JHybridNitroInputViewSpec::getMaskAffinityFormats() {
|
|
234
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<jni::JString>>()>("getMaskAffinityFormats");
|
|
235
|
+
auto __result = method(_javaPart);
|
|
236
|
+
return [&](auto&& __input) {
|
|
237
|
+
size_t __size = __input->size();
|
|
238
|
+
std::vector<std::string> __vector;
|
|
239
|
+
__vector.reserve(__size);
|
|
240
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
241
|
+
auto __element = __input->getElement(__i);
|
|
242
|
+
__vector.push_back(__element->toStdString());
|
|
243
|
+
}
|
|
244
|
+
return __vector;
|
|
245
|
+
}(__result);
|
|
246
|
+
}
|
|
247
|
+
void JHybridNitroInputViewSpec::setMaskAffinityFormats(const std::vector<std::string>& maskAffinityFormats) {
|
|
248
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<jni::JString>> /* maskAffinityFormats */)>("setMaskAffinityFormats");
|
|
249
|
+
method(_javaPart, [&](auto&& __input) {
|
|
250
|
+
size_t __size = __input.size();
|
|
251
|
+
jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
|
|
252
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
253
|
+
const auto& __element = __input[__i];
|
|
254
|
+
auto __elementJni = jni::make_jstring(__element);
|
|
255
|
+
__array->setElement(__i, *__elementJni);
|
|
256
|
+
}
|
|
257
|
+
return __array;
|
|
258
|
+
}(maskAffinityFormats));
|
|
259
|
+
}
|
|
260
|
+
NitroInputMaskAffinity JHybridNitroInputViewSpec::getMaskAffinityStrategy() {
|
|
261
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JNitroInputMaskAffinity>()>("getMaskAffinityStrategy");
|
|
262
|
+
auto __result = method(_javaPart);
|
|
263
|
+
return __result->toCpp();
|
|
264
|
+
}
|
|
265
|
+
void JHybridNitroInputViewSpec::setMaskAffinityStrategy(NitroInputMaskAffinity maskAffinityStrategy) {
|
|
266
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JNitroInputMaskAffinity> /* maskAffinityStrategy */)>("setMaskAffinityStrategy");
|
|
267
|
+
method(_javaPart, JNitroInputMaskAffinity::fromCpp(maskAffinityStrategy));
|
|
268
|
+
}
|
|
269
|
+
NitroInputTextCase JHybridNitroInputViewSpec::getMaskTextCase() {
|
|
270
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JNitroInputTextCase>()>("getMaskTextCase");
|
|
271
|
+
auto __result = method(_javaPart);
|
|
272
|
+
return __result->toCpp();
|
|
273
|
+
}
|
|
274
|
+
void JHybridNitroInputViewSpec::setMaskTextCase(NitroInputTextCase maskTextCase) {
|
|
275
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JNitroInputTextCase> /* maskTextCase */)>("setMaskTextCase");
|
|
276
|
+
method(_javaPart, JNitroInputTextCase::fromCpp(maskTextCase));
|
|
277
|
+
}
|
|
278
|
+
std::vector<NitroInputCharacterMapping> JHybridNitroInputViewSpec::getMaskCharacterMap() {
|
|
279
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JNitroInputCharacterMapping>>()>("getMaskCharacterMap");
|
|
280
|
+
auto __result = method(_javaPart);
|
|
281
|
+
return [&](auto&& __input) {
|
|
282
|
+
size_t __size = __input->size();
|
|
283
|
+
std::vector<NitroInputCharacterMapping> __vector;
|
|
284
|
+
__vector.reserve(__size);
|
|
285
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
286
|
+
auto __element = __input->getElement(__i);
|
|
287
|
+
__vector.push_back(__element->toCpp());
|
|
288
|
+
}
|
|
289
|
+
return __vector;
|
|
290
|
+
}(__result);
|
|
291
|
+
}
|
|
292
|
+
void JHybridNitroInputViewSpec::setMaskCharacterMap(const std::vector<NitroInputCharacterMapping>& maskCharacterMap) {
|
|
293
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<JNitroInputCharacterMapping>> /* maskCharacterMap */)>("setMaskCharacterMap");
|
|
294
|
+
method(_javaPart, [&](auto&& __input) {
|
|
295
|
+
size_t __size = __input.size();
|
|
296
|
+
jni::local_ref<jni::JArrayClass<JNitroInputCharacterMapping>> __array = jni::JArrayClass<JNitroInputCharacterMapping>::newArray(__size);
|
|
297
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
298
|
+
const auto& __element = __input[__i];
|
|
299
|
+
auto __elementJni = JNitroInputCharacterMapping::fromCpp(__element);
|
|
300
|
+
__array->setElement(__i, *__elementJni);
|
|
301
|
+
}
|
|
302
|
+
return __array;
|
|
303
|
+
}(maskCharacterMap));
|
|
304
|
+
}
|
|
305
|
+
std::string JHybridNitroInputViewSpec::getMaskSlotPlaceholder() {
|
|
306
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getMaskSlotPlaceholder");
|
|
307
|
+
auto __result = method(_javaPart);
|
|
308
|
+
return __result->toStdString();
|
|
309
|
+
}
|
|
310
|
+
void JHybridNitroInputViewSpec::setMaskSlotPlaceholder(const std::string& maskSlotPlaceholder) {
|
|
311
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* maskSlotPlaceholder */)>("setMaskSlotPlaceholder");
|
|
312
|
+
method(_javaPart, jni::make_jstring(maskSlotPlaceholder));
|
|
313
|
+
}
|
|
314
|
+
bool JHybridNitroInputViewSpec::getKeepPlaceholder() {
|
|
315
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("getKeepPlaceholder");
|
|
316
|
+
auto __result = method(_javaPart);
|
|
317
|
+
return static_cast<bool>(__result);
|
|
318
|
+
}
|
|
319
|
+
void JHybridNitroInputViewSpec::setKeepPlaceholder(bool keepPlaceholder) {
|
|
320
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* keepPlaceholder */)>("setKeepPlaceholder");
|
|
321
|
+
method(_javaPart, keepPlaceholder);
|
|
322
|
+
}
|
|
221
323
|
std::string JHybridNitroInputViewSpec::getGroupingSeparator() {
|
|
222
324
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getGroupingSeparator");
|
|
223
325
|
auto __result = method(_javaPart);
|
|
@@ -70,6 +70,18 @@ namespace margelo::nitro::nitroinput {
|
|
|
70
70
|
void setMaskAutocomplete(bool maskAutocomplete) override;
|
|
71
71
|
bool getMaskAutoSkip() override;
|
|
72
72
|
void setMaskAutoSkip(bool maskAutoSkip) override;
|
|
73
|
+
std::vector<std::string> getMaskAffinityFormats() override;
|
|
74
|
+
void setMaskAffinityFormats(const std::vector<std::string>& maskAffinityFormats) override;
|
|
75
|
+
NitroInputMaskAffinity getMaskAffinityStrategy() override;
|
|
76
|
+
void setMaskAffinityStrategy(NitroInputMaskAffinity maskAffinityStrategy) override;
|
|
77
|
+
NitroInputTextCase getMaskTextCase() override;
|
|
78
|
+
void setMaskTextCase(NitroInputTextCase maskTextCase) override;
|
|
79
|
+
std::vector<NitroInputCharacterMapping> getMaskCharacterMap() override;
|
|
80
|
+
void setMaskCharacterMap(const std::vector<NitroInputCharacterMapping>& maskCharacterMap) override;
|
|
81
|
+
std::string getMaskSlotPlaceholder() override;
|
|
82
|
+
void setMaskSlotPlaceholder(const std::string& maskSlotPlaceholder) override;
|
|
83
|
+
bool getKeepPlaceholder() override;
|
|
84
|
+
void setKeepPlaceholder(bool keepPlaceholder) override;
|
|
73
85
|
std::string getGroupingSeparator() override;
|
|
74
86
|
void setGroupingSeparator(const std::string& groupingSeparator) override;
|
|
75
87
|
std::string getDecimalSeparator() override;
|