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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
- **`keepPlaceholder`**: the rest of a mask's placeholder stays visible,
|
|
6
|
+
greyed, after what has been typed ("1234 5" then "678 9012"); without a
|
|
7
|
+
`placeholder` the mask itself is shown, empty slots as
|
|
8
|
+
`maskSlotPlaceholder` (`_`): `+1 (212) ___-____`. Plain and reflowing
|
|
9
|
+
fields, both platforms.
|
|
10
|
+
- **`maskAffinityFormats`** and **`maskAffinityStrategy`**: several patterns
|
|
11
|
+
for one field, the best kept on every edit (a 4-6-5 Amex card beside
|
|
12
|
+
4-4-4-4). Compared on the value characters, and a tie keeps the format that
|
|
13
|
+
is showing, so the grouping does not flip back and forth while typing.
|
|
14
|
+
- **`maskTextCase`** uppercases or lowercases letters as they arrive, and
|
|
15
|
+
**`maskCharacterMap`** replaces characters before masking (Cyrillic
|
|
16
|
+
look-alikes, a comma for a dot).
|
|
17
|
+
- Letter slots (`[A]`, `[a]`) take letters beyond ASCII: Latin with
|
|
18
|
+
diacritics, Greek, Cyrillic, Armenian, Hebrew, Arabic, Devanagari, Thai,
|
|
19
|
+
Hangul, kana and CJK.
|
|
20
|
+
- A paste that repeats a mask's leading constants ("+63…" into
|
|
21
|
+
`+63 [000] [000] [0000]`) loses the repeat when it would otherwise overflow.
|
|
22
|
+
- **Fixed**: a constant the mask inserts right at the caret now puts the
|
|
23
|
+
caret after it when typing and before it when deleting (the gravity was the
|
|
24
|
+
wrong way round), as RedMadRobot's input-mask does.
|
|
25
|
+
- **Fixed**: an ellipsis after an optional slot (`[9…]`, `[a…]`) repeats that
|
|
26
|
+
slot; the format sanitizer used to move it to the front, where it took any
|
|
27
|
+
character.
|
|
28
|
+
- **Fixed (iOS)**: changing `mask` (or a number format) re-masks the text and
|
|
29
|
+
reports it through `onChangeText` / `onChangeMask` / `getText()`, as Android
|
|
30
|
+
does; the field showed the new text while JS kept the old one.
|
|
31
|
+
- The mask engine is checked against ~1,900 cases ported from RedMadRobot's
|
|
32
|
+
input-mask (Android and iOS), maska and react-native-advanced-input-mask.
|
|
33
|
+
|
|
3
34
|
## 0.3.1
|
|
4
35
|
|
|
5
36
|
- **Signs**: `signDisplay` (`'auto'`, `'always'`, `'exceptZero'`,
|
package/README.md
CHANGED
|
@@ -107,8 +107,9 @@ The pattern is compiled once into a linked state machine in C++ and shared by
|
|
|
107
107
|
both platforms, so the formatting, the caret and the "what is still missing"
|
|
108
108
|
tail all come from one place and cannot drift apart. `[…]` is an editable
|
|
109
109
|
block, `{…}` a literal the engine inserts for you. Built-in slots: `0` a
|
|
110
|
-
required digit, `9` an optional one, `A`/`a` letters,
|
|
111
|
-
|
|
110
|
+
required digit, `9` an optional one, `A`/`a` letters (Latin, Greek, Cyrillic
|
|
111
|
+
and the other common scripts), `_`/`-` a letter or digit, `…` repeats the
|
|
112
|
+
previous slot.
|
|
112
113
|
|
|
113
114
|
Add your own with `maskNotations`:
|
|
114
115
|
|
|
@@ -125,6 +126,26 @@ before them is satisfied; `maskAutoSkip` (default `false`) lets a backspace
|
|
|
125
126
|
step back over them. Autocompletion only runs when the caret is at the end, so
|
|
126
127
|
editing in the middle of a value does not fight you.
|
|
127
128
|
|
|
129
|
+
Keep what is still to come in view, pick between several shapes, and fix the
|
|
130
|
+
case as the user types:
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
<NitroInput
|
|
134
|
+
mode="mask"
|
|
135
|
+
mask="[0000] [0000] [0000] [0000]"
|
|
136
|
+
// Amex numbers take the 4-6-5 grouping
|
|
137
|
+
maskAffinityFormats={['{34}[00] [000000] [00000]', '{37}[00] [000000] [00000]']}
|
|
138
|
+
placeholder="1234 5678 9012 3456"
|
|
139
|
+
keepPlaceholder // "4111 1" then "678 9012 3456" greyed
|
|
140
|
+
/>
|
|
141
|
+
|
|
142
|
+
<NitroInput mode="mask" mask="[AAAA][AA][__][___]" maskTextCase="upper" /> // a BIC
|
|
143
|
+
<NitroInput mode="mask" mask="[099999].[99]" maskCharacterMap={{ ',': '.' }} />
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
A paste that repeats the mask's leading constants (`+639123456789` into
|
|
147
|
+
`+63 [000] [000] [0000]`) loses the repeat when it would otherwise overflow.
|
|
148
|
+
|
|
128
149
|
### Outlined and filled frames
|
|
129
150
|
|
|
130
151
|
```tsx
|
|
@@ -402,10 +423,16 @@ rather than renumbering the columns.
|
|
|
402
423
|
| `maxIntegerDigits` | `number` | `15` | `number`: most integer digits accepted; further digits are rejected. |
|
|
403
424
|
| `groupingSeparator` | `string` | `','` | `number`: every three integer digits; `''` disables grouping. |
|
|
404
425
|
| `decimalSeparator` | `string` | `'.'` | `number`: between integer and fraction digits. |
|
|
405
|
-
| `mask` | `string` | `''` | `mask`: the pattern. `[…]` an editable block, `{…}` a literal the engine inserts. Slots: `0` required digit, `9` optional digit, `A`/`a` letter, `_
|
|
426
|
+
| `mask` | `string` | `''` | `mask`: the pattern. `[…]` an editable block, `{…}` a literal the engine inserts. Slots: `0` required digit, `9` optional digit, `A`/`a` letter, `_`/`-` letter or digit, `…` repeat. |
|
|
406
427
|
| `maskNotations` | `{ character, characterSet, isOptional }[]` | `[]` | `mask`: caller-defined slots beyond the built-ins. |
|
|
407
428
|
| `maskAutocomplete` | `boolean` | `true` | `mask`: insert literals as soon as the slot before them is filled. Only while the caret is at the end. |
|
|
408
429
|
| `maskAutoSkip` | `boolean` | `false` | `mask`: let a backspace step back over inserted literals. |
|
|
430
|
+
| `keepPlaceholder` | `boolean` | `false` | `mask`: keep the rest of the placeholder (or, without one, the mask) greyed after the typed text. |
|
|
431
|
+
| `maskSlotPlaceholder` | `string` | `'_'` with `keepPlaceholder`, else `''` | `mask`: what an empty slot shows in the kept placeholder and `onChangeMask`'s tail. |
|
|
432
|
+
| `maskAffinityFormats` | `string[]` | `[]` | `mask`: more patterns the text may take; the best one wins each edit, `mask` wins ties. |
|
|
433
|
+
| `maskAffinityStrategy` | `'wholeString' \| 'prefix' \| 'capacity' \| 'extractedValueCapacity'` | `'wholeString'` | `mask`: how the best of `maskAffinityFormats` is chosen. |
|
|
434
|
+
| `maskTextCase` | `'none' \| 'upper' \| 'lower'` | `'none'` | `mask`: fold letters as they are typed or pasted. |
|
|
435
|
+
| `maskCharacterMap` | `Record<string, string>` | `{}` | `mask`: characters replaced before masking (`{ ',': '.' }`); an empty replacement drops one. |
|
|
409
436
|
| `variant` | `'none' \| 'outlined' \| 'filled'` | `'none'` | Draws a frame for itself. The outlined notch is a real hole in the stroke. |
|
|
410
437
|
| `label` | `string` | `''` | Floating label. Also becomes the field's accessible name when nothing else gives it one. |
|
|
411
438
|
| `labelBehavior` | `'float' \| 'always'` | `'float'` | `always` keeps it floated even when empty and blurred. |
|
|
@@ -29,6 +29,15 @@ void JMaskEngine::registerNatives() {
|
|
|
29
29
|
makeNativeMethod("lastExtracted", JMaskEngine::lastExtracted),
|
|
30
30
|
makeNativeMethod("lastTailPlaceholder", JMaskEngine::lastTailPlaceholder),
|
|
31
31
|
makeNativeMethod("lastComplete", JMaskEngine::lastComplete),
|
|
32
|
+
makeNativeMethod("lastFormatIndex", JMaskEngine::lastFormatIndex),
|
|
33
|
+
makeNativeMethod("clearAffinityFormats", JMaskEngine::clearAffinityFormats),
|
|
34
|
+
makeNativeMethod("addAffinityFormat", JMaskEngine::addAffinityFormat),
|
|
35
|
+
makeNativeMethod("setAffinityStrategy", JMaskEngine::setAffinityStrategy),
|
|
36
|
+
makeNativeMethod("setTextCase", JMaskEngine::setTextCase),
|
|
37
|
+
makeNativeMethod("clearCharacterMap", JMaskEngine::clearCharacterMap),
|
|
38
|
+
makeNativeMethod("addCharacterMapping", JMaskEngine::addCharacterMapping),
|
|
39
|
+
makeNativeMethod("setSlotPlaceholder", JMaskEngine::setSlotPlaceholder),
|
|
40
|
+
makeNativeMethod("isActive", JMaskEngine::isActive),
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
43
|
|
|
@@ -78,4 +87,40 @@ bool JMaskEngine::lastComplete() {
|
|
|
78
87
|
return last_.complete;
|
|
79
88
|
}
|
|
80
89
|
|
|
90
|
+
void JMaskEngine::clearAffinityFormats() {
|
|
91
|
+
engine_.clearAffinityFormats();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void JMaskEngine::addAffinityFormat(jni::alias_ref<jni::JString> format) {
|
|
95
|
+
engine_.addAffinityFormat(str(format));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void JMaskEngine::setAffinityStrategy(int strategy) {
|
|
99
|
+
engine_.setAffinityStrategy(strategy);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void JMaskEngine::setTextCase(int textCase) {
|
|
103
|
+
engine_.setTextCase(textCase);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void JMaskEngine::clearCharacterMap() {
|
|
107
|
+
engine_.clearCharacterMap();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void JMaskEngine::addCharacterMapping(jni::alias_ref<jni::JString> from, jni::alias_ref<jni::JString> to) {
|
|
111
|
+
engine_.addCharacterMapping(str(from), str(to));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
void JMaskEngine::setSlotPlaceholder(jni::alias_ref<jni::JString> character) {
|
|
115
|
+
engine_.setSlotPlaceholder(str(character));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
bool JMaskEngine::isActive() {
|
|
119
|
+
return engine_.isActive();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
int JMaskEngine::lastFormatIndex() {
|
|
123
|
+
return last_.formatIndex;
|
|
124
|
+
}
|
|
125
|
+
|
|
81
126
|
} // namespace margelo::nitro::nitroinput
|
|
@@ -27,6 +27,14 @@ public:
|
|
|
27
27
|
void clearNotations();
|
|
28
28
|
void addNotation(jni::alias_ref<jni::JString> character, jni::alias_ref<jni::JString> characterSet, bool isOptional);
|
|
29
29
|
bool setFormat(jni::alias_ref<jni::JString> format);
|
|
30
|
+
void clearAffinityFormats();
|
|
31
|
+
void addAffinityFormat(jni::alias_ref<jni::JString> format);
|
|
32
|
+
void setAffinityStrategy(int strategy);
|
|
33
|
+
void setTextCase(int textCase);
|
|
34
|
+
void clearCharacterMap();
|
|
35
|
+
void addCharacterMapping(jni::alias_ref<jni::JString> from, jni::alias_ref<jni::JString> to);
|
|
36
|
+
void setSlotPlaceholder(jni::alias_ref<jni::JString> character);
|
|
37
|
+
bool isActive();
|
|
30
38
|
|
|
31
39
|
/// Replaces code points [start, end) of `current` with `replacement`.
|
|
32
40
|
jni::local_ref<jni::JString> applyEdit(jni::alias_ref<jni::JString> current, int start, int end,
|
|
@@ -39,6 +47,7 @@ public:
|
|
|
39
47
|
jni::local_ref<jni::JString> lastExtracted();
|
|
40
48
|
jni::local_ref<jni::JString> lastTailPlaceholder();
|
|
41
49
|
bool lastComplete();
|
|
50
|
+
int lastFormatIndex();
|
|
42
51
|
|
|
43
52
|
private:
|
|
44
53
|
friend HybridBase;
|
|
@@ -91,6 +91,18 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
91
91
|
set(value) { field = value; markConfigDirty() }
|
|
92
92
|
override var maskAutoSkip: Boolean = false
|
|
93
93
|
set(value) { field = value; markConfigDirty() }
|
|
94
|
+
override var maskAffinityFormats: Array<String> = emptyArray()
|
|
95
|
+
set(value) { field = value; markConfigDirty() }
|
|
96
|
+
override var maskAffinityStrategy: NitroInputMaskAffinity = NitroInputMaskAffinity.WHOLESTRING
|
|
97
|
+
set(value) { field = value; markConfigDirty() }
|
|
98
|
+
override var maskTextCase: NitroInputTextCase = NitroInputTextCase.NONE
|
|
99
|
+
set(value) { field = value; markConfigDirty() }
|
|
100
|
+
override var maskCharacterMap: Array<NitroInputCharacterMapping> = emptyArray()
|
|
101
|
+
set(value) { field = value; markConfigDirty() }
|
|
102
|
+
override var maskSlotPlaceholder: String = ""
|
|
103
|
+
set(value) { field = value; markConfigDirty() }
|
|
104
|
+
override var keepPlaceholder: Boolean = false
|
|
105
|
+
set(value) { field = value; markConfigDirty() }
|
|
94
106
|
override var mode: NitroInputMode = NitroInputMode.TEXT
|
|
95
107
|
set(v) { field = v; markConfigDirty() }
|
|
96
108
|
override var fractionDigits: Double = 2.0
|
|
@@ -373,6 +385,12 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
373
385
|
maskNotations = emptyArray()
|
|
374
386
|
maskAutocomplete = true
|
|
375
387
|
maskAutoSkip = false
|
|
388
|
+
maskAffinityFormats = emptyArray()
|
|
389
|
+
maskAffinityStrategy = NitroInputMaskAffinity.WHOLESTRING
|
|
390
|
+
maskTextCase = NitroInputTextCase.NONE
|
|
391
|
+
maskCharacterMap = emptyArray()
|
|
392
|
+
maskSlotPlaceholder = ""
|
|
393
|
+
keepPlaceholder = false
|
|
376
394
|
mode = NitroInputMode.TEXT
|
|
377
395
|
fractionDigits = 2.0
|
|
378
396
|
maxIntegerDigits = 15.0
|
|
@@ -570,6 +588,12 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
570
588
|
},
|
|
571
589
|
maskAutocomplete = maskAutocomplete,
|
|
572
590
|
maskAutoSkip = maskAutoSkip,
|
|
591
|
+
maskAffinityFormats = maskAffinityFormats.toList(),
|
|
592
|
+
maskAffinityStrategy = maskAffinityStrategy.value,
|
|
593
|
+
maskTextCase = maskTextCase.value,
|
|
594
|
+
maskCharacterMap = maskCharacterMap.map { NitroInputView.MaskMapping(it.from, it.to) },
|
|
595
|
+
maskSlotPlaceholder = maskSlotPlaceholder,
|
|
596
|
+
keepPlaceholder = keepPlaceholder,
|
|
573
597
|
fractionDigits = clampInt(fractionDigits, 0, 9, 2),
|
|
574
598
|
maxIntegerDigits = clampInt(maxIntegerDigits, 1, 30, 15),
|
|
575
599
|
groupingSeparator = groupingSeparator,
|
|
@@ -25,6 +25,20 @@ class MaskEngine {
|
|
|
25
25
|
external fun addNotation(character: String, characterSet: String, isOptional: Boolean)
|
|
26
26
|
/** False when the pattern is malformed; the engine then passes text through. */
|
|
27
27
|
external fun setFormat(format: String): Boolean
|
|
28
|
+
/** Stages alternative patterns for the next [setFormat]; the best one wins each edit. */
|
|
29
|
+
external fun clearAffinityFormats()
|
|
30
|
+
external fun addAffinityFormat(format: String)
|
|
31
|
+
/** `NitroInputMaskAffinity.value`: how the best alternative is chosen. */
|
|
32
|
+
external fun setAffinityStrategy(strategy: Int)
|
|
33
|
+
/** `NitroInputTextCase.value`: letters folded before masking. */
|
|
34
|
+
external fun setTextCase(textCase: Int)
|
|
35
|
+
/** Characters replaced before masking; an empty [to] drops [from]. */
|
|
36
|
+
external fun clearCharacterMap()
|
|
37
|
+
external fun addCharacterMapping(from: String, to: String)
|
|
38
|
+
/** What each empty slot shows in the tail placeholder; empty = its notation character. */
|
|
39
|
+
external fun setSlotPlaceholder(character: String)
|
|
40
|
+
/** False until a valid pattern is set. */
|
|
41
|
+
external fun isActive(): Boolean
|
|
28
42
|
|
|
29
43
|
/** Replaces code points `[start, end)` of [current] with [replacement]. */
|
|
30
44
|
external fun applyEdit(
|
|
@@ -47,4 +61,6 @@ class MaskEngine {
|
|
|
47
61
|
external fun lastTailPlaceholder(): String
|
|
48
62
|
/** Whether every mandatory slot is filled. */
|
|
49
63
|
external fun lastComplete(): Boolean
|
|
64
|
+
/** Which pattern produced the last result: 0 the primary, 1… the alternatives. */
|
|
65
|
+
external fun lastFormatIndex(): Int
|
|
50
66
|
}
|
|
@@ -79,6 +79,9 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
79
79
|
/** A caller-defined slot character for [Format.mask]. */
|
|
80
80
|
data class MaskNotation(val character: String, val characterSet: String, val isOptional: Boolean)
|
|
81
81
|
|
|
82
|
+
/** One character replaced by another before masking. */
|
|
83
|
+
data class MaskMapping(val from: String, val to: String)
|
|
84
|
+
|
|
82
85
|
/**
|
|
83
86
|
* The frame the view draws for itself: the outline (or fill) and the floating
|
|
84
87
|
* label. Separate from [Format] because it changes independently. Lengths are
|
|
@@ -110,6 +113,16 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
110
113
|
val maskNotations: List<MaskNotation> = emptyList(),
|
|
111
114
|
val maskAutocomplete: Boolean = true,
|
|
112
115
|
val maskAutoSkip: Boolean = false,
|
|
116
|
+
/** Mask mode: alternative patterns and how the best is chosen (`NitroInputMaskAffinity.value`). */
|
|
117
|
+
val maskAffinityFormats: List<String> = emptyList(),
|
|
118
|
+
val maskAffinityStrategy: Int = 0,
|
|
119
|
+
/** Mask mode: `NitroInputTextCase.value`. */
|
|
120
|
+
val maskTextCase: Int = 0,
|
|
121
|
+
val maskCharacterMap: List<MaskMapping> = emptyList(),
|
|
122
|
+
/** Mask mode: what an empty slot shows in the tail; empty = its notation. */
|
|
123
|
+
val maskSlotPlaceholder: String = "",
|
|
124
|
+
/** Mask mode: keep the rest of the placeholder after the typed text. */
|
|
125
|
+
val keepPlaceholder: Boolean = false,
|
|
113
126
|
val fractionDigits: Int = 2,
|
|
114
127
|
val maxIntegerDigits: Int = 15,
|
|
115
128
|
val groupingSeparator: String = ",",
|
|
@@ -218,11 +231,20 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
218
231
|
val old = field
|
|
219
232
|
field = value
|
|
220
233
|
formatter.setFormat(value.fractionDigits, value.maxIntegerDigits, value.groupingSeparator, value.decimalSeparator)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
234
|
+
val maskChanged = old.mask != value.mask || old.maskNotations != value.maskNotations ||
|
|
235
|
+
old.maskAffinityFormats != value.maskAffinityFormats || old.maskAffinityStrategy != value.maskAffinityStrategy ||
|
|
236
|
+
old.maskTextCase != value.maskTextCase || old.maskCharacterMap != value.maskCharacterMap ||
|
|
237
|
+
old.maskSlotPlaceholder != value.maskSlotPlaceholder
|
|
238
|
+
if (value.mode == Mode.MASK && (old.mode != Mode.MASK || maskChanged)) {
|
|
224
239
|
maskEngine.clearNotations()
|
|
225
240
|
value.maskNotations.forEach { maskEngine.addNotation(it.character, it.characterSet, it.isOptional) }
|
|
241
|
+
maskEngine.clearAffinityFormats()
|
|
242
|
+
value.maskAffinityFormats.forEach { maskEngine.addAffinityFormat(it) }
|
|
243
|
+
maskEngine.setAffinityStrategy(value.maskAffinityStrategy)
|
|
244
|
+
maskEngine.setTextCase(value.maskTextCase)
|
|
245
|
+
maskEngine.clearCharacterMap()
|
|
246
|
+
value.maskCharacterMap.forEach { maskEngine.addCharacterMapping(it.from, it.to) }
|
|
247
|
+
maskEngine.setSlotPlaceholder(value.maskSlotPlaceholder)
|
|
226
248
|
// A bad pattern leaves the engine inactive; the field then behaves as
|
|
227
249
|
// plain text rather than refusing every keystroke.
|
|
228
250
|
maskEngine.setFormat(value.mask)
|
|
@@ -382,6 +404,23 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
382
404
|
return offsetForTap(x)
|
|
383
405
|
}
|
|
384
406
|
|
|
407
|
+
private val ghostPaint = android.text.TextPaint()
|
|
408
|
+
|
|
409
|
+
override fun onDraw(canvas: Canvas) {
|
|
410
|
+
super.onDraw(canvas)
|
|
411
|
+
// Plain mode has no overlay, so `keepPlaceholder`'s tail is drawn here:
|
|
412
|
+
// from where the field's own text ends, on its baseline, in its paint
|
|
413
|
+
// and the hint colour. (onDraw's canvas is already scrolled.)
|
|
414
|
+
if (!ready || !keyboard.plain || layoutDirection == LAYOUT_DIRECTION_RTL) return
|
|
415
|
+
val tail = ghostTail
|
|
416
|
+
val textLayout = layout ?: return
|
|
417
|
+
if (tail.isEmpty()) return
|
|
418
|
+
ghostPaint.set(paint)
|
|
419
|
+
ghostPaint.color = currentHintTextColor
|
|
420
|
+
val x = compoundPaddingLeft + textLayout.getPrimaryHorizontal(length())
|
|
421
|
+
canvas.drawText(tail, x, baseline.toFloat(), ghostPaint)
|
|
422
|
+
}
|
|
423
|
+
|
|
385
424
|
override fun onSelectionChanged(selStart: Int, selEnd: Int) {
|
|
386
425
|
super.onSelectionChanged(selStart, selEnd)
|
|
387
426
|
if (!ready) return
|
|
@@ -1528,7 +1567,12 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1528
1567
|
// A plain field draws its own text and never feeds the engine, but its
|
|
1529
1568
|
// width still has to reach React for `autoWidth`; every text, font, affix
|
|
1530
1569
|
// and hint change comes through here.
|
|
1531
|
-
if (keyboard.plain) {
|
|
1570
|
+
if (keyboard.plain) {
|
|
1571
|
+
// The EditText draws the kept placeholder's tail itself (HiddenEditText.onDraw).
|
|
1572
|
+
editText.invalidate()
|
|
1573
|
+
reportIntrinsicSize()
|
|
1574
|
+
return
|
|
1575
|
+
}
|
|
1532
1576
|
val f = fonts
|
|
1533
1577
|
engine.setReduceMotion(animationsDisabled())
|
|
1534
1578
|
engine.beginText()
|
|
@@ -1549,7 +1593,13 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1549
1593
|
// body glyph before a suffix carry the seams instead.
|
|
1550
1594
|
if (signed) addRun(shown.substring(0, 1), Role.BODY, f, placeholder = false)
|
|
1551
1595
|
addRun(format.prefix, Role.PREFIX, f, placeholder = false, lastSpacing = f.prefixSeam)
|
|
1596
|
+
val tail = if (showPlaceholder) "" else ghostTail
|
|
1552
1597
|
addRun(if (signed) shown.substring(1) else shown, Role.BODY, f, placeholder = showPlaceholder,
|
|
1598
|
+
lastSpacing = if (format.suffix.isNotEmpty() && tail.isEmpty()) f.suffixSeam else null)
|
|
1599
|
+
// `keepPlaceholder`: the rest of the mask trails the text as placeholder
|
|
1600
|
+
// glyphs. They come after every typed glyph, so the caret - which counts
|
|
1601
|
+
// body glyphs in order - never lands among them.
|
|
1602
|
+
addRun(tail, Role.BODY, f, placeholder = true,
|
|
1553
1603
|
lastSpacing = if (format.suffix.isNotEmpty()) f.suffixSeam else null)
|
|
1554
1604
|
addRun(format.suffix, Role.SUFFIX, f, placeholder = false)
|
|
1555
1605
|
engine.commitText(caret, now())
|
|
@@ -1720,7 +1770,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1720
1770
|
val body = when {
|
|
1721
1771
|
text.isEmpty() -> effectivePlaceholder
|
|
1722
1772
|
keyboard.secureTextEntry -> "\u2022".repeat(text.codePointCount(0, text.length))
|
|
1723
|
-
else -> text
|
|
1773
|
+
else -> text + ghostTail
|
|
1724
1774
|
}
|
|
1725
1775
|
// The edit text's own letter spacing follows every glyph; the affixes take their room with their seams.
|
|
1726
1776
|
val f = fonts
|
|
@@ -1940,7 +1990,47 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1940
1990
|
* waits until the label has floated clear rather than printing over it.
|
|
1941
1991
|
*/
|
|
1942
1992
|
private val effectivePlaceholder: String
|
|
1943
|
-
get() = if (inputFrame.hasLabel && !labelShouldFloat) "" else
|
|
1993
|
+
get() = if (inputFrame.hasLabel && !labelShouldFloat) "" else basePlaceholder
|
|
1994
|
+
|
|
1995
|
+
/**
|
|
1996
|
+
* `keepPlaceholder` without a `placeholder` shows the mask itself, empty
|
|
1997
|
+
* slots as `maskSlotPlaceholder`: "+1 (___) ___-____".
|
|
1998
|
+
*/
|
|
1999
|
+
private val basePlaceholder: String
|
|
2000
|
+
get() {
|
|
2001
|
+
if (format.placeholder.isEmpty() && format.mode == Mode.MASK && format.keepPlaceholder && maskEngine.isActive()) {
|
|
2002
|
+
maskEngine.applyAll("", 0, true, false, false)
|
|
2003
|
+
return maskEngine.lastTailPlaceholder()
|
|
2004
|
+
}
|
|
2005
|
+
return format.placeholder
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* `keepPlaceholder`: what is still to come after the typed text, drawn in the
|
|
2010
|
+
* placeholder colour. The caller's placeholder from where the text ends -
|
|
2011
|
+
* "1234 5" leaves "678 9012" of "1234 5678 9012" - or, without one, the rest
|
|
2012
|
+
* of the mask. The placeholder is written for `mask`, so when one of
|
|
2013
|
+
* `maskAffinityFormats` has taken over (a 4-6-5 Amex under a 4-4-4-4
|
|
2014
|
+
* placeholder) its characters no longer line up, and that format's own tail
|
|
2015
|
+
* is shown instead. A complete text has nothing to come.
|
|
2016
|
+
*/
|
|
2017
|
+
private val ghostTail: String
|
|
2018
|
+
get() {
|
|
2019
|
+
if (format.mode != Mode.MASK || !format.keepPlaceholder || text.isEmpty() || keyboard.secureTextEntry ||
|
|
2020
|
+
!maskEngine.isActive()
|
|
2021
|
+
) {
|
|
2022
|
+
return ""
|
|
2023
|
+
}
|
|
2024
|
+
val typed = text.codePointCount(0, text.length)
|
|
2025
|
+
maskEngine.applyAll(text, typed, true, false, false)
|
|
2026
|
+
if (maskEngine.lastComplete()) return ""
|
|
2027
|
+
val placeholder = format.placeholder
|
|
2028
|
+
if (placeholder.isNotEmpty() && maskEngine.lastFormatIndex() == 0) {
|
|
2029
|
+
val total = placeholder.codePointCount(0, placeholder.length)
|
|
2030
|
+
return if (typed < total) placeholder.substring(placeholder.offsetByCodePoints(0, typed)) else ""
|
|
2031
|
+
}
|
|
2032
|
+
return maskEngine.lastTailPlaceholder()
|
|
2033
|
+
}
|
|
1944
2034
|
|
|
1945
2035
|
private fun resolvedStrokeColor(): Int {
|
|
1946
2036
|
val base = inputFrame.strokeColor ?: mutedTextColor
|