Skip to content

Commit 3098cc0

Browse files
authored
fix(📦): Fix typings (#11)
1 parent 86124f7 commit 3098cc0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Interactable.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ interface InteractableProps {
262262
animatedValueY?: any;
263263
style?: StyleProp<ViewStyle>;
264264
dragEnabled: boolean;
265-
onSnap: (e: { nativeEvent: SnapPoint & { index: number } }) => void;
266-
onStop: (e: { nativeEvent: { x: number, y: number } }) => void;
267-
onDrag: (e: { nativeEvent: { x: number, y: number, state: "start" | "end" } }) => void;
265+
onSnap?: (e: { nativeEvent: SnapPoint & { index: number } }) => void;
266+
onStop?: (e: { nativeEvent: { x: number, y: number } }) => void;
267+
onDrag?: (e: { nativeEvent: { x: number, y: number, state: "start" | "end" } }) => void;
268268
initialPosition: Position;
269269
dragToss: number;
270270
dragWithSpring?: {tension: number, damping: number};
@@ -396,7 +396,10 @@ export default class Interactable extends React.PureComponent<InteractableProps>
396396
}
397397

398398
const handleStartDrag = props.onDrag
399-
&& call([target.x, target.y], ([x, y]) => props.onDrag({ nativeEvent: { x, y, state: "start" } }));
399+
&& call(
400+
[target.x, target.y],
401+
([x, y]) => props.onDrag && props.onDrag({ nativeEvent: { x, y, state: "start" } }),
402+
);
400403

401404
const snapBuckets: [any[], any[], any[]] = [[], [], []];
402405
const snapAnchor = {
@@ -480,10 +483,10 @@ export default class Interactable extends React.PureComponent<InteractableProps>
480483
),
481484
block([
482485
props.onStop
483-
&& cond(
486+
? cond(
484487
clockRunning(clock),
485-
call([target.x, target.y], ([x, y]) => props.onStop({ nativeEvent: { x, y } })),
486-
),
488+
call([target.x, target.y], ([x, y]) => props.onStop && props.onStop({ nativeEvent: { x, y } })),
489+
) : [],
487490
stopClock(clock),
488491
]),
489492
startClock(clock),
@@ -522,12 +525,12 @@ export default class Interactable extends React.PureComponent<InteractableProps>
522525
const step = cond(
523526
eq(state, State.ACTIVE),
524527
[
525-
cond(dragging, 0, [
526-
handleStartDrag,
528+
cond(dragging, 0, block([
529+
handleStartDrag || [],
527530
startClock(clock),
528531
set(dragging, 1),
529532
set(start, x),
530-
]),
533+
])),
531534
set(anchor, add(start, drag)),
532535
cond(dt, dragBehaviors[axis]),
533536
],

0 commit comments

Comments
 (0)