Skip to content

Commit 74b33d2

Browse files
committed
feat: onLongPress
1 parent 868e445 commit 74b33d2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

example/lib/BouncyCheckbox.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const AnimationValues = {
2727

2828
type BasePressableProps = Pick<
2929
PressableProps,
30-
Exclude<keyof PressableProps, 'onPress'>
30+
Exclude<keyof PressableProps, 'onPress' | 'onLongPress'>
3131
>;
3232

3333
interface BouncyCheckboxProps extends BasePressableProps {
@@ -59,6 +59,7 @@ interface BouncyCheckboxProps extends BasePressableProps {
5959
textContainerStyle?: StyleProp<ViewStyle>;
6060
checkIconImageSource?: ImageSourcePropType;
6161
onPress?: (checked: boolean) => void;
62+
onLongPress?: (checked: boolean) => void;
6263
}
6364

6465
const BouncyCheckbox: React.FC<BouncyCheckboxProps> = ({
@@ -74,6 +75,7 @@ const BouncyCheckbox: React.FC<BouncyCheckboxProps> = ({
7475
textContainerStyle,
7576
size = 25,
7677
onPress,
78+
onLongPress,
7779
fillColor = '#ffc484',
7880
ImageComponent = Image,
7981
unFillColor = 'transparent',
@@ -103,6 +105,16 @@ const BouncyCheckbox: React.FC<BouncyCheckboxProps> = ({
103105
}
104106
};
105107

108+
const handleLongPress = () => {
109+
if (!disableBuiltInState) {
110+
setChecked(!checked, newCheckedValue => {
111+
onLongPress && onLongPress(newCheckedValue);
112+
});
113+
} else {
114+
onLongPress && onLongPress(checked);
115+
}
116+
};
117+
106118
const renderCheckIcon = () => {
107119
const checkStatus = disableBuiltInState ? isChecked! : checked;
108120
const scaleAnimation = {transform: [{scale: bounceValue}]};
@@ -155,6 +167,7 @@ const BouncyCheckbox: React.FC<BouncyCheckboxProps> = ({
155167
animateBounce(bounceEffectOut, bounceVelocityOut, bouncinessOut);
156168
}}
157169
onPress={handlePress}
170+
onLongPress={handleLongPress}
158171
{...rest}>
159172
{renderCheckIcon()}
160173
{renderCheckboxText()}

0 commit comments

Comments
 (0)