@@ -7,7 +7,15 @@ import {
77 GestureHandlerStateChangeNativeEvent
88} from "react-native-gesture-handler" ;
99import Animated from "react-native-reanimated" ;
10- import { springFill } from "./procs" ;
10+ import {
11+ springFill ,
12+ getOpenPct ,
13+ getLeftActive ,
14+ getMaxTranslate ,
15+ getMinTranslate ,
16+ getIsActive ,
17+ getOnPanEvent
18+ } from "./procs" ;
1119const {
1220 event,
1321 cond,
@@ -134,25 +142,21 @@ class SwipeableItem<T> extends React.PureComponent<Props<T>> {
134142 ? this . props . snapPointsRight ! [ this . props . snapPointsRight ! . length - 1 ]
135143 : 0
136144 ) ;
137- percentOpenLeft = cond (
145+
146+ percentOpenLeft = getOpenPct (
138147 this . swipingLeft ,
139- divide ( abs ( this . animState . position ) , this . leftWidth )
148+ this . animState . position ,
149+ this . leftWidth
140150 ) ;
141- percentOpenRight = cond (
151+ percentOpenRight = getOpenPct (
142152 this . swipingRight ,
143- divide ( abs ( this . animState . position ) , this . rightWidth )
144- ) ;
145- isSwiping = or ( this . swipingLeft , this . swipingRight ) ;
146-
147- leftActive = or (
148- this . swipingLeft ,
149- and ( not ( this . isSwiping ) , lessThan ( this . panX , 0 ) )
153+ this . animState . position ,
154+ this . rightWidth
150155 ) ;
151156
152- isActive = or (
153- eq ( this . gestureState , GestureState . ACTIVE ) ,
154- eq ( this . gestureState , GestureState . BEGAN )
155- ) ;
157+ isSwiping = or ( this . swipingLeft , this . swipingRight ) ;
158+ leftActive = getLeftActive ( this . swipingLeft , this . isSwiping , this . panX ) ;
159+ isActive = getIsActive ( this . gestureState ) ;
156160
157161 onSwipeLeftChange = ( [ isSwiping ] : readonly number [ ] ) => {
158162 if ( isSwiping ) this . setState ( { swipeDirection : OpenDirection . LEFT } ) ;
@@ -269,16 +273,15 @@ class SwipeableItem<T> extends React.PureComponent<Props<T>> {
269273 this . props . onChange ( { open : OpenDirection . NONE , snapPoint : 0 } ) ;
270274 } ;
271275
272- maxTranslate = cond (
276+ maxTranslate = getMaxTranslate (
273277 this . hasRight ,
274- add ( this . rightWidth , this . props . overSwipe ) ,
275- 0
278+ this . rightWidth ,
279+ this . props . overSwipe
276280 ) ;
277-
278- minTranslate = cond (
281+ minTranslate = getMinTranslate (
279282 this . hasLeft ,
280- multiply ( - 1 , add ( this . leftWidth , this . props . overSwipe ) ) ,
281- 0
283+ this . leftWidth ,
284+ this . props . overSwipe
282285 ) ;
283286
284287 onHandlerStateChange = event ( [
@@ -296,13 +299,12 @@ class SwipeableItem<T> extends React.PureComponent<Props<T>> {
296299 set ( this . panX , translationX ) ,
297300 set ( this . velocity , velocityX ) ,
298301 set ( this . tempTranslate , add ( translationX , this . prevTranslate ) ) ,
299- cond (
300- and (
301- eq ( this . gestureState , GestureState . ACTIVE ) ,
302- lessOrEq ( this . tempTranslate , this . maxTranslate ) ,
303- greaterOrEq ( this . tempTranslate , this . minTranslate )
304- ) ,
305- set ( this . animState . position , this . tempTranslate )
302+ getOnPanEvent (
303+ this . gestureState ,
304+ this . tempTranslate ,
305+ this . maxTranslate ,
306+ this . minTranslate ,
307+ this . animState . position
306308 )
307309 ] )
308310 }
0 commit comments