react-native-transformer-text-input 0.1.0-alpha.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/android/src/main/java/com/appandflow/transformertextinput/TransformerTextInputDecoratorView.kt +30 -0
- package/cpp/TransformerTextInputDecoratorViewShadowNode.cpp +24 -1
- package/ios/TransformerTextInputDecoratorView.mm +29 -1
- package/lib/module/TransformerTextInput.js +24 -0
- package/lib/module/TransformerTextInput.js.map +1 -1
- package/lib/module/formatters/currency.js +122 -0
- package/lib/module/formatters/currency.js.map +1 -0
- package/lib/module/formatters/phone-data.js +153 -27
- package/lib/module/formatters/phone-data.js.map +1 -1
- package/lib/module/formatters/phone-number.js +14 -2
- package/lib/module/formatters/phone-number.js.map +1 -1
- package/lib/module/registry.js +4 -3
- package/lib/module/registry.js.map +1 -1
- package/lib/typescript/src/TransformerTextInput.d.ts.map +1 -1
- package/lib/typescript/src/formatters/currency.d.ts +17 -0
- package/lib/typescript/src/formatters/currency.d.ts.map +1 -0
- package/lib/typescript/src/formatters/phone-data.d.ts +1 -0
- package/lib/typescript/src/formatters/phone-data.d.ts.map +1 -1
- package/lib/typescript/src/formatters/phone-number.d.ts.map +1 -1
- package/lib/typescript/src/registry.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/TransformerTextInput.tsx +23 -1
- package/src/formatters/currency.ts +142 -0
- package/src/formatters/phone-data.ts +158 -28
- package/src/formatters/phone-number.ts +18 -2
- package/src/registry.ts +4 -3
|
@@ -265,6 +265,8 @@ export class PhoneNumberTransformer extends Transformer {
|
|
|
265
265
|
|
|
266
266
|
const callingCode = countryData.callingCode;
|
|
267
267
|
const formats = countryData.formats;
|
|
268
|
+
const nationalPrefix = countryData.nationalPrefix ?? '';
|
|
269
|
+
const nationalPrefixLen = nationalPrefix.length;
|
|
268
270
|
const prefix = '+' + callingCode + ' ';
|
|
269
271
|
// Pre-compute these outside the worklet so only simple string/number
|
|
270
272
|
// values are captured in the closure (more reliable across worklet runtimes).
|
|
@@ -353,8 +355,22 @@ export class PhoneNumberTransformer extends Transformer {
|
|
|
353
355
|
finalEnd = adjustedStart - 1;
|
|
354
356
|
}
|
|
355
357
|
|
|
358
|
+
// Strip the national trunk prefix (e.g. "0") before selecting and applying
|
|
359
|
+
// a format — formats describe the national significant number — then
|
|
360
|
+
// re-add it so the displayed digits still line up with the input.
|
|
361
|
+
let significantDigits = nationalDigits;
|
|
362
|
+
let trunkPrefix = '';
|
|
363
|
+
if (
|
|
364
|
+
nationalPrefixLen > 0 &&
|
|
365
|
+
nationalDigits.length > nationalPrefixLen &&
|
|
366
|
+
nationalDigits.startsWith(nationalPrefix)
|
|
367
|
+
) {
|
|
368
|
+
significantDigits = nationalDigits.slice(nationalPrefixLen);
|
|
369
|
+
trunkPrefix = nationalPrefix;
|
|
370
|
+
}
|
|
371
|
+
|
|
356
372
|
// Select format based on leading digits
|
|
357
|
-
const format = selectFormat(
|
|
373
|
+
const format = selectFormat(significantDigits, formats);
|
|
358
374
|
if (!format) {
|
|
359
375
|
// No format available — just show digits
|
|
360
376
|
const result = outputPrefix + nationalDigits;
|
|
@@ -363,7 +379,7 @@ export class PhoneNumberTransformer extends Transformer {
|
|
|
363
379
|
}
|
|
364
380
|
|
|
365
381
|
// Apply the selected format
|
|
366
|
-
const formatted = applyFormat(
|
|
382
|
+
const formatted = trunkPrefix + applyFormat(significantDigits, format);
|
|
367
383
|
const result = outputPrefix + formatted;
|
|
368
384
|
|
|
369
385
|
// Map cursor position
|
package/src/registry.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runOnUI } from 'react-native-worklets';
|
|
1
|
+
import { runOnUI, executeOnUIRuntimeSync } from 'react-native-worklets';
|
|
2
2
|
import NativeTransformerTextInputModule from './NativeTransformerTextInputModule';
|
|
3
3
|
import { type Selection, type Transformer } from './Transformer';
|
|
4
4
|
import { computeUncontrolledSelection, validateSelection } from './selection';
|
|
@@ -29,8 +29,9 @@ function initializeIfNeeded() {
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//
|
|
33
|
-
|
|
32
|
+
// Set up registry on UI runtime synchronously so it is guaranteed to exist
|
|
33
|
+
// when native code accesses it after install().
|
|
34
|
+
executeOnUIRuntimeSync(() => {
|
|
34
35
|
'worklet';
|
|
35
36
|
|
|
36
37
|
const transformersMap = new Map<number, TransformerWrapper>();
|