react-native-nitro-input 0.3.1 → 0.3.3
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 +114 -0
- package/README.md +75 -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 +49 -4
- package/android/src/main/java/com/margelo/nitro/nitroinput/MaskEngine.kt +16 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +266 -8
- package/android/src/main/java/com/margelo/nitro/nitroinput/UnmountHandoffs.kt +57 -0
- package/cpp/MaskEngine.cpp +294 -33
- package/cpp/MaskEngine.hpp +68 -0
- package/ios/HybridNitroInputView.swift +37 -4
- package/ios/NitroInputCommands.mm +10 -0
- package/ios/NitroInputView.swift +474 -20
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +8 -0
- package/lib/commonjs/src/NitroInput.js +116 -15
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +8 -0
- package/lib/module/src/NitroInput.js +117 -16
- package/lib/typescript/src/NitroInput.d.ts +55 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +65 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +124 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +17 -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 +40 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +52 -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 +68 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +48 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +9 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +111 -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 +17 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +26 -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 +16 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +27 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +8 -0
- package/package.json +2 -2
- package/src/NitroInput.tsx +190 -11
- package/src/index.ts +3 -0
- package/src/specs/NitroInput.nitro.ts +68 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,119 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.3
|
|
4
|
+
|
|
5
|
+
- **`keyboardHandoffMs`**: when the focused field is popped or unmounted,
|
|
6
|
+
the keyboard stays up this long for the next field to take over (the
|
|
7
|
+
screen you return to, the next step's field), instead of dropping and
|
|
8
|
+
rising again. Both platforms; `Keyboard.dismiss()` ends the hold at once.
|
|
9
|
+
- **`focus()` on a field that is not on screen yet** (a screen navigated back
|
|
10
|
+
to, refocusing its field before it is shown again) now focuses it as soon
|
|
11
|
+
as it is, while the keyboard is still up. On Android this alone keeps the
|
|
12
|
+
keyboard up across a stack pop.
|
|
13
|
+
- **iOS number pads get a return key**: a field on the number, phone or
|
|
14
|
+
decimal pad with a `returnKeyType` set shows a bar above the keyboard with
|
|
15
|
+
that key ("Next", "Go", "Done"...), as `TextInput` does. The pads have no
|
|
16
|
+
return key of their own, so a form chained with Next stopped at its first
|
|
17
|
+
numeric field. The bar is the return key: `submitBehavior`,
|
|
18
|
+
`onSubmitEditing` and worklets run as for the real one.
|
|
19
|
+
- **`returnKeyBar`** (iOS, default `true`): `false` leaves a number pad
|
|
20
|
+
without the return key bar, for a screen whose own button rides the
|
|
21
|
+
keyboard (a sticky or morphing CTA) and would otherwise be doubled.
|
|
22
|
+
- **Fixed (iOS)**: coming back to a screen whose field had the keyboard, when
|
|
23
|
+
the field on the leaving screen used `keyboardHandoffMs`, left the keyboard
|
|
24
|
+
down: the stand-in held it, so UIKit had nothing to give back. The field
|
|
25
|
+
now takes the keyboard back itself, with the back animation.
|
|
26
|
+
- **Fixed (iOS)**: a multiline field kept drawing its placeholder under the
|
|
27
|
+
first characters typed.
|
|
28
|
+
- **iOS 26: no dark keyboard on the way back.** When you return to a screen
|
|
29
|
+
whose field had the keyboard, UIKit gives the field its focus back as the
|
|
30
|
+
transition starts, and iOS 26 then slides the keyboard in with the screen as
|
|
31
|
+
a flat dark snapshot. The field now takes its focus back once the screen has
|
|
32
|
+
settled, so the real keyboard rises from the bottom, as in the system apps
|
|
33
|
+
(Contacts). Focus the app asks for (`focus()`, `autoFocus`) is unchanged.
|
|
34
|
+
- **Fixed: `<Activity>`** (React 19.2). A hidden `<Activity>` deletes its
|
|
35
|
+
native views and creates new ones when shown again, so a NitroInput came
|
|
36
|
+
back with its first text (an uncontrolled field's text lived only
|
|
37
|
+
natively), and a handle kept from before hiding reached the pooled view,
|
|
38
|
+
which another field may have been given: `focus()` on a hidden field's
|
|
39
|
+
handle focused that other field. The text is now kept across hide and show,
|
|
40
|
+
and while hidden a field's handle does nothing (`focus()` / `blur()`) or
|
|
41
|
+
waits (`setText`); `getText()` returns the kept text. On Android, where
|
|
42
|
+
a hidden field keeps its view, the field takes it back when shown, and a
|
|
43
|
+
`focus()` asked for while the field is still hidden waits until it is
|
|
44
|
+
shown.
|
|
45
|
+
- **Fixed**: `Keyboard.dismiss()` right after a field with `keyboardHandoffMs`
|
|
46
|
+
unmounted, on a screen with no other field (a questionnaire's tap-only
|
|
47
|
+
question), waited for the hold to run out (about 0.4 s) before the keyboard
|
|
48
|
+
closed. It closes at once now.
|
|
49
|
+
- **Fixed (iOS)**: keyboard-controller's `KeyboardAwareScrollView` did not
|
|
50
|
+
scroll a field that got its focus back (the caret had not moved, so it got no
|
|
51
|
+
selection event and waited for one). The field now reports its selection
|
|
52
|
+
once editing begins.
|
|
53
|
+
- **Changed**: a controlled field whose parent keeps its `value` while the
|
|
54
|
+
user types (a rejected edit, a digits-only filter) puts the value back, as
|
|
55
|
+
`TextInput` does. It used to keep showing what was typed.
|
|
56
|
+
- **Fixed (Android)**: `keyboardHandoffMs` on a field that unmounts could lose
|
|
57
|
+
the race with the frame that removes it (about two runs in three on a
|
|
58
|
+
Galaxy A22), and the keyboard dropped anyway. The handoff now runs on the
|
|
59
|
+
UI thread just before Fabric applies that frame's view changes.
|
|
60
|
+
- **Docs**: "The keyboard across screens and lists" in the README: the
|
|
61
|
+
settings that make a NitroInput screen behave like the platform apps, back
|
|
62
|
+
navigation included (iOS gives the field its keyboard back as long as
|
|
63
|
+
native-stack's `keyboardHandlingEnabled` stays off).
|
|
64
|
+
- **Fixed (Android)**: a field on a screen react-native-screens covered and
|
|
65
|
+
uncovered came back still flagged as focused, and `focus()` did nothing.
|
|
66
|
+
- **Fixed (Android)**: keyboard-controller saw no focused input for a
|
|
67
|
+
NitroInput, so `KeyboardAwareScrollView` never scrolled to it.
|
|
68
|
+
- **Fixed (Android)**: changing `clearTextOnFocus` after mount had no effect.
|
|
69
|
+
- **Fixed (iOS)**: `KeyboardAwareScrollView` scrolled a reflowing field only
|
|
70
|
+
far enough to show the top of its line.
|
|
71
|
+
- **Fixed (iOS)**: a multiline field counted twice for keyboard-controller's
|
|
72
|
+
next / previous and its toolbar.
|
|
73
|
+
- **Fixed (iOS)**: React Native's `focus` / `blur` view commands now go
|
|
74
|
+
through the field's own `focus()` / `blur()` (retrying a declined focus).
|
|
75
|
+
- An on-device keyboard suite measures each of these: no keyboard hide when
|
|
76
|
+
focus moves, a field unmounts as the next autofocuses, a stack pops, a
|
|
77
|
+
search list filters under the field, or a scroll moves it out of sight.
|
|
78
|
+
The example app has an input lab (a search list and a form chained with
|
|
79
|
+
Next, each with NitroInput or TextInput), and
|
|
80
|
+
`example/e2e/keyboard-lab-android.sh` drives it with real touches over adb.
|
|
81
|
+
The lab also has a form with a sticky and a morphing CTA (keyboard-
|
|
82
|
+
controller), a push, a form sheet and a list of fields, and a scripted run
|
|
83
|
+
(`globalThis.__lab.run()`) that records keyboard-controller's events on a
|
|
84
|
+
device nothing can tap on.
|
|
85
|
+
|
|
86
|
+
## 0.3.2
|
|
87
|
+
|
|
88
|
+
- **`keepPlaceholder`**: the rest of a mask's placeholder stays visible,
|
|
89
|
+
greyed, after what has been typed ("1234 5" then "678 9012"); without a
|
|
90
|
+
`placeholder` the mask itself is shown, empty slots as
|
|
91
|
+
`maskSlotPlaceholder` (`_`): `+1 (212) ___-____`. Plain and reflowing
|
|
92
|
+
fields, both platforms.
|
|
93
|
+
- **`maskAffinityFormats`** and **`maskAffinityStrategy`**: several patterns
|
|
94
|
+
for one field, the best kept on every edit (a 4-6-5 Amex card beside
|
|
95
|
+
4-4-4-4). Compared on the value characters, and a tie keeps the format that
|
|
96
|
+
is showing, so the grouping does not flip back and forth while typing.
|
|
97
|
+
- **`maskTextCase`** uppercases or lowercases letters as they arrive, and
|
|
98
|
+
**`maskCharacterMap`** replaces characters before masking (Cyrillic
|
|
99
|
+
look-alikes, a comma for a dot).
|
|
100
|
+
- Letter slots (`[A]`, `[a]`) take letters beyond ASCII: Latin with
|
|
101
|
+
diacritics, Greek, Cyrillic, Armenian, Hebrew, Arabic, Devanagari, Thai,
|
|
102
|
+
Hangul, kana and CJK.
|
|
103
|
+
- A paste that repeats a mask's leading constants ("+63…" into
|
|
104
|
+
`+63 [000] [000] [0000]`) loses the repeat when it would otherwise overflow.
|
|
105
|
+
- **Fixed**: a constant the mask inserts right at the caret now puts the
|
|
106
|
+
caret after it when typing and before it when deleting (the gravity was the
|
|
107
|
+
wrong way round), as RedMadRobot's input-mask does.
|
|
108
|
+
- **Fixed**: an ellipsis after an optional slot (`[9…]`, `[a…]`) repeats that
|
|
109
|
+
slot; the format sanitizer used to move it to the front, where it took any
|
|
110
|
+
character.
|
|
111
|
+
- **Fixed (iOS)**: changing `mask` (or a number format) re-masks the text and
|
|
112
|
+
reports it through `onChangeText` / `onChangeMask` / `getText()`, as Android
|
|
113
|
+
does; the field showed the new text while JS kept the old one.
|
|
114
|
+
- The mask engine is checked against ~1,900 cases ported from RedMadRobot's
|
|
115
|
+
input-mask (Android and iOS), maska and react-native-advanced-input-mask.
|
|
116
|
+
|
|
3
117
|
## 0.3.1
|
|
4
118
|
|
|
5
119
|
- **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
|
|
@@ -391,6 +412,49 @@ place. Typing uses **caret matching**: the characters on either side of the
|
|
|
391
412
|
caret keep their identity, so inserting a `9` into `12|34` slides `34` over
|
|
392
413
|
rather than renumbering the columns.
|
|
393
414
|
|
|
415
|
+
### The keyboard across screens and lists
|
|
416
|
+
|
|
417
|
+
Held against iOS Contacts and Samsung's Settings and Contacts, a NitroInput
|
|
418
|
+
screen behaves like theirs with these settings:
|
|
419
|
+
|
|
420
|
+
- **Coming back to a screen whose field had the keyboard**: on iOS the field
|
|
421
|
+
gets its focus and the keyboard back once the screen has settled (swipe-back
|
|
422
|
+
too), so the real keyboard rises from the bottom as in Contacts rather than
|
|
423
|
+
sliding in with the screen as iOS 26's dark snapshot; on Android the
|
|
424
|
+
keyboard stays down. Native-stack does both by itself
|
|
425
|
+
as long as `keyboardHandlingEnabled` stays off, its default. Turned on
|
|
426
|
+
(react-native-screens' `hideKeyboardOnSwipe`), it takes the focus away as
|
|
427
|
+
the screen starts to leave, and there is nothing to give back.
|
|
428
|
+
- **The keyboard's Next key**: `returnKeyType="next"` with
|
|
429
|
+
`submitBehavior="submit"`, and `onSubmitEditing` focusing the next field.
|
|
430
|
+
The keyboard stays up between fields. On iOS's number, phone and decimal
|
|
431
|
+
pads, which have no return key, the field shows a bar with that key.
|
|
432
|
+
- **Lists and forms**: `keyboardShouldPersistTaps="handled"`, so a tap on a
|
|
433
|
+
row works while the keyboard is up (React Native's default spends the first
|
|
434
|
+
tap on closing it), and `keyboardDismissMode="on-drag"` to close the
|
|
435
|
+
keyboard when the list is dragged.
|
|
436
|
+
- **A field that leaves while it has the keyboard** (its step replaced, a
|
|
437
|
+
screen popped back to one that focuses its own field): `keyboardHandoffMs`
|
|
438
|
+
keeps the keyboard up for the next field instead of dropping and raising it.
|
|
439
|
+
Coming back to a screen whose field had the keyboard still gives it back:
|
|
440
|
+
that field takes it over from the stand-in.
|
|
441
|
+
- **A button riding the keyboard** (keyboard-controller's
|
|
442
|
+
`KeyboardStickyView`): measured frame by frame on an iPhone 11 Pro and a
|
|
443
|
+
Galaxy A22, it follows the keyboard through opening, closing, a keyboard
|
|
444
|
+
that changes height between fields (text, email, number and phone pads, a
|
|
445
|
+
TextInput in between) and a push to a screen that focuses its own field,
|
|
446
|
+
the same with NitroInput as with TextInput. On a number pad, pass
|
|
447
|
+
`returnKeyBar={false}` when the screen's own button is the keyboard's
|
|
448
|
+
action, or iOS shows two.
|
|
449
|
+
|
|
450
|
+
```tsx
|
|
451
|
+
<Stack.Navigator>{/* keyboardHandlingEnabled left off */}</Stack.Navigator>
|
|
452
|
+
|
|
453
|
+
<FlatList keyboardShouldPersistTaps="handled" keyboardDismissMode="on-drag" … />
|
|
454
|
+
|
|
455
|
+
<NitroInput returnKeyType="next" submitBehavior="submit" onSubmitEditing={() => next.current?.focus()} />
|
|
456
|
+
```
|
|
457
|
+
|
|
394
458
|
## NitroInput props
|
|
395
459
|
|
|
396
460
|
| Prop | Type | Default | Description |
|
|
@@ -402,10 +466,16 @@ rather than renumbering the columns.
|
|
|
402
466
|
| `maxIntegerDigits` | `number` | `15` | `number`: most integer digits accepted; further digits are rejected. |
|
|
403
467
|
| `groupingSeparator` | `string` | `','` | `number`: every three integer digits; `''` disables grouping. |
|
|
404
468
|
| `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, `_
|
|
469
|
+
| `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
470
|
| `maskNotations` | `{ character, characterSet, isOptional }[]` | `[]` | `mask`: caller-defined slots beyond the built-ins. |
|
|
407
471
|
| `maskAutocomplete` | `boolean` | `true` | `mask`: insert literals as soon as the slot before them is filled. Only while the caret is at the end. |
|
|
408
472
|
| `maskAutoSkip` | `boolean` | `false` | `mask`: let a backspace step back over inserted literals. |
|
|
473
|
+
| `keepPlaceholder` | `boolean` | `false` | `mask`: keep the rest of the placeholder (or, without one, the mask) greyed after the typed text. |
|
|
474
|
+
| `maskSlotPlaceholder` | `string` | `'_'` with `keepPlaceholder`, else `''` | `mask`: what an empty slot shows in the kept placeholder and `onChangeMask`'s tail. |
|
|
475
|
+
| `maskAffinityFormats` | `string[]` | `[]` | `mask`: more patterns the text may take; the best one wins each edit, `mask` wins ties. |
|
|
476
|
+
| `maskAffinityStrategy` | `'wholeString' \| 'prefix' \| 'capacity' \| 'extractedValueCapacity'` | `'wholeString'` | `mask`: how the best of `maskAffinityFormats` is chosen. |
|
|
477
|
+
| `maskTextCase` | `'none' \| 'upper' \| 'lower'` | `'none'` | `mask`: fold letters as they are typed or pasted. |
|
|
478
|
+
| `maskCharacterMap` | `Record<string, string>` | `{}` | `mask`: characters replaced before masking (`{ ',': '.' }`); an empty replacement drops one. |
|
|
409
479
|
| `variant` | `'none' \| 'outlined' \| 'filled'` | `'none'` | Draws a frame for itself. The outlined notch is a real hole in the stroke. |
|
|
410
480
|
| `label` | `string` | `''` | Floating label. Also becomes the field's accessible name when nothing else gives it one. |
|
|
411
481
|
| `labelBehavior` | `'float' \| 'always'` | `'float'` | `always` keeps it floated even when empty and blurred. |
|
|
@@ -464,6 +534,8 @@ rather than renumbering the columns.
|
|
|
464
534
|
| `showSoftInputOnFocus` | `boolean` | `true` | `false` focuses, with the caret, but shows no keyboard. |
|
|
465
535
|
| `selectTextOnFocus` | `boolean` | `false` | Select everything when the field gains focus. |
|
|
466
536
|
| `clearTextOnFocus` | `boolean` | `false` | Empty the field when it gains focus. |
|
|
537
|
+
| `returnKeyBar` | `boolean` | `true` | iOS: on the number, phone and decimal pads, which have no return key, a bar over the keyboard with the `returnKeyType` key ("Next", "Done"…), as `TextInput` shows. `false` for a screen with its own button riding the keyboard. |
|
|
538
|
+
| `keyboardHandoffMs` | `number` | `0` | When the focused field is popped or unmounted, keep the keyboard up this long for the next field to take over, instead of it dropping and rising again. 300-500 covers a stack pop. |
|
|
467
539
|
| `contextMenuHidden` | `boolean` | `false` | Hides the Cut / Copy / Paste menu. |
|
|
468
540
|
| `editable` | `boolean` | `true` | |
|
|
469
541
|
| `readOnly` | `boolean` | `false` | Alias of `editable={false}`, as on `TextInput`. |
|
|
@@ -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
|
|
@@ -229,6 +241,10 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
229
241
|
set(v) { field = v; markConfigDirty() }
|
|
230
242
|
override var clearTextOnFocus: Boolean = false
|
|
231
243
|
set(v) { field = v; markConfigDirty() }
|
|
244
|
+
// iOS only: Android's number pads have an action key of their own.
|
|
245
|
+
override var returnKeyBar: Boolean = true
|
|
246
|
+
override var keyboardHandoffMs: Double = 0.0
|
|
247
|
+
set(v) { field = v; markConfigDirty() }
|
|
232
248
|
override var contextMenuHidden: Boolean = false
|
|
233
249
|
set(v) { field = v; markConfigDirty() }
|
|
234
250
|
override var spellCheck: Boolean = true
|
|
@@ -280,6 +296,15 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
280
296
|
|
|
281
297
|
override fun blur() = onMain { inputView.blur() }
|
|
282
298
|
|
|
299
|
+
override fun prepareForUnmount() {
|
|
300
|
+
if (Looper.myLooper() == Looper.getMainLooper()) {
|
|
301
|
+
inputView.handOffKeyboardIfFocused()
|
|
302
|
+
return
|
|
303
|
+
}
|
|
304
|
+
// Before the frame that removes the view (see UnmountHandoffs).
|
|
305
|
+
if (!UnmountHandoffs.request(context, inputView)) onMain { inputView.handOffKeyboardIfFocused() }
|
|
306
|
+
}
|
|
307
|
+
|
|
283
308
|
override fun clear() = onMain {
|
|
284
309
|
flushConfigIfNeeded()
|
|
285
310
|
inputView.clear()
|
|
@@ -373,6 +398,12 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
373
398
|
maskNotations = emptyArray()
|
|
374
399
|
maskAutocomplete = true
|
|
375
400
|
maskAutoSkip = false
|
|
401
|
+
maskAffinityFormats = emptyArray()
|
|
402
|
+
maskAffinityStrategy = NitroInputMaskAffinity.WHOLESTRING
|
|
403
|
+
maskTextCase = NitroInputTextCase.NONE
|
|
404
|
+
maskCharacterMap = emptyArray()
|
|
405
|
+
maskSlotPlaceholder = ""
|
|
406
|
+
keepPlaceholder = false
|
|
376
407
|
mode = NitroInputMode.TEXT
|
|
377
408
|
fractionDigits = 2.0
|
|
378
409
|
maxIntegerDigits = 15.0
|
|
@@ -442,6 +473,8 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
442
473
|
showSoftInputOnFocus = true
|
|
443
474
|
selectTextOnFocus = false
|
|
444
475
|
clearTextOnFocus = false
|
|
476
|
+
keyboardHandoffMs = 0.0
|
|
477
|
+
returnKeyBar = true
|
|
445
478
|
contextMenuHidden = false
|
|
446
479
|
spellCheck = true
|
|
447
480
|
selectionStart = -1.0
|
|
@@ -537,16 +570,21 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
537
570
|
}
|
|
538
571
|
|
|
539
572
|
/**
|
|
540
|
-
* The `text` / `mostRecentEventCount` handshake:
|
|
541
|
-
*
|
|
542
|
-
*
|
|
573
|
+
* The `text` / `mostRecentEventCount` handshake: `text` is applied only once
|
|
574
|
+
* JS has seen every native edit (a stale count means the user typed since,
|
|
575
|
+
* and the field already shows what they typed). Compared with what the field
|
|
576
|
+
* shows, not just the last value applied: a controlled parent that keeps its
|
|
577
|
+
* value while the user types (a rejected edit) puts its text back, as
|
|
578
|
+
* `TextInput` does; `applyText` leaves the field alone when the conformed
|
|
579
|
+
* value is already there. An uncontrolled field sends a count of 0, so its
|
|
580
|
+
* initial text is never re-applied over what the user typed.
|
|
543
581
|
*/
|
|
544
582
|
private fun flushTextIfNeeded() {
|
|
545
583
|
if (!textDirty) return
|
|
546
584
|
textDirty = false
|
|
547
585
|
val value = text
|
|
548
|
-
if (lastAppliedText == value) return
|
|
549
586
|
if (mostRecentEventCount < eventCount) return
|
|
587
|
+
if (lastAppliedText == value && inputView.text == value) return
|
|
550
588
|
lastAppliedText = value
|
|
551
589
|
inputView.applyText(value)
|
|
552
590
|
cachedText = inputView.text
|
|
@@ -570,6 +608,12 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
570
608
|
},
|
|
571
609
|
maskAutocomplete = maskAutocomplete,
|
|
572
610
|
maskAutoSkip = maskAutoSkip,
|
|
611
|
+
maskAffinityFormats = maskAffinityFormats.toList(),
|
|
612
|
+
maskAffinityStrategy = maskAffinityStrategy.value,
|
|
613
|
+
maskTextCase = maskTextCase.value,
|
|
614
|
+
maskCharacterMap = maskCharacterMap.map { NitroInputView.MaskMapping(it.from, it.to) },
|
|
615
|
+
maskSlotPlaceholder = maskSlotPlaceholder,
|
|
616
|
+
keepPlaceholder = keepPlaceholder,
|
|
573
617
|
fractionDigits = clampInt(fractionDigits, 0, 9, 2),
|
|
574
618
|
maxIntegerDigits = clampInt(maxIntegerDigits, 1, 30, 15),
|
|
575
619
|
groupingSeparator = groupingSeparator,
|
|
@@ -674,6 +718,7 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
|
|
|
674
718
|
NitroInputSubmitBehavior.NEWLINE -> NitroInputView.SubmitBehavior.NEWLINE
|
|
675
719
|
},
|
|
676
720
|
secureTextEntry = secureTextEntry,
|
|
721
|
+
keyboardHandoffMs = if (keyboardHandoffMs.isFinite()) keyboardHandoffMs.coerceAtLeast(0.0) else 0.0,
|
|
677
722
|
autofillHint = autofillHintFor(textContentType),
|
|
678
723
|
showSoftInputOnFocus = showSoftInputOnFocus,
|
|
679
724
|
selectTextOnFocus = selectTextOnFocus,
|
|
@@ -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
|
}
|