@r5n/otp-react-native 0.0.0-stage → 8.0.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/LICENSE +21 -0
  3. package/README.md +227 -2
  4. package/lib/commonjs/Cell.js +140 -0
  5. package/lib/commonjs/Cell.js.map +1 -0
  6. package/lib/commonjs/OtpInput.js +129 -0
  7. package/lib/commonjs/OtpInput.js.map +1 -0
  8. package/lib/commonjs/accessibility.js +90 -0
  9. package/lib/commonjs/accessibility.js.map +1 -0
  10. package/lib/commonjs/clipboard.js +197 -0
  11. package/lib/commonjs/clipboard.js.map +1 -0
  12. package/lib/commonjs/dev.js +63 -0
  13. package/lib/commonjs/dev.js.map +1 -0
  14. package/lib/commonjs/hiddenInput.js +95 -0
  15. package/lib/commonjs/hiddenInput.js.map +1 -0
  16. package/lib/commonjs/index.js +53 -0
  17. package/lib/commonjs/index.js.map +1 -0
  18. package/lib/commonjs/legacy.js +217 -0
  19. package/lib/commonjs/legacy.js.map +1 -0
  20. package/lib/commonjs/managedProps.js +73 -0
  21. package/lib/commonjs/managedProps.js.map +1 -0
  22. package/lib/commonjs/package.json +1 -0
  23. package/lib/commonjs/types.js +45 -0
  24. package/lib/commonjs/types.js.map +1 -0
  25. package/lib/commonjs/useOtpController.js +70 -0
  26. package/lib/commonjs/useOtpController.js.map +1 -0
  27. package/lib/commonjs/useOtpInput.js +251 -0
  28. package/lib/commonjs/useOtpInput.js.map +1 -0
  29. package/lib/module/Cell.js +103 -0
  30. package/lib/module/Cell.js.map +1 -0
  31. package/lib/module/OtpInput.js +94 -0
  32. package/lib/module/OtpInput.js.map +1 -0
  33. package/lib/module/accessibility.js +49 -0
  34. package/lib/module/accessibility.js.map +1 -0
  35. package/lib/module/clipboard.js +156 -0
  36. package/lib/module/clipboard.js.map +1 -0
  37. package/lib/module/dev.js +22 -0
  38. package/lib/module/dev.js.map +1 -0
  39. package/lib/module/hiddenInput.js +54 -0
  40. package/lib/module/hiddenInput.js.map +1 -0
  41. package/lib/module/index.js +14 -0
  42. package/lib/module/index.js.map +1 -0
  43. package/lib/module/legacy.js +187 -0
  44. package/lib/module/legacy.js.map +1 -0
  45. package/lib/module/managedProps.js +32 -0
  46. package/lib/module/managedProps.js.map +1 -0
  47. package/lib/module/types.js +3 -0
  48. package/lib/module/types.js.map +1 -0
  49. package/lib/module/useOtpController.js +29 -0
  50. package/lib/module/useOtpController.js.map +1 -0
  51. package/lib/module/useOtpInput.js +216 -0
  52. package/lib/module/useOtpInput.js.map +1 -0
  53. package/lib/typescript/commonjs/package.json +1 -0
  54. package/lib/typescript/commonjs/src/Cell.d.ts +39 -0
  55. package/lib/typescript/commonjs/src/Cell.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/OtpInput.d.ts +12 -0
  57. package/lib/typescript/commonjs/src/OtpInput.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/accessibility.d.ts +39 -0
  59. package/lib/typescript/commonjs/src/accessibility.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/clipboard.d.ts +9 -0
  61. package/lib/typescript/commonjs/src/clipboard.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/src/dev.d.ts +13 -0
  63. package/lib/typescript/commonjs/src/dev.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/src/hiddenInput.d.ts +31 -0
  65. package/lib/typescript/commonjs/src/hiddenInput.d.ts.map +1 -0
  66. package/lib/typescript/commonjs/src/index.d.ts +11 -0
  67. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  68. package/lib/typescript/commonjs/src/legacy.d.ts +78 -0
  69. package/lib/typescript/commonjs/src/legacy.d.ts.map +1 -0
  70. package/lib/typescript/commonjs/src/managedProps.d.ts +5 -0
  71. package/lib/typescript/commonjs/src/managedProps.d.ts.map +1 -0
  72. package/lib/typescript/commonjs/src/types.d.ts +262 -0
  73. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  74. package/lib/typescript/commonjs/src/useOtpController.d.ts +28 -0
  75. package/lib/typescript/commonjs/src/useOtpController.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/useOtpInput.d.ts +22 -0
  77. package/lib/typescript/commonjs/src/useOtpInput.d.ts.map +1 -0
  78. package/lib/typescript/module/src/Cell.d.ts +39 -0
  79. package/lib/typescript/module/src/Cell.d.ts.map +1 -0
  80. package/lib/typescript/module/src/OtpInput.d.ts +12 -0
  81. package/lib/typescript/module/src/OtpInput.d.ts.map +1 -0
  82. package/lib/typescript/module/src/accessibility.d.ts +39 -0
  83. package/lib/typescript/module/src/accessibility.d.ts.map +1 -0
  84. package/lib/typescript/module/src/clipboard.d.ts +9 -0
  85. package/lib/typescript/module/src/clipboard.d.ts.map +1 -0
  86. package/lib/typescript/module/src/dev.d.ts +13 -0
  87. package/lib/typescript/module/src/dev.d.ts.map +1 -0
  88. package/lib/typescript/module/src/hiddenInput.d.ts +31 -0
  89. package/lib/typescript/module/src/hiddenInput.d.ts.map +1 -0
  90. package/lib/typescript/module/src/index.d.ts +11 -0
  91. package/lib/typescript/module/src/index.d.ts.map +1 -0
  92. package/lib/typescript/module/src/legacy.d.ts +78 -0
  93. package/lib/typescript/module/src/legacy.d.ts.map +1 -0
  94. package/lib/typescript/module/src/managedProps.d.ts +5 -0
  95. package/lib/typescript/module/src/managedProps.d.ts.map +1 -0
  96. package/lib/typescript/module/src/types.d.ts +262 -0
  97. package/lib/typescript/module/src/types.d.ts.map +1 -0
  98. package/lib/typescript/module/src/useOtpController.d.ts +28 -0
  99. package/lib/typescript/module/src/useOtpController.d.ts.map +1 -0
  100. package/lib/typescript/module/src/useOtpInput.d.ts +22 -0
  101. package/lib/typescript/module/src/useOtpInput.d.ts.map +1 -0
  102. package/package.json +102 -4
  103. package/src/Cell.tsx +146 -0
  104. package/src/OtpInput.tsx +120 -0
  105. package/src/accessibility.ts +86 -0
  106. package/src/clipboard.ts +232 -0
  107. package/src/dev.ts +33 -0
  108. package/src/hiddenInput.ts +80 -0
  109. package/src/index.ts +38 -0
  110. package/src/legacy.tsx +317 -0
  111. package/src/managedProps.ts +29 -0
  112. package/src/types.ts +299 -0
  113. package/src/useOtpController.ts +58 -0
  114. package/src/useOtpInput.ts +313 -0
