@asaddevworld/code-input 0.0.0-stage → 0.1.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/LICENSE +20 -0
- package/README.md +105 -2
- package/lib/module/Cell.js +128 -0
- package/lib/module/Cell.js.map +1 -0
- package/lib/module/CodeInput.js +157 -0
- package/lib/module/CodeInput.js.map +1 -0
- package/lib/module/PinPad.js +222 -0
- package/lib/module/PinPad.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useShake.js +35 -0
- package/lib/module/useShake.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Cell.d.ts +15 -0
- package/lib/typescript/src/Cell.d.ts.map +1 -0
- package/lib/typescript/src/CodeInput.d.ts +3 -0
- package/lib/typescript/src/CodeInput.d.ts.map +1 -0
- package/lib/typescript/src/PinPad.d.ts +3 -0
- package/lib/typescript/src/PinPad.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +54 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/useShake.d.ts +10 -0
- package/lib/typescript/src/useShake.d.ts.map +1 -0
- package/package.json +160 -4
- package/src/Cell.tsx +152 -0
- package/src/CodeInput.tsx +187 -0
- package/src/PinPad.tsx +241 -0
- package/src/index.tsx +8 -0
- package/src/types.ts +57 -0
- package/src/useShake.ts +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asad Ali
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rn-code-input
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One-time code and PIN inputs for React Native. `CodeInput` renders animated cells for an OTP or passcode: digits pop in, the row shakes and turns red on a wrong code, SMS autofill works on iOS and Android, and a masked mode shows dots for PINs. `PinPad` is a lock-screen keypad with a dot indicator, an async check, and a biometric key. Animations run with Reanimated.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
https://github.com/user-attachments/assets/aa0f423d-6991-4ef3-be63-567ca21fa531
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
_Demo recorded on the iOS Simulator from the example app: [docs/demo.mp4](docs/demo.mp4)._
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @asaddevworld/code-input react-native-reanimated react-native-worklets
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
With Expo:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx expo install @asaddevworld/code-input react-native-reanimated react-native-worklets
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires React Native 0.76 or newer and Reanimated 4.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { CodeInput, PinPad } from '@asaddevworld/code-input';
|
|
31
|
+
|
|
32
|
+
<CodeInput
|
|
33
|
+
length={6}
|
|
34
|
+
autoFocus
|
|
35
|
+
error={wrong}
|
|
36
|
+
onErrorCleared={() => setWrong(false)}
|
|
37
|
+
onComplete={(code) => verify(code).then((ok) => setWrong(!ok))}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<CodeInput length={4} masked onComplete={savePin} />
|
|
41
|
+
|
|
42
|
+
<PinPad
|
|
43
|
+
length={4}
|
|
44
|
+
biometricLabel="Face ID"
|
|
45
|
+
onBiometric={unlockWithBiometrics}
|
|
46
|
+
onComplete={async (pin) => (await check(pin)) ? true : false}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
### `CodeInput` props
|
|
53
|
+
|
|
54
|
+
| prop | type | default | description |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| `length` | `number` | `6` | Number of cells. |
|
|
57
|
+
| `value` / `defaultValue` | `string` | | Controlled or starting value. |
|
|
58
|
+
| `onChange` | `(code) => void` | | Every change, sanitised and capped. |
|
|
59
|
+
| `onComplete` | `(code) => void` | | Once, when every cell is filled. |
|
|
60
|
+
| `masked` | `boolean` | `false` | Dots instead of characters. |
|
|
61
|
+
| `error` | `boolean` | `false` | Plays the shake, shows red cells, clears the value, then calls `onErrorCleared`. |
|
|
62
|
+
| `autoFocus` | `boolean` | `false` | Focus and show the keyboard on mount. |
|
|
63
|
+
| `keyboardType` | `'number-pad' \| 'default'` | `'number-pad'` | `'default'` allows letters. |
|
|
64
|
+
| `disabled` | `boolean` | `false` | Block input. |
|
|
65
|
+
| `haptics` | `(event: 'tick' \| 'error' \| 'success') => void` | | Hook up any haptics library. |
|
|
66
|
+
| `cellStyle`, `activeCellStyle`, `filledCellStyle`, `errorCellStyle`, `cellTextStyle` | styles | | Appearance per state. |
|
|
67
|
+
| `gap` | `number` | `10` | Space between cells. |
|
|
68
|
+
|
|
69
|
+
The hidden text field sets `textContentType="oneTimeCode"` and `autoComplete="sms-otp"`, so the OS offers codes from messages.
|
|
70
|
+
|
|
71
|
+
### `PinPad` props
|
|
72
|
+
|
|
73
|
+
| prop | type | default | description |
|
|
74
|
+
|---|---|---|---|
|
|
75
|
+
| `length` | `number` | `4` | Digits. |
|
|
76
|
+
| `onComplete` | `(pin) => boolean \| Promise<boolean>` | required | Return `false` to shake and clear. Dots pulse while a promise is pending. |
|
|
77
|
+
| `biometricLabel` | `string` | | Label of the bottom-left key, for example "Face ID". Omit for a blank key. |
|
|
78
|
+
| `onBiometric` | `() => void` | | Pressed the biometric key. |
|
|
79
|
+
| `haptics` | same as above | | |
|
|
80
|
+
| `keySize` | `number` | `72` | Key diameter. |
|
|
81
|
+
| `keyStyle`, `keyTextStyle`, `dotColor`, `errorColor` | | | Appearance. |
|
|
82
|
+
|
|
83
|
+
## Behaviour notes
|
|
84
|
+
|
|
85
|
+
- A digit landing pops its cell (scale 1 → 1.12 → 1) and fades the character in; backspace fades it out.
|
|
86
|
+
- The active cell shows a blinking caret. Tapping anywhere on the row focuses the hidden field.
|
|
87
|
+
- Pasting a full code fills every cell at once.
|
|
88
|
+
- `CodeInput` is one accessible element labelled "Verification code, 3 of 6 digits entered". Keypad keys are buttons.
|
|
89
|
+
- Reduced motion shortens the animations.
|
|
90
|
+
|
|
91
|
+
## Example app
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
yarn
|
|
95
|
+
yarn example ios
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Three tabs: Verify (right code 123456, wrong codes shake), PIN (masked), Lock screen (keypad, passcode 2468, Face ID button).
|
|
99
|
+
|
|
100
|
+
## Credits
|
|
101
|
+
|
|
102
|
+
Inspired by the verification code and lock-screen PIN demos by Enzo Mangano at reactiive.io. Implemented from scratch for this package.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT © Asad Ali
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import Animated, { Easing, ReduceMotion, useAnimatedStyle, useSharedValue, withRepeat, withSequence, withSpring, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
export function Cell({
|
|
8
|
+
char,
|
|
9
|
+
masked,
|
|
10
|
+
active,
|
|
11
|
+
error,
|
|
12
|
+
style,
|
|
13
|
+
activeStyle,
|
|
14
|
+
filledStyle,
|
|
15
|
+
errorStyle,
|
|
16
|
+
textStyle
|
|
17
|
+
}) {
|
|
18
|
+
const pop = useSharedValue(1);
|
|
19
|
+
const fade = useSharedValue(char ? 1 : 0);
|
|
20
|
+
const caret = useSharedValue(1);
|
|
21
|
+
const filled = char.length > 0;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (filled) {
|
|
24
|
+
fade.value = withTiming(1, {
|
|
25
|
+
duration: 120,
|
|
26
|
+
reduceMotion: ReduceMotion.System
|
|
27
|
+
});
|
|
28
|
+
pop.value = withSequence(withTiming(1.12, {
|
|
29
|
+
duration: 90,
|
|
30
|
+
easing: Easing.out(Easing.quad),
|
|
31
|
+
reduceMotion: ReduceMotion.System
|
|
32
|
+
}), withSpring(1, {
|
|
33
|
+
damping: 14,
|
|
34
|
+
stiffness: 320,
|
|
35
|
+
reduceMotion: ReduceMotion.System
|
|
36
|
+
}));
|
|
37
|
+
} else {
|
|
38
|
+
fade.value = withTiming(0, {
|
|
39
|
+
duration: 90,
|
|
40
|
+
reduceMotion: ReduceMotion.System
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, [filled, fade, pop]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (active && !filled) {
|
|
46
|
+
caret.value = withRepeat(withSequence(withTiming(0, {
|
|
47
|
+
duration: 450,
|
|
48
|
+
reduceMotion: ReduceMotion.System
|
|
49
|
+
}), withTiming(1, {
|
|
50
|
+
duration: 450,
|
|
51
|
+
reduceMotion: ReduceMotion.System
|
|
52
|
+
})), -1, false);
|
|
53
|
+
} else {
|
|
54
|
+
caret.value = 0;
|
|
55
|
+
}
|
|
56
|
+
}, [active, filled, caret]);
|
|
57
|
+
const cellStyle = useAnimatedStyle(() => ({
|
|
58
|
+
transform: [{
|
|
59
|
+
scale: pop.value
|
|
60
|
+
}]
|
|
61
|
+
}));
|
|
62
|
+
const charStyle = useAnimatedStyle(() => ({
|
|
63
|
+
opacity: fade.value
|
|
64
|
+
}));
|
|
65
|
+
const caretStyle = useAnimatedStyle(() => ({
|
|
66
|
+
opacity: caret.value
|
|
67
|
+
}));
|
|
68
|
+
return /*#__PURE__*/_jsxs(Animated.View, {
|
|
69
|
+
style: [styles.cell, style, filled && [styles.filled, filledStyle], active && [styles.active, activeStyle], error && [styles.error, errorStyle], cellStyle],
|
|
70
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
71
|
+
style: charStyle,
|
|
72
|
+
children: masked && filled ? /*#__PURE__*/_jsx(View, {
|
|
73
|
+
style: [styles.dot, error && styles.dotError]
|
|
74
|
+
}) : /*#__PURE__*/_jsx(Text, {
|
|
75
|
+
style: [styles.text, textStyle, error && styles.textError],
|
|
76
|
+
children: char
|
|
77
|
+
})
|
|
78
|
+
}), active && !filled ? /*#__PURE__*/_jsx(Animated.View, {
|
|
79
|
+
style: [styles.caret, caretStyle]
|
|
80
|
+
}) : null]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const styles = StyleSheet.create({
|
|
84
|
+
cell: {
|
|
85
|
+
width: 48,
|
|
86
|
+
height: 58,
|
|
87
|
+
borderRadius: 12,
|
|
88
|
+
borderWidth: 1.5,
|
|
89
|
+
borderColor: 'rgba(128,128,128,0.35)',
|
|
90
|
+
alignItems: 'center',
|
|
91
|
+
justifyContent: 'center'
|
|
92
|
+
},
|
|
93
|
+
filled: {
|
|
94
|
+
borderColor: 'rgba(128,128,128,0.6)'
|
|
95
|
+
},
|
|
96
|
+
active: {
|
|
97
|
+
borderColor: '#6C8CFF'
|
|
98
|
+
},
|
|
99
|
+
error: {
|
|
100
|
+
borderColor: '#FF6B6B'
|
|
101
|
+
},
|
|
102
|
+
text: {
|
|
103
|
+
fontSize: 24,
|
|
104
|
+
fontWeight: '700',
|
|
105
|
+
color: '#F3F4F6',
|
|
106
|
+
fontVariant: ['tabular-nums']
|
|
107
|
+
},
|
|
108
|
+
textError: {
|
|
109
|
+
color: '#FF6B6B'
|
|
110
|
+
},
|
|
111
|
+
dot: {
|
|
112
|
+
width: 12,
|
|
113
|
+
height: 12,
|
|
114
|
+
borderRadius: 6,
|
|
115
|
+
backgroundColor: '#F3F4F6'
|
|
116
|
+
},
|
|
117
|
+
dotError: {
|
|
118
|
+
backgroundColor: '#FF6B6B'
|
|
119
|
+
},
|
|
120
|
+
caret: {
|
|
121
|
+
position: 'absolute',
|
|
122
|
+
width: 2,
|
|
123
|
+
height: 24,
|
|
124
|
+
borderRadius: 1,
|
|
125
|
+
backgroundColor: '#6C8CFF'
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=Cell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","StyleSheet","Text","View","Animated","Easing","ReduceMotion","useAnimatedStyle","useSharedValue","withRepeat","withSequence","withSpring","withTiming","jsx","_jsx","jsxs","_jsxs","Cell","char","masked","active","error","style","activeStyle","filledStyle","errorStyle","textStyle","pop","fade","caret","filled","length","value","duration","reduceMotion","System","easing","out","quad","damping","stiffness","cellStyle","transform","scale","charStyle","opacity","caretStyle","styles","cell","children","dot","dotError","text","textError","create","width","height","borderRadius","borderWidth","borderColor","alignItems","justifyContent","fontSize","fontWeight","color","fontVariant","backgroundColor","position"],"sourceRoot":"../../src","sources":["Cell.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,OAAO;AACjC,SACEC,UAAU,EACVC,IAAI,EACJC,IAAI,QAIC,cAAc;AACrB,OAAOC,QAAQ,IACbC,MAAM,EACNC,YAAY,EACZC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,YAAY,EACZC,UAAU,EACVC,UAAU,QACL,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAcjC,OAAO,SAASC,IAAIA,CAAC;EACnBC,IAAI;EACJC,MAAM;EACNC,MAAM;EACNC,KAAK;EACLC,KAAK;EACLC,WAAW;EACXC,WAAW;EACXC,UAAU;EACVC;AACK,CAAC,EAAE;EACR,MAAMC,GAAG,GAAGnB,cAAc,CAAC,CAAC,CAAC;EAC7B,MAAMoB,IAAI,GAAGpB,cAAc,CAACU,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;EACzC,MAAMW,KAAK,GAAGrB,cAAc,CAAC,CAAC,CAAC;EAC/B,MAAMsB,MAAM,GAAGZ,IAAI,CAACa,MAAM,GAAG,CAAC;EAE9B/B,SAAS,CAAC,MAAM;IACd,IAAI8B,MAAM,EAAE;MACVF,IAAI,CAACI,KAAK,GAAGpB,UAAU,CAAC,CAAC,EAAE;QACzBqB,QAAQ,EAAE,GAAG;QACbC,YAAY,EAAE5B,YAAY,CAAC6B;MAC7B,CAAC,CAAC;MACFR,GAAG,CAACK,KAAK,GAAGtB,YAAY,CACtBE,UAAU,CAAC,IAAI,EAAE;QACfqB,QAAQ,EAAE,EAAE;QACZG,MAAM,EAAE/B,MA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,GAAG;IAChBC,WAAW,EAAE,wBAAwB;IACrCC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;EAClB,CAAC;EACD/B,MAAM,EAAE;IAAE6B,WAAW,EAAE;EAAwB,CAAC;EAChDvC,MAAM,EAAE;IAAEuC,WAAW,EAAE;EAAU,CAAC;EAClCtC,KAAK,EAAE;IAAEsC,WAAW,EAAE;EAAU,CAAC;EACjCP,IAAI,EAAE;IACJU,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE,KAAK;IACjBC,KAAK,EAAE,SAAS;IAChBC,WAAW,EAAE,CAAC,cAAc;EAC9B,CAAC;EACDZ,SAAS,EAAE;IAAEW,KAAK,EAAE;EAAU,CAAC;EAC/Bd,GAAG,EAAE;IAAEK,KAAK,EAAE,EAAE;IAAEC,MAAM,EAAE,EAAE;IAAEC,YAAY,EAAE,CAAC;IAAES,eAAe,EAAE;EAAU,CAAC;EAC3Ef,QAAQ,EAAE;IAAEe,eAAe,EAAE;EAAU,CAAC;EACxCrC,KAAK,EAAE;IACLsC,QAAQ,EAAE,UAAU;IACpBZ,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE,EAAE;IACVC,YAAY,EAAE,CAAC;IACfS,eAAe,EAAE;EACnB;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Platform, Pressable, StyleSheet, TextInput } from 'react-native';
|
|
5
|
+
import Animated from 'react-native-reanimated';
|
|
6
|
+
import { Cell } from "./Cell.js";
|
|
7
|
+
import { useShake } from "./useShake.js";
|
|
8
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
function sanitize(text, length, numeric) {
|
|
10
|
+
const cleaned = numeric ? text.replace(/\D/g, '') : text.replace(/\s/g, '');
|
|
11
|
+
return cleaned.slice(0, length);
|
|
12
|
+
}
|
|
13
|
+
export function CodeInput({
|
|
14
|
+
length = 6,
|
|
15
|
+
value,
|
|
16
|
+
defaultValue = '',
|
|
17
|
+
onChange,
|
|
18
|
+
onComplete,
|
|
19
|
+
masked = false,
|
|
20
|
+
error = false,
|
|
21
|
+
onErrorCleared,
|
|
22
|
+
autoFocus = false,
|
|
23
|
+
keyboardType = 'number-pad',
|
|
24
|
+
disabled = false,
|
|
25
|
+
haptics,
|
|
26
|
+
cellStyle,
|
|
27
|
+
activeCellStyle,
|
|
28
|
+
filledCellStyle,
|
|
29
|
+
errorCellStyle,
|
|
30
|
+
cellTextStyle,
|
|
31
|
+
gap = 10,
|
|
32
|
+
style,
|
|
33
|
+
accessibilityLabel,
|
|
34
|
+
testID
|
|
35
|
+
}) {
|
|
36
|
+
const numeric = keyboardType === 'number-pad';
|
|
37
|
+
const [inner, setInner] = useState(() => sanitize(defaultValue, length, numeric));
|
|
38
|
+
const code = value !== undefined ? sanitize(value, length, numeric) : inner;
|
|
39
|
+
const [focused, setFocused] = useState(autoFocus);
|
|
40
|
+
const [showError, setShowError] = useState(false);
|
|
41
|
+
const inputRef = useRef(null);
|
|
42
|
+
const completedFor = useRef(null);
|
|
43
|
+
const {
|
|
44
|
+
shake,
|
|
45
|
+
style: shakeStyle
|
|
46
|
+
} = useShake();
|
|
47
|
+
const update = useCallback(next => {
|
|
48
|
+
const cleaned = sanitize(next, length, numeric);
|
|
49
|
+
if (cleaned.length > code.length) {
|
|
50
|
+
haptics?.('tick');
|
|
51
|
+
}
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
setInner(cleaned);
|
|
54
|
+
}
|
|
55
|
+
onChange?.(cleaned);
|
|
56
|
+
}, [code.length, haptics, length, numeric, onChange, value]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (code.length === length && completedFor.current !== code) {
|
|
59
|
+
completedFor.current = code;
|
|
60
|
+
haptics?.('success');
|
|
61
|
+
onComplete?.(code);
|
|
62
|
+
}
|
|
63
|
+
if (code.length < length) {
|
|
64
|
+
completedFor.current = null;
|
|
65
|
+
}
|
|
66
|
+
}, [code, length, onComplete, haptics]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!error) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
setShowError(true);
|
|
72
|
+
haptics?.('error');
|
|
73
|
+
shake(() => {
|
|
74
|
+
setShowError(false);
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
setInner('');
|
|
77
|
+
}
|
|
78
|
+
onChange?.('');
|
|
79
|
+
onErrorCleared?.();
|
|
80
|
+
});
|
|
81
|
+
// Run once per error pulse.
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, [error]);
|
|
84
|
+
const focus = useCallback(() => {
|
|
85
|
+
if (!disabled) {
|
|
86
|
+
inputRef.current?.focus();
|
|
87
|
+
}
|
|
88
|
+
}, [disabled]);
|
|
89
|
+
const onKeyPress = useCallback(e => {
|
|
90
|
+
// Android number pads do not always report a changed text on backspace of an empty field.
|
|
91
|
+
if (e.nativeEvent.key === 'Backspace' && code.length > 0 && Platform.OS === 'android') {
|
|
92
|
+
update(code.slice(0, -1));
|
|
93
|
+
}
|
|
94
|
+
}, [code, update]);
|
|
95
|
+
const activeIndex = Math.min(code.length, length - 1);
|
|
96
|
+
return /*#__PURE__*/_jsxs(Pressable, {
|
|
97
|
+
onPress: focus,
|
|
98
|
+
style: style,
|
|
99
|
+
accessible: true,
|
|
100
|
+
accessibilityRole: "none",
|
|
101
|
+
accessibilityLabel: accessibilityLabel ?? `Verification code, ${code.length} of ${length} ${numeric ? 'digits' : 'characters'} entered`,
|
|
102
|
+
testID: testID,
|
|
103
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
104
|
+
style: [styles.row, {
|
|
105
|
+
gap
|
|
106
|
+
}, shakeStyle],
|
|
107
|
+
children: Array.from({
|
|
108
|
+
length
|
|
109
|
+
}, (_, i) => /*#__PURE__*/_jsx(Cell, {
|
|
110
|
+
char: code[i] ?? '',
|
|
111
|
+
masked: masked,
|
|
112
|
+
active: focused && i === activeIndex && !showError,
|
|
113
|
+
error: showError,
|
|
114
|
+
style: cellStyle,
|
|
115
|
+
activeStyle: activeCellStyle,
|
|
116
|
+
filledStyle: filledCellStyle,
|
|
117
|
+
errorStyle: errorCellStyle,
|
|
118
|
+
textStyle: cellTextStyle
|
|
119
|
+
}, i))
|
|
120
|
+
}), /*#__PURE__*/_jsx(TextInput, {
|
|
121
|
+
ref: inputRef,
|
|
122
|
+
value: code,
|
|
123
|
+
onChangeText: update,
|
|
124
|
+
onKeyPress: onKeyPress,
|
|
125
|
+
onFocus: () => setFocused(true),
|
|
126
|
+
onBlur: () => setFocused(false),
|
|
127
|
+
autoFocus: autoFocus,
|
|
128
|
+
editable: !disabled,
|
|
129
|
+
maxLength: length,
|
|
130
|
+
keyboardType: numeric ? 'number-pad' : 'default',
|
|
131
|
+
autoCapitalize: "characters",
|
|
132
|
+
autoCorrect: false,
|
|
133
|
+
textContentType: "oneTimeCode",
|
|
134
|
+
autoComplete: Platform.OS === 'android' ? 'sms-otp' : 'one-time-code',
|
|
135
|
+
caretHidden: true,
|
|
136
|
+
style: styles.hidden,
|
|
137
|
+
accessibilityElementsHidden: true,
|
|
138
|
+
importantForAccessibility: "no-hide-descendants",
|
|
139
|
+
testID: testID ? `${testID}-input` : undefined
|
|
140
|
+
})]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const styles = StyleSheet.create({
|
|
144
|
+
row: {
|
|
145
|
+
flexDirection: 'row',
|
|
146
|
+
justifyContent: 'center'
|
|
147
|
+
},
|
|
148
|
+
hidden: {
|
|
149
|
+
position: 'absolute',
|
|
150
|
+
opacity: 0,
|
|
151
|
+
width: 1,
|
|
152
|
+
height: 1,
|
|
153
|
+
left: 0,
|
|
154
|
+
top: 0
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
//# sourceMappingURL=CodeInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useRef","useState","Platform","Pressable","StyleSheet","TextInput","Animated","Cell","useShake","jsx","_jsx","jsxs","_jsxs","sanitize","text","length","numeric","cleaned","replace","slice","CodeInput","value","defaultValue","onChange","onComplete","masked","error","onErrorCleared","autoFocus","keyboardType","disabled","haptics","cellStyle","activeCellStyle","filledCellStyle","errorCellStyle","cellTextStyle","gap","style","accessibilityLabel","testID","inner","setInner","code","undefined","focused","setFocused","showError","setShowError","inputRef","completedFor","shake","shakeStyle","update","next","current","focus","onKeyPress","e","nativeEvent","key","OS","activeIndex","Math","min","onPress","accessible","accessibilityRole","children","View","styles","row","Array","from","_","i","char","active","activeStyle","filledStyle","errorStyle","textStyle","ref","onChangeText","onFocus","onBlur","editable","maxLength","autoCapitalize","autoCorrect","textContentType","autoComplete","caretHidden","hidden","accessibilityElementsHidden","importantForAccessibility","create","flexDirection","justifyContent","position","opacity","width","height","left","top"],"sourceRoot":"../../src","sources":["CodeInput.tsx"],"mappings":";;AAAA,SACEA,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QAEH,OAAO;AACd,SACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,SAAS,QAEJ,cAAc;AACrB,OAAOC,QAAQ,MAAM,yBAAyB;AAC9C,SAASC,IAAI,QAAQ,WAAQ;AAE7B,SAASC,QAAQ,QAAQ,eAAY;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAEtC,SAASC,QAAQA,CAACC,IAAY,EAAEC,MAAc,EAAEC,OAAgB,EAAU;EACxE,MAAMC,OAAO,GAAGD,OAAO,GAAGF,IAAI,CAACI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAGJ,IAAI,CAACI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAC3E,OAAOD,OAAO,CAACE,KAAK,CAAC,CAAC,EAAEJ,MAAM,CAAC;AACjC;AAEA,OAAO,SAASK,SAASA,CAA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EAAE;EACP;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import Animated, { ReduceMotion, useAnimatedStyle, useSharedValue, withRepeat, withSequence, withSpring, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { useShake } from "./useShake.js";
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
const KEYS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'bio', '0', 'del'];
|
|
9
|
+
export function PinPad({
|
|
10
|
+
length = 4,
|
|
11
|
+
onComplete,
|
|
12
|
+
biometricLabel,
|
|
13
|
+
onBiometric,
|
|
14
|
+
haptics,
|
|
15
|
+
keySize = 72,
|
|
16
|
+
keyStyle,
|
|
17
|
+
keyTextStyle,
|
|
18
|
+
dotColor = '#F3F4F6',
|
|
19
|
+
errorColor = '#FF6B6B',
|
|
20
|
+
style,
|
|
21
|
+
testID
|
|
22
|
+
}) {
|
|
23
|
+
const [pin, setPin] = useState('');
|
|
24
|
+
const [pending, setPending] = useState(false);
|
|
25
|
+
const [wrong, setWrong] = useState(false);
|
|
26
|
+
const {
|
|
27
|
+
shake,
|
|
28
|
+
style: shakeStyle
|
|
29
|
+
} = useShake();
|
|
30
|
+
const pulse = useSharedValue(1);
|
|
31
|
+
const busy = useRef(false);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (pending) {
|
|
34
|
+
pulse.value = withRepeat(withSequence(withTiming(0.4, {
|
|
35
|
+
duration: 350,
|
|
36
|
+
reduceMotion: ReduceMotion.System
|
|
37
|
+
}), withTiming(1, {
|
|
38
|
+
duration: 350,
|
|
39
|
+
reduceMotion: ReduceMotion.System
|
|
40
|
+
})), -1, false);
|
|
41
|
+
} else {
|
|
42
|
+
pulse.value = withTiming(1, {
|
|
43
|
+
duration: 120,
|
|
44
|
+
reduceMotion: ReduceMotion.System
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, [pending, pulse]);
|
|
48
|
+
const dotsStyle = useAnimatedStyle(() => ({
|
|
49
|
+
opacity: pulse.value
|
|
50
|
+
}));
|
|
51
|
+
const submit = useCallback(async candidate => {
|
|
52
|
+
busy.current = true;
|
|
53
|
+
setPending(true);
|
|
54
|
+
let ok = false;
|
|
55
|
+
try {
|
|
56
|
+
ok = await onComplete(candidate);
|
|
57
|
+
} finally {
|
|
58
|
+
setPending(false);
|
|
59
|
+
}
|
|
60
|
+
if (ok) {
|
|
61
|
+
haptics?.('success');
|
|
62
|
+
busy.current = false;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
setWrong(true);
|
|
66
|
+
haptics?.('error');
|
|
67
|
+
shake(() => {
|
|
68
|
+
setWrong(false);
|
|
69
|
+
setPin('');
|
|
70
|
+
busy.current = false;
|
|
71
|
+
});
|
|
72
|
+
}, [haptics, onComplete, shake]);
|
|
73
|
+
const press = useCallback(key => {
|
|
74
|
+
if (busy.current) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (key === 'bio') {
|
|
78
|
+
onBiometric?.();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (key === 'del') {
|
|
82
|
+
setPin(p => p.slice(0, -1));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
haptics?.('tick');
|
|
86
|
+
setPin(p => {
|
|
87
|
+
if (p.length >= length) {
|
|
88
|
+
return p;
|
|
89
|
+
}
|
|
90
|
+
const next = p + key;
|
|
91
|
+
if (next.length === length) {
|
|
92
|
+
void submit(next);
|
|
93
|
+
}
|
|
94
|
+
return next;
|
|
95
|
+
});
|
|
96
|
+
}, [haptics, length, onBiometric, submit]);
|
|
97
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
98
|
+
style: [styles.root, style],
|
|
99
|
+
testID: testID,
|
|
100
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
101
|
+
style: [styles.dots, shakeStyle, dotsStyle],
|
|
102
|
+
accessibilityLabel: `${pin.length} of ${length} digits entered`,
|
|
103
|
+
children: Array.from({
|
|
104
|
+
length
|
|
105
|
+
}, (_, i) => /*#__PURE__*/_jsx(View, {
|
|
106
|
+
style: [styles.dot, {
|
|
107
|
+
borderColor: wrong ? errorColor : dotColor
|
|
108
|
+
}, i < pin.length && {
|
|
109
|
+
backgroundColor: wrong ? errorColor : dotColor
|
|
110
|
+
}]
|
|
111
|
+
}, i))
|
|
112
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
113
|
+
style: [styles.grid, {
|
|
114
|
+
width: keySize * 3 + 24 * 2
|
|
115
|
+
}],
|
|
116
|
+
children: KEYS.map(key => {
|
|
117
|
+
const blank = key === 'bio' && !biometricLabel;
|
|
118
|
+
const label = key === 'bio' ? biometricLabel ?? '' : key === 'del' ? '⌫' : key;
|
|
119
|
+
return /*#__PURE__*/_jsx(Key, {
|
|
120
|
+
label: label,
|
|
121
|
+
size: keySize,
|
|
122
|
+
blank: blank,
|
|
123
|
+
small: key === 'bio' || key === 'del',
|
|
124
|
+
onPress: () => press(key),
|
|
125
|
+
style: keyStyle,
|
|
126
|
+
textStyle: keyTextStyle,
|
|
127
|
+
accessibilityLabel: key === 'del' ? 'Delete' : key === 'bio' ? biometricLabel : key
|
|
128
|
+
}, key);
|
|
129
|
+
})
|
|
130
|
+
})]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function Key({
|
|
134
|
+
label,
|
|
135
|
+
size,
|
|
136
|
+
blank,
|
|
137
|
+
small,
|
|
138
|
+
onPress,
|
|
139
|
+
style,
|
|
140
|
+
textStyle,
|
|
141
|
+
accessibilityLabel
|
|
142
|
+
}) {
|
|
143
|
+
const scale = useSharedValue(1);
|
|
144
|
+
const animated = useAnimatedStyle(() => ({
|
|
145
|
+
transform: [{
|
|
146
|
+
scale: scale.value
|
|
147
|
+
}]
|
|
148
|
+
}));
|
|
149
|
+
if (blank) {
|
|
150
|
+
return /*#__PURE__*/_jsx(View, {
|
|
151
|
+
style: {
|
|
152
|
+
width: size,
|
|
153
|
+
height: size
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
158
|
+
onPress: onPress,
|
|
159
|
+
onPressIn: () => {
|
|
160
|
+
scale.value = withSpring(0.9, {
|
|
161
|
+
damping: 14,
|
|
162
|
+
stiffness: 400
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
onPressOut: () => {
|
|
166
|
+
scale.value = withSpring(1, {
|
|
167
|
+
damping: 14,
|
|
168
|
+
stiffness: 400
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
accessibilityRole: "button",
|
|
172
|
+
accessibilityLabel: accessibilityLabel,
|
|
173
|
+
children: /*#__PURE__*/_jsx(Animated.View, {
|
|
174
|
+
style: [styles.key, {
|
|
175
|
+
width: size,
|
|
176
|
+
height: size,
|
|
177
|
+
borderRadius: size / 2
|
|
178
|
+
}, style, animated],
|
|
179
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
180
|
+
style: [styles.keyText, small && styles.keyTextSmall, textStyle],
|
|
181
|
+
children: label
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const styles = StyleSheet.create({
|
|
187
|
+
root: {
|
|
188
|
+
alignItems: 'center',
|
|
189
|
+
gap: 32
|
|
190
|
+
},
|
|
191
|
+
dots: {
|
|
192
|
+
flexDirection: 'row',
|
|
193
|
+
gap: 16
|
|
194
|
+
},
|
|
195
|
+
dot: {
|
|
196
|
+
width: 14,
|
|
197
|
+
height: 14,
|
|
198
|
+
borderRadius: 7,
|
|
199
|
+
borderWidth: 1.5
|
|
200
|
+
},
|
|
201
|
+
grid: {
|
|
202
|
+
flexDirection: 'row',
|
|
203
|
+
flexWrap: 'wrap',
|
|
204
|
+
justifyContent: 'space-between',
|
|
205
|
+
rowGap: 18
|
|
206
|
+
},
|
|
207
|
+
key: {
|
|
208
|
+
backgroundColor: 'rgba(128,128,128,0.18)',
|
|
209
|
+
alignItems: 'center',
|
|
210
|
+
justifyContent: 'center'
|
|
211
|
+
},
|
|
212
|
+
keyText: {
|
|
213
|
+
fontSize: 30,
|
|
214
|
+
fontWeight: '500',
|
|
215
|
+
color: '#F3F4F6'
|
|
216
|
+
},
|
|
217
|
+
keyTextSmall: {
|
|
218
|
+
fontSize: 16,
|
|
219
|
+
fontWeight: '600'
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
//# sourceMappingURL=PinPad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useRef","useState","Pressable","StyleSheet","Text","View","Animated","ReduceMotion","useAnimatedStyle","useSharedValue","withRepeat","withSequence","withSpring","withTiming","useShake","jsx","_jsx","jsxs","_jsxs","KEYS","PinPad","length","onComplete","biometricLabel","onBiometric","haptics","keySize","keyStyle","keyTextStyle","dotColor","errorColor","style","testID","pin","setPin","pending","setPending","wrong","setWrong","shake","shakeStyle","pulse","busy","value","duration","reduceMotion","System","dotsStyle","opacity","submit","candidate","current","ok","press","key","p","slice","next","styles","root","children","dots","accessibilityLabel","Array","from","_","i","dot","borderColor","backgroundColor","grid","width","map","blank","label","Key","size","small","onPress","textStyle","scale","animated","transform","height","onPressIn","damping","stiffness","onPressOut","accessibilityRole","borderRadius","keyText","keyTextSmall","create","alignItems","gap","flexDirection","borderWidth","flexWrap","justifyContent","rowGap","fontSize","fontWeight","color"],"sourceRoot":"../../src","sources":["PinPad.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAChE,SAASC,SAAS,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAChE,OAAOC,QAAQ,IACbC,YAAY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