@@ -5,72 +5,15 @@ import React, {
55 useEffect ,
66 useImperativeHandle ,
77} from 'react' ;
8- import {
9- View ,
10- Text ,
11- Image ,
12- Animated ,
13- StyleProp ,
14- ViewStyle ,
15- Pressable ,
16- PressableProps ,
17- TextStyle ,
18- ImageStyle ,
19- ImageSourcePropType ,
20- } from 'react-native' ;
8+ import { View , Text , Image , Animated , Pressable } from 'react-native' ;
219import useBounceAnimation from './hooks/useBounceAnimation' ;
22- import useStateWIthCallback from './helpers/useStateWIthCallback ' ;
10+ import useStateWithCallback from './helpers/useStateWithCallback ' ;
2311import styles from './BouncyCheckbox.style' ;
24-
25- const AnimationValues = {
26- BounceIn : 0.9 ,
27- BounceOut : 1 ,
28- VelocityIn : 0.1 ,
29- VelocityOut : 0.4 ,
30- BouncinessIn : 20 ,
31- BouncinessOut : 20 ,
32- } ;
33-
34- type BasePressableProps = Pick <
35- PressableProps ,
36- Exclude < keyof PressableProps , 'onPress' | 'onLongPress' >
37- > ;
38-
39- export interface BouncyCheckboxProps extends BasePressableProps {
40- size ?: number ;
41- text ?: string ;
42- testID ?: string ;
43- fillColor ?: string ;
44- isChecked ?: boolean ;
45- unFillColor ?: string ;
46- disableText ?: boolean ;
47- bounceEffect ?: number ;
48- bounceFriction ?: number ;
49- useNativeDriver ?: boolean ;
50- bounceEffectIn ?: number ;
51- bounceEffectOut ?: number ;
52- bounceVelocityIn ?: number ;
53- bounceVelocityOut ?: number ;
54- bouncinessIn ?: number ;
55- bouncinessOut ?: number ;
56- ImageComponent ?: any ;
57- TouchableComponent ?: any ;
58- iconComponent ?: React . ReactNode ;
59- textComponent ?: React . ReactNode ;
60- iconStyle ?: StyleProp < ViewStyle > ;
61- innerIconStyle ?: StyleProp < ViewStyle > ;
62- style ?: StyleProp < ViewStyle > ;
63- textStyle ?: StyleProp < TextStyle > ;
64- iconImageStyle ?: StyleProp < ImageStyle > ;
65- textContainerStyle ?: StyleProp < ViewStyle > ;
66- checkIconImageSource ?: ImageSourcePropType ;
67- onPress ?: ( checked : boolean ) => void ;
68- onLongPress ?: ( checked : boolean ) => void ;
69- }
70-
71- export interface BouncyCheckboxHandle {
72- onCheckboxPress : ( ) => void ;
73- }
12+ import {
13+ AnimationValues ,
14+ BouncyCheckboxHandle ,
15+ BouncyCheckboxProps ,
16+ } from './BouncyCheckbox.type' ;
7417
7518const BouncyCheckbox : React . ForwardRefRenderFunction <
7619 BouncyCheckboxHandle ,
@@ -81,7 +24,6 @@ const BouncyCheckbox: React.ForwardRefRenderFunction<
8124 iconStyle,
8225 iconComponent,
8326 iconImageStyle,
84- isChecked,
8527 innerIconStyle,
8628 text,
8729 textComponent,
@@ -95,6 +37,7 @@ const BouncyCheckbox: React.ForwardRefRenderFunction<
9537 ImageComponent = Image ,
9638 unFillColor = 'transparent' ,
9739 disableText = false ,
40+ isChecked = undefined ,
9841 checkIconImageSource = require ( './check.png' ) ,
9942 bounceEffectIn = AnimationValues . BounceIn ,
10043 bounceEffectOut = AnimationValues . BounceOut ,
@@ -106,7 +49,7 @@ const BouncyCheckbox: React.ForwardRefRenderFunction<
10649 ...rest
10750 } = props ;
10851
109- const [ checked , setChecked ] = useStateWIthCallback ( isChecked || false ) ;
52+ const [ checked , setChecked ] = useStateWithCallback ( isChecked || false ) ;
11053
11154 const { bounceAnimation, syntheticBounceAnimation, bounceValue} =
11255 useBounceAnimation ( ) ;
@@ -136,16 +79,19 @@ const BouncyCheckbox: React.ForwardRefRenderFunction<
13679 syntheticBounceAnimation ,
13780 ] ) ;
13881
139- useImperativeHandle ( ref , ( ) => ( { onCheckboxPress} ) , [ onCheckboxPress ] ) ;
140-
141- const handleLongPress = ( ) => {
82+ const onCheckboxLongPress = useCallback ( ( ) => {
14283 if ( ! onLongPress ) {
14384 return ;
14485 }
14586 setChecked ( ! checked , newCheckedValue => {
14687 onLongPress && onLongPress ( newCheckedValue ) ;
14788 } ) ;
148- } ;
89+ } , [ checked , onLongPress , setChecked ] ) ;
90+
91+ useImperativeHandle ( ref , ( ) => ( { onCheckboxPress, onCheckboxLongPress} ) , [
92+ onCheckboxPress ,
93+ onCheckboxLongPress ,
94+ ] ) ;
14995
15096 const renderCheckIcon = ( ) => {
15197 const scaleAnimation = { transform : [ { scale : bounceValue } ] } ;
@@ -193,7 +139,7 @@ const BouncyCheckbox: React.ForwardRefRenderFunction<
193139 bounceAnimation ( bounceEffectOut , bounceVelocityOut , bouncinessOut ) ;
194140 } }
195141 onPress = { onCheckboxPress }
196- onLongPress = { handleLongPress }
142+ onLongPress = { onCheckboxLongPress }
197143 { ...rest } >
198144 { renderCheckIcon ( ) }
199145 { renderCheckboxText ( ) }
0 commit comments