Skip to content

Commit 58c5004

Browse files
committed
feat: fix id and wrong press animation + add buttonStyle
1 parent bb4dafa commit 58c5004

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/PinCodeKey.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import {
44
type ColorValue,
55
Easing,
66
Pressable,
7+
type RegisteredStyle,
78
Text,
89
type TextStyle,
910
TouchableOpacity,
11+
type ViewStyle,
1012
} from 'react-native';
1113
import type { NumberProp } from 'react-native-svg';
1214
import BackspaceKeyIcon from './BackspaceKeyIcon';
1315
import BioMetricIcon from './BioMetricIcon';
1416

17+
const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
18+
1519
function PinCodeKey({
1620
item,
1721
onKeyPress,
@@ -29,6 +33,7 @@ function PinCodeKey({
2933
disable = false,
3034
animated = false,
3135
animationProps,
36+
style,
3237
}: {
3338
item: string | number;
3439
onKeyPress: (value: any) => void;
@@ -51,9 +56,9 @@ function PinCodeKey({
5156
pressInDuration?: number;
5257
pressOutDuration?: number;
5358
};
59+
style?: RegisteredStyle<ViewStyle>;
5460
}) {
5561
// animations
56-
const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
5762
const anim = React.useRef(new Animated.Value(0)).current;
5863

5964
const bgColor = anim.interpolate({
@@ -150,9 +155,9 @@ function PinCodeKey({
150155
justifyContent: 'center',
151156
alignItems: 'center',
152157
flex: 1,
153-
borderRadius: 12,
154158
backgroundColor: bgColor,
155159
},
160+
style,
156161
]}
157162
disabled={disable}
158163
>
@@ -163,11 +168,14 @@ function PinCodeKey({
163168
return (
164169
<TouchableOpacity
165170
onPress={() => getOnPress()}
166-
style={{
167-
justifyContent: 'center',
168-
alignItems: 'center',
169-
flex: 1,
170-
}}
171+
style={[
172+
{
173+
justifyContent: 'center',
174+
alignItems: 'center',
175+
flex: 1,
176+
},
177+
style,
178+
]}
171179
disabled={disable}
172180
>
173181
{getContent()}

src/keypad.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import React, { type ComponentProps, useId } from 'react';
2-
import type { ColorValue, StyleProp, TextStyle, ViewStyle } from 'react-native';
1+
import React, { type ComponentProps } from 'react';
2+
import type {
3+
ColorValue,
4+
RegisteredStyle,
5+
StyleProp,
6+
TextStyle,
7+
ViewStyle,
8+
} from 'react-native';
39
import type { NumberProp } from 'react-native-svg';
410
import PinCodeKey from './PinCodeKey';
511
import PinCodeRow from './PinCodeRow';
@@ -21,6 +27,7 @@ export const Keypad = ({
2127
disable = false,
2228
animated = false,
2329
rowStyle,
30+
buttonStyle,
2431
animationProps,
2532
}: {
2633
onKeyPress: (value: any) => void;
@@ -39,6 +46,7 @@ export const Keypad = ({
3946
disable?: boolean;
4047
animated?: boolean;
4148
rowStyle?: StyleProp<ViewStyle>;
49+
buttonStyle?: RegisteredStyle<ViewStyle>;
4250
animationProps?: ComponentProps<typeof PinCodeKey>['animationProps'];
4351
}) => {
4452
// ---------------------------------------------------
@@ -50,7 +58,6 @@ export const Keypad = ({
5058
[7, 8, 9],
5159
['auth', 0, 'delete'],
5260
];
53-
const id = useId();
5461
// ---------------------------------------------------
5562
// @ Main View
5663
// ---------------------------------------------------
@@ -59,7 +66,7 @@ export const Keypad = ({
5966
{keys.map((list: any) => (
6067
<PinCodeRow
6168
rowReverse={rowReverse}
62-
key={`${id}-keypad-row`}
69+
key={`row-${list.join('-')}`}
6370
style={rowStyle}
6471
>
6572
{list.map((item: string | number) => (
@@ -81,6 +88,7 @@ export const Keypad = ({
8188
disable={disable}
8289
animated={animated}
8390
animationProps={animationProps}
91+
style={buttonStyle}
8492
/>
8593
))}
8694
</PinCodeRow>

0 commit comments

Comments
 (0)