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/src/NitroInput.tsx
CHANGED
|
@@ -37,6 +37,9 @@ import type {
|
|
|
37
37
|
NitroInputSignPlacement,
|
|
38
38
|
NitroInputVariant,
|
|
39
39
|
NitroInputNotation,
|
|
40
|
+
NitroInputMaskAffinity,
|
|
41
|
+
NitroInputTextCase,
|
|
42
|
+
NitroInputCharacterMapping,
|
|
40
43
|
} from './specs/NitroInput.nitro'
|
|
41
44
|
import {
|
|
42
45
|
allocateWorkletId,
|
|
@@ -152,6 +155,8 @@ function reactTagOf(host: unknown): number {
|
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
const EMPTY_NOTATIONS: NitroInputNotation[] = []
|
|
158
|
+
const EMPTY_STRINGS: string[] = []
|
|
159
|
+
const EMPTY_MAPPINGS: NitroInputCharacterMapping[] = []
|
|
155
160
|
|
|
156
161
|
/** Mounted fields, by the host instance React Native's registry stores. */
|
|
157
162
|
const mountedFields = new WeakMap<object, { focus(): void; blur(): void }>()
|
|
@@ -318,6 +323,44 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
|
|
|
318
323
|
maskAutocomplete?: boolean
|
|
319
324
|
/** `'mask'`: backspace walks back over autocompleted constants. Default: `false`. */
|
|
320
325
|
maskAutoSkip?: boolean
|
|
326
|
+
/**
|
|
327
|
+
* `'mask'`: more patterns the text may take, e.g. a 4-6-5 Amex card beside
|
|
328
|
+
* a 4-4-4-4 `mask`: `['{34}[00] [000000] [00000]', '{37}[00] [000000] [00000]']`.
|
|
329
|
+
* Every edit is masked with each and the best, by `maskAffinityStrategy`, is
|
|
330
|
+
* kept; `mask` wins ties.
|
|
331
|
+
*/
|
|
332
|
+
maskAffinityFormats?: string[]
|
|
333
|
+
/**
|
|
334
|
+
* `'mask'`: how the best of `maskAffinityFormats` is chosen. `'wholeString'`
|
|
335
|
+
* the format that accepts the most characters and inserts the fewest,
|
|
336
|
+
* `'prefix'` the one whose output starts most like what was typed,
|
|
337
|
+
* `'capacity'` / `'extractedValueCapacity'` the fullest format that still
|
|
338
|
+
* holds all of the text / all of its value characters. Default: `'wholeString'`.
|
|
339
|
+
*/
|
|
340
|
+
maskAffinityStrategy?: NitroInputMaskAffinity
|
|
341
|
+
/** `'mask'`: uppercases or lowercases letters as they are typed or pasted. Default: `'none'`. */
|
|
342
|
+
maskTextCase?: NitroInputTextCase
|
|
343
|
+
/**
|
|
344
|
+
* `'mask'`: characters replaced before masking, one character each:
|
|
345
|
+
* `{ 'С': 'C' }` turns a Cyrillic look-alike into a Latin letter,
|
|
346
|
+
* `{ ',': '.' }` lets a comma through to a dot-decimal mask. An empty
|
|
347
|
+
* replacement drops the character.
|
|
348
|
+
*/
|
|
349
|
+
maskCharacterMap?: Record<string, string>
|
|
350
|
+
/**
|
|
351
|
+
* `'mask'`: the character each empty slot shows in the kept placeholder and
|
|
352
|
+
* in `onChangeMask`'s tail. Default: `'_'` with `keepPlaceholder`, otherwise
|
|
353
|
+
* the slot's own notation character.
|
|
354
|
+
*/
|
|
355
|
+
maskSlotPlaceholder?: string
|
|
356
|
+
/**
|
|
357
|
+
* `'mask'`: keeps the rest of the placeholder visible after what has been
|
|
358
|
+
* typed: with `placeholder="1234 5678 9012"`, typing "12345" shows
|
|
359
|
+
* "1234 5" and then "678 9012" greyed. Without a `placeholder` the mask
|
|
360
|
+
* itself is shown, its empty slots as `maskSlotPlaceholder`:
|
|
361
|
+
* `+1 (212) ___-____`. Default: `false`.
|
|
362
|
+
*/
|
|
363
|
+
keepPlaceholder?: boolean
|
|
321
364
|
/**
|
|
322
365
|
* `'mask'` mode: called whenever the text changes, from a keystroke,
|
|
323
366
|
* `setText` / `clear` or the `value` prop alike, with the masked text, the
|
|
@@ -698,6 +741,12 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
698
741
|
maskNotations,
|
|
699
742
|
maskAutocomplete,
|
|
700
743
|
maskAutoSkip,
|
|
744
|
+
maskAffinityFormats,
|
|
745
|
+
maskAffinityStrategy,
|
|
746
|
+
maskTextCase,
|
|
747
|
+
maskCharacterMap,
|
|
748
|
+
maskSlotPlaceholder,
|
|
749
|
+
keepPlaceholder,
|
|
701
750
|
returnKeyType,
|
|
702
751
|
autoCapitalize,
|
|
703
752
|
autoCorrect,
|
|
@@ -1122,6 +1171,24 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1122
1171
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1123
1172
|
[notationsKey]
|
|
1124
1173
|
)
|
|
1174
|
+
// The same for the affinity formats and the character map.
|
|
1175
|
+
const affinityKey =
|
|
1176
|
+
maskAffinityFormats != null && maskAffinityFormats.length > 0 ? JSON.stringify(maskAffinityFormats) : ''
|
|
1177
|
+
const stableAffinityFormats = useMemo(
|
|
1178
|
+
() => (affinityKey !== '' && maskAffinityFormats ? [...maskAffinityFormats] : EMPTY_STRINGS),
|
|
1179
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1180
|
+
[affinityKey]
|
|
1181
|
+
)
|
|
1182
|
+
const characterMapKey =
|
|
1183
|
+
maskCharacterMap != null && Object.keys(maskCharacterMap).length > 0 ? JSON.stringify(maskCharacterMap) : ''
|
|
1184
|
+
const stableCharacterMap = useMemo<NitroInputCharacterMapping[]>(
|
|
1185
|
+
() =>
|
|
1186
|
+
characterMapKey !== '' && maskCharacterMap
|
|
1187
|
+
? Object.entries(maskCharacterMap).map(([from, to]) => ({ from, to }))
|
|
1188
|
+
: EMPTY_MAPPINGS,
|
|
1189
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1190
|
+
[characterMapKey]
|
|
1191
|
+
)
|
|
1125
1192
|
const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2
|
|
1126
1193
|
const resolvedKeyboardType =
|
|
1127
1194
|
keyboardType ??
|
|
@@ -1275,6 +1342,12 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1275
1342
|
maskNotations={stableNotations}
|
|
1276
1343
|
maskAutocomplete={maskAutocomplete ?? true}
|
|
1277
1344
|
maskAutoSkip={maskAutoSkip ?? false}
|
|
1345
|
+
maskAffinityFormats={stableAffinityFormats}
|
|
1346
|
+
maskAffinityStrategy={maskAffinityStrategy ?? 'wholeString'}
|
|
1347
|
+
maskTextCase={maskTextCase ?? 'none'}
|
|
1348
|
+
maskCharacterMap={stableCharacterMap}
|
|
1349
|
+
maskSlotPlaceholder={maskSlotPlaceholder ?? (keepPlaceholder ? '_' : '')}
|
|
1350
|
+
keepPlaceholder={keepPlaceholder ?? false}
|
|
1278
1351
|
onChangeMask={onChangeMaskCallback}
|
|
1279
1352
|
keyboardType={resolvedKeyboardType}
|
|
1280
1353
|
returnKeyType={resolvedReturnKeyType}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,24 @@ import type {
|
|
|
11
11
|
*/
|
|
12
12
|
export type NitroInputMode = 'text' | 'number' | 'mask'
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* How the best of `maskAffinityFormats` is chosen for the text in the field:
|
|
16
|
+
* `'wholeString'` the format that accepts the most characters and inserts the
|
|
17
|
+
* fewest, `'prefix'` the one whose output starts most like what was typed,
|
|
18
|
+
* `'capacity'` / `'extractedValueCapacity'` the fullest format that still
|
|
19
|
+
* holds all of the text / all of its value characters.
|
|
20
|
+
*/
|
|
21
|
+
export type NitroInputMaskAffinity = 'wholeString' | 'prefix' | 'capacity' | 'extractedValueCapacity'
|
|
22
|
+
|
|
23
|
+
/** How letters are cased as they are typed into a mask. */
|
|
24
|
+
export type NitroInputTextCase = 'none' | 'upper' | 'lower'
|
|
25
|
+
|
|
26
|
+
/** One character replaced by another before masking; an empty `to` drops it. */
|
|
27
|
+
export interface NitroInputCharacterMapping {
|
|
28
|
+
from: string
|
|
29
|
+
to: string
|
|
30
|
+
}
|
|
31
|
+
|
|
14
32
|
/**
|
|
15
33
|
* A caller-defined slot character for `mask`, beyond the built-in
|
|
16
34
|
* `0 9 A a _ - …`. `characterSet` lists every character the slot accepts.
|
|
@@ -175,6 +193,34 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
175
193
|
* Default: `false`.
|
|
176
194
|
*/
|
|
177
195
|
maskAutoSkip: boolean
|
|
196
|
+
/**
|
|
197
|
+
* `'mask'`: more patterns the text may take, e.g. a 4-6-5 Amex card beside
|
|
198
|
+
* a 4-4-4-4 `mask`. Every edit is masked with each and the best, by
|
|
199
|
+
* `maskAffinityStrategy`, is kept; `mask` wins ties. Default: none.
|
|
200
|
+
*/
|
|
201
|
+
maskAffinityFormats: string[]
|
|
202
|
+
/** `'mask'`: how the best of `maskAffinityFormats` is chosen. Default: `'wholeString'`. */
|
|
203
|
+
maskAffinityStrategy: NitroInputMaskAffinity
|
|
204
|
+
/** `'mask'`: uppercases or lowercases letters as they are typed or pasted. Default: `'none'`. */
|
|
205
|
+
maskTextCase: NitroInputTextCase
|
|
206
|
+
/**
|
|
207
|
+
* `'mask'`: characters replaced before masking, e.g. a Cyrillic "С" with a
|
|
208
|
+
* Latin "C", or "," with "." for a decimal mask. Default: none.
|
|
209
|
+
*/
|
|
210
|
+
maskCharacterMap: NitroInputCharacterMapping[]
|
|
211
|
+
/**
|
|
212
|
+
* `'mask'`: the character each empty slot shows in the kept placeholder and
|
|
213
|
+
* in `onChangeMask`'s tail, e.g. `'_'`. Empty: the slot's own notation
|
|
214
|
+
* character. Default: `''`.
|
|
215
|
+
*/
|
|
216
|
+
maskSlotPlaceholder: string
|
|
217
|
+
/**
|
|
218
|
+
* `'mask'`: keeps the rest of the placeholder visible after what has been
|
|
219
|
+
* typed, so "1234 5" shows "678 9012" greyed after it. Without a
|
|
220
|
+
* `placeholder`, the mask itself is shown, empty slots as
|
|
221
|
+
* `maskSlotPlaceholder`: `+1 (212) ___-____`. Default: `false`.
|
|
222
|
+
*/
|
|
223
|
+
keepPlaceholder: boolean
|
|
178
224
|
/** `'number'`: inserted between every three integer digits; empty disables grouping. Default: `','`. */
|
|
179
225
|
groupingSeparator: string
|
|
180
226
|
/** `'number'`: between the integer and fraction digits. Default: `'.'`. */
|