@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CodeInput","PinPad"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,gBAAa;AACvC,SAASC,MAAM,QAAQ,aAAU","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { ReduceMotion, runOnJS, useAnimatedStyle, useSharedValue, withSequence, withTiming } from 'react-native-reanimated';
|
|
5
|
+
const AMPLITUDE = 8;
|
|
6
|
+
const STEP = 55;
|
|
7
|
+
|
|
8
|
+
/** Horizontal shake: four cycles, then a callback on the JS thread. */
|
|
9
|
+
export function useShake() {
|
|
10
|
+
const offset = useSharedValue(0);
|
|
11
|
+
const shake = useCallback(onDone => {
|
|
12
|
+
const t = to => withTiming(to, {
|
|
13
|
+
duration: STEP,
|
|
14
|
+
reduceMotion: ReduceMotion.System
|
|
15
|
+
});
|
|
16
|
+
offset.value = withSequence(t(-AMPLITUDE), t(AMPLITUDE), t(-AMPLITUDE), t(AMPLITUDE), t(-AMPLITUDE / 2), t(AMPLITUDE / 2), withTiming(0, {
|
|
17
|
+
duration: STEP,
|
|
18
|
+
reduceMotion: ReduceMotion.System
|
|
19
|
+
}, () => {
|
|
20
|
+
if (onDone) {
|
|
21
|
+
runOnJS(onDone)();
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
}, [offset]);
|
|
25
|
+
const style = useAnimatedStyle(() => ({
|
|
26
|
+
transform: [{
|
|
27
|
+
translateX: offset.value
|
|
28
|
+
}]
|
|
29
|
+
}));
|
|
30
|
+
return {
|
|
31
|
+
shake,
|
|
32
|
+
style
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=useShake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","ReduceMotion","runOnJS","useAnimatedStyle","useSharedValue","withSequence","withTiming","AMPLITUDE","STEP","useShake","offset","shake","onDone","t","to","duration","reduceMotion","System","value","style","transform","translateX"],"s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reList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type StyleProp, type TextStyle, type ViewStyle } from 'react-native';
|
|
2
|
+
interface Props {
|
|
3
|
+
char: string;
|
|
4
|
+
masked: boolean;
|
|
5
|
+
active: boolean;
|
|
6
|
+
error: boolean;
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
activeStyle?: StyleProp<ViewStyle>;
|
|
9
|
+
filledStyle?: StyleProp<ViewStyle>;
|
|
10
|
+
errorStyle?: StyleProp<ViewStyle>;
|
|
11
|
+
textStyle?: StyleProp<TextStyle>;
|
|
12
|
+
}
|
|
13
|
+
export declare function Cell({ char, masked, active, error, style, activeStyle, filledStyle, errorStyle, textStyle, }: Props): import("react").JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=Cell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cell.d.ts","sourceRoot":"","sources":["../../../src/Cell.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAYtB,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAClC;AAED,wBAAgB,IAAI,CAAC,EACnB,IAAI,EACJ,MAAM,EACN,MAAM,EACN,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,EACX,UAAU,EACV,SAAS,GACV,EAAE,KAAK,+BA8EP"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CodeInputProps } from './types.js';
|
|
2
|
+
export declare function CodeInput({ length, value, defaultValue, onChange, onComplete, masked, error, onErrorCleared, autoFocus, keyboardType, disabled, haptics, cellStyle, activeCellStyle, filledCellStyle, errorCellStyle, cellTextStyle, gap, style, accessibilityLabel, testID, }: CodeInputProps): import("react").JSX.Element;
|
|
3
|
+
//# sourceMappingURL=CodeInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeInput.d.ts","sourceRoot":"","sources":["../../../src/CodeInput.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAS,CAAC;AAQ9C,wBAAgB,SAAS,CAAC,EACxB,MAAU,EACV,KAAK,EACL,YAAiB,EACjB,QAAQ,EACR,UAAU,EACV,MAAc,EACd,KAAa,EACb,cAAc,EACd,SAAiB,EACjB,YAA2B,EAC3B,QAAgB,EAChB,OAAO,EACP,SAAS,EACT,eAAe,EACf,eAAe,EACf,cAAc,EACd,aAAa,EACb,GAAQ,EACR,KAAK,EACL,kBAAkB,EAClB,MAAM,GACP,EAAE,cAAc,+BAgIhB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PinPadProps } from './types.js';
|
|
2
|
+
export declare function PinPad({ length, onComplete, biometricLabel, onBiometric, haptics, keySize, keyStyle, keyTextStyle, dotColor, errorColor, style, testID, }: PinPadProps): import("react").JSX.Element;
|
|
3
|
+
//# sourceMappingURL=PinPad.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PinPad.d.ts","sourceRoot":"","sources":["../../../src/PinPad.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAS,CAAC;AAkB3C,wBAAgB,MAAM,CAAC,EACrB,MAAU,EACV,UAAU,EACV,cAAc,EACd,WAAW,EACX,OAAO,EACP,OAAY,EACZ,QAAQ,EACR,YAAY,EACZ,QAAoB,EACpB,UAAsB,EACtB,KAAK,EACL,MAAM,GACP,EAAE,WAAW,+BA6Hb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAU,CAAC;AAClC,YAAY,EACV,cAAc,EACd,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,YAAS,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
+
export type HapticEvent = 'tick' | 'error' | 'success';
|
|
3
|
+
export type HapticsCallback = (event: HapticEvent) => void;
|
|
4
|
+
export interface CodeInputProps {
|
|
5
|
+
/** Number of cells. Default 6. */
|
|
6
|
+
length?: number;
|
|
7
|
+
/** Controlled value. Digits only unless `keyboardType` is 'default'. */
|
|
8
|
+
value?: string;
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
onChange?: (code: string) => void;
|
|
11
|
+
/** Fires once when every cell is filled. */
|
|
12
|
+
onComplete?: (code: string) => void;
|
|
13
|
+
/** Show dots instead of characters. Default false. */
|
|
14
|
+
masked?: boolean;
|
|
15
|
+
/** True plays the shake, shows the error state, then clears the value. */
|
|
16
|
+
error?: boolean;
|
|
17
|
+
/** Called after the error shake has cleared the value. */
|
|
18
|
+
onErrorCleared?: () => void;
|
|
19
|
+
autoFocus?: boolean;
|
|
20
|
+
/** 'number-pad' (default) or 'default' for alphanumeric codes. */
|
|
21
|
+
keyboardType?: 'number-pad' | 'default';
|
|
22
|
+
/** Disable input. */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
haptics?: HapticsCallback;
|
|
25
|
+
cellStyle?: StyleProp<ViewStyle>;
|
|
26
|
+
activeCellStyle?: StyleProp<ViewStyle>;
|
|
27
|
+
filledCellStyle?: StyleProp<ViewStyle>;
|
|
28
|
+
errorCellStyle?: StyleProp<ViewStyle>;
|
|
29
|
+
cellTextStyle?: StyleProp<TextStyle>;
|
|
30
|
+
/** Space between cells. Default 10. */
|
|
31
|
+
gap?: number;
|
|
32
|
+
style?: StyleProp<ViewStyle>;
|
|
33
|
+
accessibilityLabel?: string;
|
|
34
|
+
testID?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PinPadProps {
|
|
37
|
+
/** Number of digits. Default 4. */
|
|
38
|
+
length?: number;
|
|
39
|
+
/** Return false (or a promise of false) to shake and clear. */
|
|
40
|
+
onComplete: (pin: string) => boolean | Promise<boolean>;
|
|
41
|
+
/** Label of the bottom-left key, for example "Face ID". Omit to leave it blank. */
|
|
42
|
+
biometricLabel?: string;
|
|
43
|
+
onBiometric?: () => void;
|
|
44
|
+
haptics?: HapticsCallback;
|
|
45
|
+
/** Key diameter. Default 72. */
|
|
46
|
+
keySize?: number;
|
|
47
|
+
keyStyle?: StyleProp<ViewStyle>;
|
|
48
|
+
keyTextStyle?: StyleProp<TextStyle>;
|
|
49
|
+
dotColor?: string;
|
|
50
|
+
errorColor?: string;
|
|
51
|
+
style?: StyleProp<ViewStyle>;
|
|
52
|
+
testID?: string;
|
|
53
|
+
}
|
|
54
|
+
//# 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,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEpE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,WAAW,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UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxD,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Horizontal shake: four cycles, then a callback on the JS thread. */
|
|
2
|
+
export declare function useShake(): {
|
|
3
|
+
shake: (onDone?: () => void) => void;
|
|
4
|
+
style: import("react-native-reanimated/lib/typescript/hook/commonTypes").AnimatedStyleHandle<{
|
|
5
|
+
transform: {
|
|
6
|
+
translateX: number;
|
|
7
|
+
}[];
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=useShake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useShake.d.ts","sourceRoot":"","sources":["../../../src/useShake.ts"],"names":[],"mappings":"AAaA,uEAAuE;AACvE,wBAAgB,QAAQ;qBAIV,MAAM,IAAI;;;;;;EA6BvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,162 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asaddevworld/code-input",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One-time code and PIN inputs for React Native: animated cells, shake on error, SMS autofill, masked mode, and a lock-screen keypad",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"rn-code-input-source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace rn-code-input-example",
|
|
36
|
+
"clean": "del-cli lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"react-native",
|
|
44
|
+
"expo",
|
|
45
|
+
"otp",
|
|
46
|
+
"one-time-code",
|
|
47
|
+
"verification-code",
|
|
48
|
+
"pin",
|
|
49
|
+
"pin-pad",
|
|
50
|
+
"passcode",
|
|
51
|
+
"input",
|
|
52
|
+
"reanimated",
|
|
53
|
+
"ios",
|
|
54
|
+
"android"
|
|
55
|
+
],
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "git+https://github.com/asadDevWorld/rn-code-input.git"
|
|
59
|
+
},
|
|
60
|
+
"author": "Asad Ali <sadali3690@gmail.com> (https://github.com/asadDevWorld)",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/asadDevWorld/rn-code-input/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/asadDevWorld/rn-code-input#readme",
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"registry": "https://registry.npmjs.org/",
|
|
68
|
+
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@eslint/compat": "^2.1.1",
|
|
72
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
73
|
+
"@eslint/js": "^9.39.5",
|
|
74
|
+
"@jest/globals": "^29.7.0",
|
|
75
|
+
"@react-native/babel-preset": "0.88.1",
|
|
76
|
+
"@react-native/eslint-config": "0.88.1",
|
|
77
|
+
"@react-native/jest-preset": "0.88.1",
|
|
78
|
+
"@testing-library/react-native": "^13.3.3",
|
|
79
|
+
"@types/react": "^19.2.0",
|
|
80
|
+
"del-cli": "^8.0.1",
|
|
81
|
+
"eslint": "^9.39.5",
|
|
82
|
+
"eslint-config-prettier": "^10.1.8",
|
|
83
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
84
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
85
|
+
"jest": "^29.7.0",
|
|
86
|
+
"prettier": "^3.9.10",
|
|
87
|
+
"react": "19.3.0",
|
|
88
|
+
"react-native": "0.88.1",
|
|
89
|
+
"react-native-builder-bob": "^0.44.1",
|
|
90
|
+
"react-native-reanimated": "4.7.1",
|
|
91
|
+
"react-native-safe-area-context": "~5.10.1",
|
|
92
|
+
"react-native-worklets": "0.13.0",
|
|
93
|
+
"react-test-renderer": "19.3.0",
|
|
94
|
+
"turbo": "^2.11.10",
|
|
95
|
+
"typescript": "^6.0.3"
|
|
96
|
+
},
|
|
97
|
+
"peerDependencies": {
|
|
98
|
+
"react": "*",
|
|
99
|
+
"react-native": "*",
|
|
100
|
+
"react-native-reanimated": ">=4.0.0",
|
|
101
|
+
"react-native-worklets": "*"
|
|
102
|
+
},
|
|
103
|
+
"workspaces": [
|
|
104
|
+
"example"
|
|
105
|
+
],
|
|
106
|
+
"packageManager": "yarn@4.18.1",
|
|
107
|
+
"react-native-builder-bob": {
|
|
108
|
+
"source": "src",
|
|
109
|
+
"output": "lib",
|
|
110
|
+
"targets": [
|
|
111
|
+
[
|
|
112
|
+
"module",
|
|
113
|
+
{
|
|
114
|
+
"esm": true
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"typescript",
|
|
119
|
+
{
|
|
120
|
+
"project": "tsconfig.build.json"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"prettier": {
|
|
126
|
+
"quoteProps": "consistent",
|
|
127
|
+
"singleQuote": true,
|
|
128
|
+
"tabWidth": 2,
|
|
129
|
+
"trailingComma": "es5",
|
|
130
|
+
"useTabs": false
|
|
131
|
+
},
|
|
132
|
+
"jest": {
|
|
133
|
+
"preset": "@react-native/jest-preset",
|
|
134
|
+
"testEnvironmentOptions": {
|
|
135
|
+
"customExportConditions": [
|
|
136
|
+
"require",
|
|
137
|
+
"react-native",
|
|
138
|
+
"rn-code-input-source"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"modulePathIgnorePatterns": [
|
|
142
|
+
"<rootDir>/example/node_modules",
|
|
143
|
+
"<rootDir>/lib/"
|
|
144
|
+
],
|
|
145
|
+
"setupFiles": [
|
|
146
|
+
"<rootDir>/jest.setup.js"
|
|
147
|
+
],
|
|
148
|
+
"resolver": "react-native-reanimated/jest/resolver",
|
|
149
|
+
"transformIgnorePatterns": [
|
|
150
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|react-native-reanimated|react-native-worklets|react-native-safe-area-context)/)"
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
"create-react-native-library": {
|
|
154
|
+
"type": "library",
|
|
155
|
+
"languages": "js",
|
|
156
|
+
"tools": [
|
|
157
|
+
"eslint",
|
|
158
|
+
"jest"
|
|
159
|
+
],
|
|
160
|
+
"version": "0.64.0"
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/Cell.tsx
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
Text,
|
|
5
|
+
View,
|
|
6
|
+
type StyleProp,
|
|
7
|
+
type TextStyle,
|
|
8
|
+
type ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import Animated, {
|
|
11
|
+
Easing,
|
|
12
|
+
ReduceMotion,
|
|
13
|
+
useAnimatedStyle,
|
|
14
|
+
useSharedValue,
|
|
15
|
+
withRepeat,
|
|
16
|
+
withSequence,
|
|
17
|
+
withSpring,
|
|
18
|
+
withTiming,
|
|
19
|
+
} from 'react-native-reanimated';
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
char: string;
|
|
23
|
+
masked: boolean;
|
|
24
|
+
active: boolean;
|
|
25
|
+
error: boolean;
|
|
26
|
+
style?: StyleProp<ViewStyle>;
|
|
27
|
+
activeStyle?: StyleProp<ViewStyle>;
|
|
28
|
+
filledStyle?: StyleProp<ViewStyle>;
|
|
29
|
+
errorStyle?: StyleProp<ViewStyle>;
|
|
30
|
+
textStyle?: StyleProp<TextStyle>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Cell({
|
|
34
|
+
char,
|
|
35
|
+
masked,
|
|
36
|
+
active,
|
|
37
|
+
error,
|
|
38
|
+
style,
|
|
39
|
+
activeStyle,
|
|
40
|
+
filledStyle,
|
|
41
|
+
errorStyle,
|
|
42
|
+
textStyle,
|
|
43
|
+
}: Props) {
|
|
44
|
+
const pop = useSharedValue(1);
|
|
45
|
+
const fade = useSharedValue(char ? 1 : 0);
|
|
46
|
+
const caret = useSharedValue(1);
|
|
47
|
+
const filled = char.length > 0;
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (filled) {
|
|
51
|
+
fade.value = withTiming(1, {
|
|
52
|
+
duration: 120,
|
|
53
|
+
reduceMotion: ReduceMotion.System,
|
|
54
|
+
});
|
|
55
|
+
pop.value = withSequence(
|
|
56
|
+
withTiming(1.12, {
|
|
57
|
+
duration: 90,
|
|
58
|
+
easing: Easing.out(Easing.quad),
|
|
59
|
+
reduceMotion: ReduceMotion.System,
|
|
60
|
+
}),
|
|
61
|
+
withSpring(1, {
|
|
62
|
+
damping: 14,
|
|
63
|
+
stiffness: 320,
|
|
64
|
+
reduceMotion: ReduceMotion.System,
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
} else {
|
|
68
|
+
fade.value = withTiming(0, {
|
|
69
|
+
duration: 90,
|
|
70
|
+
reduceMotion: ReduceMotion.System,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}, [filled, fade, pop]);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (active && !filled) {
|
|
77
|
+
caret.value = withRepeat(
|
|
78
|
+
withSequence(
|
|
79
|
+
withTiming(0, { duration: 450, reduceMotion: ReduceMotion.System }),
|
|
80
|
+
withTiming(1, { duration: 450, reduceMotion: ReduceMotion.System })
|
|
81
|
+
),
|
|
82
|
+
-1,
|
|
83
|
+
false
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
caret.value = 0;
|
|
87
|
+
}
|
|
88
|
+
}, [active, filled, caret]);
|
|
89
|
+
|
|
90
|
+
const cellStyle = useAnimatedStyle(() => ({
|
|
91
|
+
transform: [{ scale: pop.value }],
|
|
92
|
+
}));
|
|
93
|
+
const charStyle = useAnimatedStyle(() => ({ opacity: fade.value }));
|
|
94
|
+
const caretStyle = useAnimatedStyle(() => ({ opacity: caret.value }));
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Animated.View
|
|
98
|
+
style={[
|
|
99
|
+
styles.cell,
|
|
100
|
+
style,
|
|
101
|
+
filled && [styles.filled, filledStyle],
|
|
102
|
+
active && [styles.active, activeStyle],
|
|
103
|
+
error && [styles.error, errorStyle],
|
|
104
|
+
cellStyle,
|
|
105
|
+
]}
|
|
106
|
+
>
|
|
107
|
+
<Animated.View style={charStyle}>
|
|
108
|
+
{masked && filled ? (
|
|
109
|
+
<View style={[styles.dot, error && styles.dotError]} />
|
|
110
|
+
) : (
|
|
111
|
+
<Text style={[styles.text, textStyle, error && styles.textError]}>
|
|
112
|
+
{char}
|
|
113
|
+
</Text>
|
|
114
|
+
)}
|
|
115
|
+
</Animated.View>
|
|
116
|
+
{active && !filled ? (
|
|
117
|
+
<Animated.View style={[styles.caret, caretStyle]} />
|
|
118
|
+
) : null}
|
|
119
|
+
</Animated.View>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const styles = StyleSheet.create({
|
|
124
|
+
cell: {
|
|
125
|
+
width: 48,
|
|
126
|
+
height: 58,
|
|
127
|
+
borderRadius: 12,
|
|
128
|
+
borderWidth: 1.5,
|
|
129
|
+
borderColor: 'rgba(128,128,128,0.35)',
|
|
130
|
+
alignItems: 'center',
|
|
131
|
+
justifyContent: 'center',
|
|
132
|
+
},
|
|
133
|
+
filled: { borderColor: 'rgba(128,128,128,0.6)' },
|
|
134
|
+
active: { borderColor: '#6C8CFF' },
|
|
135
|
+
error: { borderColor: '#FF6B6B' },
|
|
136
|
+
text: {
|
|
137
|
+
fontSize: 24,
|
|
138
|
+
fontWeight: '700',
|
|
139
|
+
color: '#F3F4F6',
|
|
140
|
+
fontVariant: ['tabular-nums'],
|
|
141
|
+
},
|
|
142
|
+
textError: { color: '#FF6B6B' },
|
|
143
|
+
dot: { width: 12, height: 12, borderRadius: 6, backgroundColor: '#F3F4F6' },
|
|
144
|
+
dotError: { backgroundColor: '#FF6B6B' },
|
|
145
|
+
caret: {
|
|
146
|
+
position: 'absolute',
|
|
147
|
+
width: 2,
|
|
148
|
+
height: 24,
|
|
149
|
+
borderRadius: 1,
|
|
150
|
+
backgroundColor: '#6C8CFF',
|
|
151
|
+
},
|
|
152
|
+
});
|