From 3098cc0e4559fd3eab1da37c0333b0a329bc7a53 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Thu, 2 May 2019 13:32:07 +0200 Subject: [PATCH] =?UTF-8?q?fix(=F0=9F=93=A6):=20Fix=20typings=20(#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Interactable.tsx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Interactable.tsx b/src/Interactable.tsx index f0e57700..32bde6ac 100644 --- a/src/Interactable.tsx +++ b/src/Interactable.tsx @@ -262,9 +262,9 @@ interface InteractableProps { animatedValueY?: any; style?: StyleProp; dragEnabled: boolean; - onSnap: (e: { nativeEvent: SnapPoint & { index: number } }) => void; - onStop: (e: { nativeEvent: { x: number, y: number } }) => void; - onDrag: (e: { nativeEvent: { x: number, y: number, state: "start" | "end" } }) => void; + onSnap?: (e: { nativeEvent: SnapPoint & { index: number } }) => void; + onStop?: (e: { nativeEvent: { x: number, y: number } }) => void; + onDrag?: (e: { nativeEvent: { x: number, y: number, state: "start" | "end" } }) => void; initialPosition: Position; dragToss: number; dragWithSpring?: {tension: number, damping: number}; @@ -396,7 +396,10 @@ export default class Interactable extends React.PureComponent } const handleStartDrag = props.onDrag - && call([target.x, target.y], ([x, y]) => props.onDrag({ nativeEvent: { x, y, state: "start" } })); + && call( + [target.x, target.y], + ([x, y]) => props.onDrag && props.onDrag({ nativeEvent: { x, y, state: "start" } }), + ); const snapBuckets: [any[], any[], any[]] = [[], [], []]; const snapAnchor = { @@ -480,10 +483,10 @@ export default class Interactable extends React.PureComponent ), block([ props.onStop - && cond( + ? cond( clockRunning(clock), - call([target.x, target.y], ([x, y]) => props.onStop({ nativeEvent: { x, y } })), - ), + call([target.x, target.y], ([x, y]) => props.onStop && props.onStop({ nativeEvent: { x, y } })), + ) : [], stopClock(clock), ]), startClock(clock), @@ -522,12 +525,12 @@ export default class Interactable extends React.PureComponent const step = cond( eq(state, State.ACTIVE), [ - cond(dragging, 0, [ - handleStartDrag, + cond(dragging, 0, block([ + handleStartDrag || [], startClock(clock), set(dragging, 1), set(start, x), - ]), + ])), set(anchor, add(start, drag)), cond(dt, dragBehaviors[axis]), ],