@@ -0,0 +1,31 @@
1
+ import type { ResolvedOtpOptions } from '@r5n/otp-core';
2
+ import { type TextInputProps, type TextStyle } from 'react-native';
3
+ import type { OtpInputAutoComplete } from './types.js';
4
+ /**
5
+ * Functional style of the hidden `TextInput` (orchestrator decision P1, `rn-platform.md` Q2).
6
+ * - Literal absolute positioning with zero insets: `StyleSheet.absoluteFillObject` no longer
7
+ * exists in React Native 0.88.
8
+ * - `opacity: 0.02`: iOS ignores touches on views below 0.01 (no tap focus, no long-press Paste),
9
+ * and Android treats alpha 0 as invisible (no autofill session, no TalkBack).
10
+ * - Transparent colours hide the text at that opacity; `fontSize: 1` makes taps land after the
11
+ * text, so the native caret stays at the end.
12
+ * - No `lineHeight`, `letterSpacing` or `fontFamily`: fewer attribute writes on the focused iOS
13
+ * field, which can drop fast keystrokes (`rn-platform.md` Q5, RN #58904).
14
+ */
15
+ export declare const HIDDEN_INPUT_STYLE: TextStyle;
16
+ interface HiddenInputOptions {
17
+ options: ResolvedOtpOptions;
18
+ autoComplete: OtpInputAutoComplete;
19
+ keyboardType: TextInputProps['keyboardType'];
20
+ }
21
+ /**
22
+ * Platform props of the hidden input (P2, `rn-platform.md` Q1). Deliberately absent:
23
+ * `maxLength` (native truncation cuts pastes and autofill before JavaScript sees them, G1),
24
+ * `inputMode` (it would override `keyboardType`), `caretHidden` and `contextMenuHidden` (they
25
+ * remove the long-press Paste/AutoFill menu), `secureTextEntry` (masking is visual; on iOS it can
26
+ * bring up the Strong Password UI) and a controlled `selection` (it races fast typing, P3).
27
+ * Predictive text and the keyboard's learning are off through `autoCorrect`/`spellCheck`.
28
+ */
29
+ export declare const hiddenInputProps: ({ options, autoComplete, keyboardType, }: HiddenInputOptions) => TextInputProps;
30
+ export {};
31
+ //# sourceMappingURL=hiddenInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hiddenInput.d.ts","sourceRoot":"","sources":["../../../../src/hiddenInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAY,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAW/B,CAAC;AAEH,UAAU,kBAAkB;IAC1B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,YAAY,EAAE,oBAAoB,CAAC;IACnC,YAAY,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;CAC9C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,6CAI1B,kBAAkB,KAAG,cAiCvB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@r5n/otp-react-native`: one-time code input for React Native, built on `@r5n/otp-core`.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export type { OtpCasing, OtpCharset, OtpController, OtpSelection, OtpSlot, OtpSnapshot, } from '@r5n/otp-core';
7
+ export { OtpInputs as default, type OtpInputsProps, type OtpInputsRef, type OtpLegacyClipboard, } from './legacy.js';
8
+ export { OtpInput } from './OtpInput.js';
9
+ export type { OtpCellProps, OtpClipboardProvider, OtpDecorationProps, OtpHiddenInputProps, OtpInputAccessibilityTexts, OtpInputAutoComplete, OtpInputCellState, OtpInputDirection, OtpInputProps, OtpInputRef, OtpTextInputProps, OtpTextInputRef, UseOtpInputOptions, UseOtpInputResult, } from './types.js';
10
+ export { useOtpInput } from './useOtpInput.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,SAAS,EACT,UAAU,EACV,aAAa,EACb,YAAY,EACZ,OAAO,EACP,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,IAAI,OAAO,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { type KeyboardTypeOptions, type StyleProp, type TextInputProps, type TextStyle, type ViewStyle } from 'react-native';
2
+ import type { OtpClipboardProvider } from './types.js';
3
+ /** Clipboard module for the v7 wrapper, for example `@react-native-clipboard/clipboard`. */
4
+ export type OtpLegacyClipboard = Pick<OtpClipboardProvider, 'getString' | 'hasString'>;
5
+ /**
6
+ * Props of the deprecated v7-compatible default export.
7
+ * @deprecated Use `OtpInputProps` with the named `OtpInput` export.
8
+ */
9
+ export interface OtpInputsProps extends Omit<TextInputProps, 'style' | 'keyboardType' | 'defaultValue'> {
10
+ /** Maps to `length`. Default `4`. */
11
+ numberOfInputs?: number | undefined;
12
+ /** Maps to `onChange`. */
13
+ handleChange?: ((otpCode: string) => void) | undefined;
14
+ /**
15
+ * Fills the code, as in v7: shown at mount (and reported through `handleChange`), and every
16
+ * later non-empty change is applied as if entered (`handleChange`, then `onComplete` behaviour).
17
+ */
18
+ defaultValue?: string | undefined;
19
+ /**
20
+ * Reads the clipboard through `clipboard`, which is required since v8 (no native dependency).
21
+ * Default: on when `clipboard` is given.
22
+ */
23
+ autofillFromClipboard?: boolean | undefined;
24
+ /** Also read the clipboard at this interval while focused and incomplete. */
25
+ autofillListenerIntervalMS?: number | undefined;
26
+ /** New in v8: the clipboard module to read from (only read, never written). */
27
+ clipboard?: OtpLegacyClipboard | undefined;
28
+ /** Default `'phone-pad'`, as in v7. */
29
+ keyboardType?: KeyboardTypeOptions | undefined;
30
+ /**
31
+ * Hides the code. The cells always show `•` (`mask`).
32
+ *
33
+ * - Android: the hidden input is also a real secure field (`secureTextEntry`), as in v7.4.0, so
34
+ * TalkBack and other accessibility services do not get the code. Android treats only text and
35
+ * number fields as passwords, so `keyboardType` `'phone-pad'` (the default) becomes
36
+ * `'number-pad'`.
37
+ * - iOS: mask only. A secure iOS field clears itself when typing resumes after a refocus (with
38
+ * one input that would erase the whole code), and it can offer the Strong Password UI.
39
+ *
40
+ * The named `OtpInput` export does not do this; it takes `secureTextEntry` as an opt-in through
41
+ * `textInputProps`.
42
+ */
43
+ secureTextEntry?: boolean | undefined;
44
+ /** Row of cells. */
45
+ style?: StyleProp<ViewStyle>;
46
+ /** Maps to `focusedCellStyle`. */
47
+ focusStyles?: StyleProp<ViewStyle>;
48
+ /** Maps to `cellStyle`. */
49
+ inputContainerStyles?: StyleProp<ViewStyle>;
50
+ /** Maps to `cellTextStyle`. */
51
+ inputStyles?: StyleProp<TextStyle>;
52
+ /**
53
+ * Reverses the cells, as in v7: the first character is in the right-most cell when `isRTL`
54
+ * differs from `I18nManager.isRTL` (v7 reversed the cells inside a row that React Native mirrors
55
+ * in right-to-left apps). So in a right-to-left app `isRTL` puts the first character on the left.
56
+ * Maps to `direction: 'rtl'` or `'ltr'`.
57
+ */
58
+ isRTL?: boolean | undefined;
59
+ /** Test ID of the hidden input (default `'otpInput'`); cells get `${testIDPrefix}-cell-<index>`. */
60
+ testIDPrefix?: string | undefined;
61
+ }
62
+ /**
63
+ * Ref of the deprecated default export.
64
+ * @deprecated Use `OtpInputRef`.
65
+ */
66
+ export interface OtpInputsRef {
67
+ /** Empties the value and calls `handleChange('')`, also when already empty. Never touches the clipboard. */
68
+ reset(): void;
69
+ focus(): void;
70
+ }
71
+ /**
72
+ * v7-compatible wrapper around {@link OtpInput}, kept for one major version: accepts any
73
+ * character (`charset: 'any'`) and dismisses the keyboard on completion, as v7 did.
74
+ *
75
+ * @deprecated Use the named export: `import { OtpInput } from '@r5n/otp-react-native'`.
76
+ */
77
+ export declare const OtpInputs: import("react").ForwardRefExoticComponent<OtpInputsProps & import("react").RefAttributes<OtpInputsRef>>;
78
+ //# sourceMappingURL=legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../../src/legacy.tsx"],"names":[],"mappings":"AASA,OAAO,EAGL,KAAK,mBAAmB,EAExB,KAAK,SAAS,EAEd,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,oBAAoB,EAAe,MAAM,SAAS,CAAC;AAEjE,4FAA4F;AAC5F,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,oBAAoB,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC;AAEvF;;;GAGG;AACH,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,GAAG,cAAc,CAAC;IACvE,qCAAqC;IACrC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,0BAA0B;IAC1B,YAAY,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACvD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5C,6EAA6E;IAC7E,0BAA0B,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,+EAA+E;IAC/E,SAAS,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC3C,uCAAuC;IACvC,YAAY,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IAC/C;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,oBAAoB;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,kCAAkC;IAClC,WAAW,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACnC,2BAA2B;IAC3B,oBAAoB,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5C,+BAA+B;IAC/B,WAAW,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACnC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,oGAAoG;IACpG,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,4GAA4G;IAC5G,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;CACf;AAqDD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,yGAkKpB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Runtime list of `OtpTextInputManagedProp` (kept equal by the public API type test). */
2
+ export declare const TEXT_INPUT_MANAGED_PROPS: readonly ["value", "defaultValue", "maxLength", "selection", "editable", "readOnly", "caretHidden", "contextMenuHidden", "pointerEvents", "selectTextOnFocus", "clearTextOnFocus", "inputMode"];
3
+ /** Runtime list of `OtpCellManagedProp` (kept equal by the public API type test). */
4
+ export declare const CELL_MANAGED_PROPS: readonly ["children", "style", "testID", "pointerEvents", "aria-hidden", "accessible", "accessibilityElementsHidden", "importantForAccessibility"];
5
+ //# sourceMappingURL=managedProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managedProps.d.ts","sourceRoot":"","sources":["../../../../src/managedProps.ts"],"names":[],"mappings":"AAEA,0FAA0F;AAC1F,eAAO,MAAM,wBAAwB,iMAakB,CAAC;AAExD,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,oJASmB,CAAC"}
@@ -0,0 +1,262 @@
1
+ import type { OtpController, OtpOptions, OtpSnapshot } from '@r5n/otp-core';
2
+ import type { ComponentRef, ReactNode, RefObject } from 'react';
3
+ import type { ColorValue, StyleProp, TextInput, TextInputProps, TextStyle, ViewProps, ViewStyle } from 'react-native';
4
+ /**
5
+ * Layout direction of the row of cells. The value is always stored in logical order; only the
6
+ * row is mirrored.
7
+ * - `'ltr'` (default): codes read left to right, also in right-to-left apps.
8
+ * - `'rtl'`: the first character is in the right-most cell.
9
+ * - `'auto'`: follows `I18nManager.isRTL`.
10
+ */
11
+ export type OtpInputDirection = 'ltr' | 'rtl' | 'auto';
12
+ /**
13
+ * OS one-time-code autofill. `'auto'` (or its alias `'one-time-code'`, the value
14
+ * `@r5n/otp-react` uses) offers SMS codes (iOS `oneTimeCode`, Android `sms-otp`); `'off'` opts the
15
+ * field out of autofill.
16
+ */
17
+ export type OtpInputAutoComplete = 'auto' | 'one-time-code' | 'off';
18
+ /**
19
+ * Clipboard access injected by the app, so the package needs no native clipboard module. Works
20
+ * with `@react-native-clipboard/clipboard` (pass the default export) and `expo-clipboard`
21
+ * (`{ getString: Clipboard.getStringAsync, hasString: Clipboard.hasStringAsync }`).
22
+ */
23
+ export interface OtpClipboardProvider {
24
+ /** Reads the clipboard text. Never written to: the component only reads. */
25
+ getString(): Promise<string>;
26
+ /**
27
+ * Optional cheap check run before `getString`. Returning `false` skips the read, which avoids
28
+ * the iOS 16+ paste prompt when the clipboard has no text. iOS can report no text while it is
29
+ * still presenting the keyboard, so after an empty result on focus or on return to the
30
+ * foreground the clipboard is checked once more about 800 ms later.
31
+ */
32
+ hasString?: (() => Promise<boolean>) | undefined;
33
+ /**
34
+ * Also read every `intervalMs` milliseconds while the input is focused and incomplete. Without
35
+ * it the clipboard is read only on focus and when the app returns to the foreground (plus the
36
+ * one later check described under `hasString`).
37
+ */
38
+ intervalMs?: number | undefined;
39
+ }
40
+ /**
41
+ * Texts read by screen readers. Defaults are English; override them to localise. Announcements
42
+ * are queued behind speech in progress on iOS.
43
+ */
44
+ export interface OtpInputAccessibilityTexts {
45
+ /** Announced when the code becomes complete; `false` disables it. Default `'Code complete'`. */
46
+ complete?: string | false | undefined;
47
+ /**
48
+ * Announced when `error` turns on, and part of the field's accessibility value while it stays
49
+ * on; `false` disables it. Default `'Incorrect code'`. Only a change from `false` to `true` is
50
+ * announced: turn `error` off when the user edits the code, so a second wrong code is announced
51
+ * too.
52
+ */
53
+ error?: string | false | undefined;
54
+ /** Progress part of the field's accessibility value. Default `` `${filled} of ${length} entered` ``. */
55
+ progress?: ((filled: number, length: number) => string) | undefined;
56
+ }
57
+ /** Instance of the hidden native `TextInput`. */
58
+ export type OtpTextInputRef = ComponentRef<typeof TextInput>;
59
+ /**
60
+ * Props of the hidden `TextInput` that the component manages, or that would break paste, autofill
61
+ * or screen readers on it (P1). Passed anyway (from JavaScript or through a cast), they are
62
+ * dropped with a development warning (C:S3-6).
63
+ */
64
+ export type OtpTextInputManagedProp = 'value' | 'defaultValue' | 'maxLength' | 'selection' | 'editable' | 'readOnly' | 'caretHidden' | 'contextMenuHidden' | 'pointerEvents' | 'selectTextOnFocus' | 'clearTextOnFocus' | 'inputMode';
65
+ /**
66
+ * Extra props for the hidden `TextInput` (escape hatch). The props in `OtpTextInputManagedProp`
67
+ * cannot be passed. Overriding the functional props it sets (style,
68
+ * autofill, keyboard) is possible but voids the platform guarantees described in the docs.
69
+ * `secureTextEntry` is allowed as an opt-in that hides the characters from screen readers too, at
70
+ * the cost described in the accessibility docs (iOS clears a secure field when typing resumes after
71
+ * refocusing, and may offer password AutoFill).
72
+ */
73
+ export type OtpTextInputProps = Omit<TextInputProps, OtpTextInputManagedProp>;
74
+ /** Props spread onto the hidden `TextInput` by {@link UseOtpInputResult.inputProps}. */
75
+ export type OtpHiddenInputProps = TextInputProps & {
76
+ ref: RefObject<OtpTextInputRef | null>;
77
+ };
78
+ /**
79
+ * Props of a cell's `View` that keep it out of touches and screen readers (P4). Passed in
80
+ * `cellProps` anyway, they are dropped with a development warning (C:S3-6).
81
+ */
82
+ export type OtpCellManagedProp = 'children' | 'style' | 'testID' | 'pointerEvents' | 'aria-hidden' | 'accessible' | 'accessibilityElementsHidden' | 'importantForAccessibility';
83
+ /** Extra props applied to the `View` of every cell. */
84
+ export type OtpCellProps = Omit<ViewProps, OtpCellManagedProp>;
85
+ /** Props that hide a decorative view from touches and screen readers; see `decorationProps`. */
86
+ export interface OtpDecorationProps {
87
+ readonly pointerEvents: 'none';
88
+ readonly accessibilityElementsHidden: true;
89
+ readonly importantForAccessibility: 'no-hide-descendants';
90
+ }
91
+ /** Render state of one cell: primitives only, so memoised cells re-render only when it changes. */
92
+ export interface OtpInputCellState {
93
+ /** Position of the cell, from 0, in logical order. */
94
+ readonly index: number;
95
+ /** The entered character, `''` when empty. Not masked: render `displayChar` to honour `mask`. */
96
+ readonly char: string;
97
+ /** What the default cell shows: the character, the mask glyph, the placeholder, or `''`. */
98
+ readonly displayChar: string;
99
+ readonly isFilled: boolean;
100
+ /** The caret is on this cell while the input is focused. */
101
+ readonly isActive: boolean;
102
+ /** `displayChar` is the placeholder. */
103
+ readonly isPlaceholder: boolean;
104
+ readonly isMasked: boolean;
105
+ readonly isError: boolean;
106
+ readonly isDisabled: boolean;
107
+ /** Index of the group (see `groups`) the cell belongs to. */
108
+ readonly groupIndex: number;
109
+ readonly isFirstInGroup: boolean;
110
+ readonly isLastInGroup: boolean;
111
+ }
112
+ /** Imperative API of {@link OtpInput} (via `ref`) and of {@link useOtpInput}. */
113
+ export interface OtpInputRef {
114
+ /** Focuses the hidden input (no-op while `disabled`). */
115
+ focus(): void;
116
+ blur(): void;
117
+ /**
118
+ * Empties the value. Fires `onChange('')` only when the value was not already empty. Never
119
+ * touches the clipboard.
120
+ */
121
+ clear(): void;
122
+ /**
123
+ * Sets the value as if the user entered it: fires `onChange` when the value changes and, for a
124
+ * complete code, `onComplete` (in controlled mode, once the parent confirms it; see
125
+ * `onComplete`). `''` clears. Text longer than `length` (an SMS body) is searched for a code;
126
+ * otherwise only a bare code is set (`'12'`, `'123 456'`), and other text (`'Error: 15'`) is
127
+ * ignored: the value stays and no callback fires.
128
+ */
129
+ setValue(value: string): void;
130
+ getValue(): string;
131
+ isFocused(): boolean;
132
+ /**
133
+ * The hidden native `TextInput` instance, for measuring or for native methods the component does
134
+ * not wrap. `null` before mount and after unmount. It reads the current instance on every access,
135
+ * so it stays valid after React re-runs the effects of a mounted input (StrictMode,
136
+ * `<Activity>`). The same name as `OtpInputRef.input` in `@r5n/otp-react` (W:#22). The component
137
+ * owns the value, selection and managed props: change those through this API, not on the
138
+ * instance.
139
+ */
140
+ readonly input: OtpTextInputRef | null;
141
+ }
142
+ /** Behaviour options shared by {@link OtpInput} and {@link useOtpInput}. */
143
+ export interface UseOtpInputOptions extends OtpOptions {
144
+ /**
145
+ * Controlled value. Updates from the parent never fire `onChange`; a change the parent does not
146
+ * accept is reverted on the next render. A parent update fires `onComplete` only to confirm a
147
+ * complete value the user just entered (see `onComplete`).
148
+ */
149
+ value?: string | undefined;
150
+ /** Initial value when uncontrolled. Read once; never fires callbacks. */
151
+ defaultValue?: string | undefined;
152
+ /** Called once per visible change of the value, from the input event (never during render). */
153
+ onChange?: ((value: string) => void) | undefined;
154
+ /**
155
+ * Called when a user action, paste, autofill, clipboard autofill or `ref.setValue()` produces a
156
+ * different complete value. Uncontrolled: right after `onChange`. Controlled (`value` set): after
157
+ * the parent confirms that value, that is, once the next render passes it back as `value`; if
158
+ * the parent passes a different value instead, `onComplete` does not fire.
159
+ */
160
+ onComplete?: ((value: string) => void) | undefined;
161
+ /** Focuses the input one frame after mount (deferred, so it survives navigation transitions). */
162
+ autoFocus?: boolean | undefined;
163
+ /** Makes the input non-editable and reports the disabled state to screen readers. */
164
+ disabled?: boolean | undefined;
165
+ /** Shows the error styles and announces `accessibilityTexts.error` when it turns on. */
166
+ error?: boolean | undefined;
167
+ /**
168
+ * Hides the characters in the cells: `true` shows `•`, a string shows that glyph (`''` means not
169
+ * masked). The value is not changed. Screen readers: on iOS the field's value then reports only
170
+ * progress, but typing echo and the field's text can still speak the characters on both
171
+ * platforms; pass `textInputProps={{ secureTextEntry: true }}` to hide them from assistive
172
+ * technology too (see `OtpTextInputProps`).
173
+ */
174
+ mask?: boolean | string | undefined;
175
+ /**
176
+ * Shown in empty cells. A string of exactly `length` characters gives each cell its own
177
+ * character; any other string is shown whole in every empty cell.
178
+ */
179
+ placeholder?: string | undefined;
180
+ /** Default `'auto'`. */
181
+ autoComplete?: OtpInputAutoComplete | undefined;
182
+ /** Default: `'number-pad'` for the numeric charset, `'default'` otherwise. */
183
+ keyboardType?: TextInputProps['keyboardType'];
184
+ /** Default `'ltr'`. */
185
+ direction?: OtpInputDirection | undefined;
186
+ /** Blurs the input (closing the keyboard) right after `onComplete`. Default `false`. */
187
+ blurOnComplete?: boolean | undefined;
188
+ /** Opt-in clipboard autofill. Default `false`: the clipboard is never read. */
189
+ clipboardAutofill?: false | OtpClipboardProvider | undefined;
190
+ /**
191
+ * Default `'One-time code, <length> digits'`: `digit(s)` for the numeric charset, `letter(s)` for
192
+ * alphabetic, `character(s)` otherwise (for example `'One-time code, 6 digits'`).
193
+ */
194
+ accessibilityLabel?: string | undefined;
195
+ accessibilityHint?: string | undefined;
196
+ accessibilityTexts?: OtpInputAccessibilityTexts | undefined;
197
+ onFocus?: TextInputProps['onFocus'];
198
+ onBlur?: TextInputProps['onBlur'];
199
+ /** See {@link OtpTextInputProps}. */
200
+ textInputProps?: OtpTextInputProps | undefined;
201
+ /** Test ID of the hidden input; cells get `` `${testID}-cell-${index}` ``. */
202
+ testID?: string | undefined;
203
+ }
204
+ /** Everything needed to render a custom code input around the hidden `TextInput`. */
205
+ export interface UseOtpInputResult extends OtpInputRef {
206
+ /** Current state of the core controller (value, selection, slots, completion, focus). */
207
+ snapshot: OtpSnapshot;
208
+ /** Render state of every cell, with `mask`, `placeholder`, `error` and `disabled` applied. */
209
+ cells: readonly OtpInputCellState[];
210
+ /**
211
+ * Spread onto every cell and separator view: hides them from touches and screen readers, so the
212
+ * hidden input stays the only accessibility element (P4, W:#15).
213
+ */
214
+ decorationProps: OtpDecorationProps;
215
+ /**
216
+ * Spread onto a `TextInput` rendered **last** inside the row, so it covers the cells and owns
217
+ * every tap, long-press paste, autofill and screen-reader focus.
218
+ */
219
+ inputProps: OtpHiddenInputProps;
220
+ /** Style for the row that contains the cells and the input (`flexDirection` and `direction`). */
221
+ rowStyle: ViewStyle;
222
+ /** For a `Pressable` around custom cells when the input does not cover them. */
223
+ pressableProps: {
224
+ onPress: () => void;
225
+ disabled: boolean;
226
+ accessible: false;
227
+ };
228
+ /** The underlying `@r5n/otp-core` controller (advanced use). */
229
+ controller: OtpController;
230
+ }
231
+ /** Props of {@link OtpInput}. */
232
+ export interface OtpInputProps extends UseOtpInputOptions {
233
+ /** Row that contains the cells. */
234
+ style?: StyleProp<ViewStyle>;
235
+ cellStyle?: StyleProp<ViewStyle>;
236
+ /** Applied to the active cell while focused. Precedence: cell < filled < focused < error. */
237
+ focusedCellStyle?: StyleProp<ViewStyle>;
238
+ filledCellStyle?: StyleProp<ViewStyle>;
239
+ errorCellStyle?: StyleProp<ViewStyle>;
240
+ /**
241
+ * Style of the cell text. The default colour follows the system colour scheme (`useColorScheme`:
242
+ * near-black in light mode, white in dark mode); set `color` here when the app's theme does not
243
+ * follow the system scheme.
244
+ */
245
+ cellTextStyle?: StyleProp<TextStyle>;
246
+ /** Colour of placeholder characters (applied after `cellTextStyle`). Default `'#8E8E93'`. */
247
+ placeholderTextColor?: ColorValue | undefined;
248
+ /** Style of the spacer between groups (see `groups`). */
249
+ separatorStyle?: StyleProp<ViewStyle>;
250
+ /** Replaces the content of every cell; the cell styles are then not applied. */
251
+ renderCell?: ((state: OtpInputCellState) => ReactNode) | undefined;
252
+ /** Content of the spacer between groups; `groupIndex` is the group before it. */
253
+ renderSeparator?: ((groupIndex: number) => ReactNode) | undefined;
254
+ cellProps?: OtpCellProps | undefined;
255
+ /**
256
+ * Largest font scale of the cell text (Dynamic Type, font size settings). Default `2` (200%,
257
+ * WCAG 1.4.4). The text shrinks to fit its cell (`adjustsFontSizeToFit`, down to half size on
258
+ * iOS), so long codes at the largest sizes get smaller digits instead of clipped ones.
259
+ */
260
+ maxFontSizeMultiplier?: number | undefined;
261
+ }
262
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,EACT,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,eAAe,GAAG,KAAK,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC5E,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IACjD;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,gGAA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C,UAAU,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAAS,CAAC;IAClE,SAAS,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACrC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C"}
@@ -0,0 +1,28 @@
1
+ import type { OtpController, OtpControllerOptions, OtpSnapshot } from '@r5n/otp-core';
2
+ /** Whether an effect cleanup destroyed `controller` (it is about to be replaced). */
3
+ export declare const isDestroyed: (controller: OtpController) => boolean;
4
+ /** Creates a controller; `seed` is the last snapshot of a destroyed one being replaced. */
5
+ export type CreateController = (seed?: OtpSnapshot) => OtpController;
6
+ interface ControllerBinding {
7
+ controller: OtpController;
8
+ snapshot: OtpSnapshot;
9
+ }
10
+ /**
11
+ * Owns the core controller of one mounted input (`rn-platform.md` Q5).
12
+ *
13
+ * - Created in the state initialiser: pure, no subscriptions, so double rendering is harmless.
14
+ * - Destroyed on unmount. When React runs the effects of a component that is still mounted again
15
+ * (StrictMode in development, an `<Activity>` becoming visible), the destroyed controller is
16
+ * replaced by a new one seeded with its last value, so the input never stays dead. Focus is not
17
+ * carried over: the caller reads it from the native input (C:S3-1).
18
+ * - Props are reconciled after every render with `update()` from a layout effect, never during
19
+ * render (core B6). Running it after every render reverts an optimistic edit that a controlled
20
+ * parent did not accept, and confirms a complete one it did: `update()` calls no `onChange`, and
21
+ * calls `onComplete` only for that confirmation (C:S3-4).
22
+ * - Read through `useSyncExternalStore`; the snapshot is stable until something changes.
23
+ *
24
+ * `create` must be stable (it should read the latest props from a ref).
25
+ */
26
+ export declare const useOtpController: (create: CreateController, reconcile: Partial<OtpControllerOptions>) => ControllerBinding;
27
+ export {};
28
+ //# sourceMappingURL=useOtpController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOtpController.d.ts","sourceRoot":"","sources":["../../../../src/useOtpController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAMtF,qFAAqF;AACrF,eAAO,MAAM,WAAW,eAAgB,aAAa,KAAG,OAAoC,CAAC;AAE7F,2FAA2F;AAC3F,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,KAAK,aAAa,CAAC;AAErE,UAAU,iBAAiB;IACzB,UAAU,EAAE,aAAa,CAAC;IAC1B,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,WACnB,gBAAgB,aACb,OAAO,CAAC,oBAAoB,CAAC,KACvC,iBAqBF,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { UseOtpInputOptions, UseOtpInputResult } from './types.js';
2
+ /**
3
+ * Headless code input: the state, cell render data and hidden `TextInput` props behind
4
+ * `OtpInput`, for building a custom layout.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * const otp = useOtpInput({ length: 6, onComplete: verify });
9
+ * return (
10
+ * <View style={otp.rowStyle}>
11
+ * {otp.cells.map((cell) => (
12
+ * <View key={cell.index} {...otp.decorationProps}>
13
+ * <Text>{cell.displayChar}</Text>
14
+ * </View>
15
+ * ))}
16
+ * <TextInput {...otp.inputProps} />
17
+ * </View>
18
+ * );
19
+ * ```
20
+ */
21
+ export declare function useOtpInput(options: UseOtpInputOptions): UseOtpInputResult;
22
+ //# sourceMappingURL=useOtpInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOtpInput.d.ts","sourceRoot":"","sources":["../../../../src/useOtpInput.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAKV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAsCjB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAyO1E"}
package/package.json CHANGED
@@ -1,6 +1,104 @@
1
1
  {
2
2
  "name": "@r5n/otp-react-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "8.0.0",
4
+ "description": "One-time code input for React Native: one native TextInput, any number of visual cells, with OS autofill and paste.",
5
+ "keywords": [
6
+ "otp",
7
+ "otp-input",
8
+ "one-time-password",
9
+ "one-time-code",
10
+ "verification-code",
11
+ "sms",
12
+ "autofill",
13
+ "react-native",
14
+ "expo",
15
+ "inputs"
16
+ ],
17
+ "homepage": "https://github.com/r5n-labs/react-native-otp-inputs/tree/develop/packages/otp-react-native#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/r5n-labs/react-native-otp-inputs/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/r5n-labs/react-native-otp-inputs.git",
24
+ "directory": "packages/otp-react-native"
25
+ },
26
+ "license": "MIT",
27
+ "author": "Damian Sznajder <damsznajder@gmail.com>",
28
+ "contributors": [
29
+ "Michal Kantor <kantorm96@gmail.com>"
30
+ ],
31
+ "r5n": {
32
+ "product": "otp-inputs",
33
+ "kind": "react-native",
34
+ "size": [
35
+ {
36
+ "name": "with @r5n/otp-core (production)",
37
+ "entry": "lib/module/index.js",
38
+ "include": [
39
+ "@r5n/otp-core"
40
+ ],
41
+ "limit": "9.95 kB"
42
+ },
43
+ {
44
+ "name": "alone (production)",
45
+ "entry": "lib/module/index.js",
46
+ "limit": "5.85 kB"
47
+ }
48
+ ]
49
+ },
50
+ "type": "module",
51
+ "sideEffects": false,
52
+ "main": "./lib/commonjs/index.js",
53
+ "module": "./lib/module/index.js",
54
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
55
+ "react-native": "./lib/module/index.js",
56
+ "source": "./src/index.ts",
57
+ "exports": {
58
+ ".": {
59
+ "@r5n/otp-react-native-source": "./src/index.ts",
60
+ "import": {
61
+ "types": "./lib/typescript/module/src/index.d.ts",
62
+ "default": "./lib/module/index.js"
63
+ },
64
+ "require": {
65
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
66
+ "default": "./lib/commonjs/index.js"
67
+ }
68
+ },
69
+ "./package.json": "./package.json"
70
+ },
71
+ "files": [
72
+ "src",
73
+ "lib",
74
+ "CHANGELOG.md",
75
+ "!**/__tests__",
76
+ "!**/__fixtures__",
77
+ "!**/__mocks__"
78
+ ],
79
+ "scripts": {
80
+ "build": "bun ../../tools/build.ts",
81
+ "check": "bun run --bun tsc -p tsconfig.json",
82
+ "test": "bun test --isolate",
83
+ "test:coverage": "bun test --isolate --coverage"
84
+ },
85
+ "dependencies": {
86
+ "@r5n/otp-core": "^0.1.0"
87
+ },
88
+ "peerDependencies": {
89
+ "react": ">=19.2.3",
90
+ "react-native": ">=0.86"
91
+ },
92
+ "devDependencies": {
93
+ "@r5n/test-react-native": "0.0.0",
94
+ "@testing-library/react-native": "^14.1.1",
95
+ "@types/bun": "^1.4.5",
96
+ "@types/react": "^19.3.3",
97
+ "react": "19.3.0",
98
+ "react-native": "0.88.1",
99
+ "test-renderer": "^1.3.1"
100
+ },
101
+ "publishConfig": {
102
+ "access": "public"
103
+ }
104
+ }