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.
@@ -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(nationalDigits, formats);
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(nationalDigits, format);
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
- // Important that `runOnUI` is called first to make sure the UI runtime is initialized.
33
- runOnUI(() => {
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>();