Skip to content

Commit 1be5c33

Browse files
committed
cleanup, remove unnecessary blocks
1 parent 0789f2d commit 1be5c33

File tree

1 file changed

+63
-67
lines changed

1 file changed

+63
-67
lines changed

src/index.tsx

Lines changed: 63 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
459459
size,
460460
offset,
461461
style,
462-
onLayout: async () => {
462+
onLayout: () => {
463463
if (this.state.activeKey !== key) this.measureCell(key);
464464
},
465465
onUnmount: () => initialized.setValue(0),
@@ -654,18 +654,11 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
654654
}
655655
};
656656

657-
isAtTopEdge = cond(
658-
lessOrEq(this.distToTopEdge, this.props.autoscrollThreshold!),
659-
1,
660-
0
661-
);
662-
663-
isAtBottomEdge = cond(
664-
lessOrEq(this.distToBottomEdge, this.props.autoscrollThreshold!),
665-
1,
666-
0
657+
isAtTopEdge = lessOrEq(this.distToTopEdge, this.props.autoscrollThreshold!);
658+
isAtBottomEdge = lessOrEq(
659+
this.distToBottomEdge,
660+
this.props.autoscrollThreshold!
667661
);
668-
669662
isAtEdge = or(this.isAtBottomEdge, this.isAtTopEdge);
670663

671664
autoscrollParams = [
@@ -684,7 +677,7 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
684677
eq(this.panGestureState, GestureState.ACTIVE),
685678
not(this.isAutoscrolling.native)
686679
),
687-
[call(this.autoscrollParams, this.autoscroll)]
680+
call(this.autoscrollParams, this.autoscroll)
688681
);
689682

690683
onScroll = event([
@@ -741,13 +734,11 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
741734
x,
742735
y
743736
}: GestureHandlerGestureEventNativeEvent & TapGestureHandlerEventExtra) =>
744-
block([
745-
cond(and(neq(state, this.tapGestureState), not(this.disabled)), [
746-
set(this.tapGestureState, state),
747-
cond(eq(state, GestureState.BEGAN), [
748-
set(this.isPressedIn.native, 1),
749-
set(this.touchAbsolute, this.props.horizontal ? x : y)
750-
])
737+
cond(and(neq(state, this.tapGestureState), not(this.disabled)), [
738+
set(this.tapGestureState, state),
739+
cond(eq(state, GestureState.BEGAN), [
740+
set(this.isPressedIn.native, 1),
741+
set(this.touchAbsolute, this.props.horizontal ? x : y)
751742
])
752743
])
753744
}
@@ -760,68 +751,53 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
760751
x,
761752
y
762753
}: GestureHandlerGestureEventNativeEvent & PanGestureHandlerEventExtra) =>
763-
block([
764-
cond(and(neq(state, this.panGestureState), not(this.disabled)), [
765-
set(this.panGestureState, state),
766-
cond(
767-
eq(this.panGestureState, GestureState.ACTIVE),
768-
set(
769-
this.activationDistance,
770-
sub(this.touchAbsolute, this.props.horizontal ? x : y)
771-
)
772-
),
773-
cond(
774-
or(
775-
eq(state, GestureState.END),
776-
eq(state, GestureState.CANCELLED),
777-
eq(state, GestureState.FAILED)
778-
),
779-
this.onGestureRelease
754+
cond(and(neq(state, this.panGestureState), not(this.disabled)), [
755+
set(this.panGestureState, state),
756+
cond(
757+
eq(this.panGestureState, GestureState.ACTIVE),
758+
set(
759+
this.activationDistance,
760+
sub(this.touchAbsolute, this.props.horizontal ? x : y)
780761
)
781-
])
762+
),
763+
cond(
764+
or(
765+
eq(state, GestureState.END),
766+
eq(state, GestureState.CANCELLED),
767+
eq(state, GestureState.FAILED)
768+
),
769+
this.onGestureRelease
770+
)
782771
])
783772
}
784773
]);
785774

786775
onPanGestureEvent = event([
787776
{
788777
nativeEvent: ({ x, y }: PanGestureHandlerEventExtra) =>
789-
block([
790-
cond(
791-
and(
792-
this.isHovering,
793-
eq(this.panGestureState, GestureState.ACTIVE),
794-
not(this.disabled)
795-
),
796-
[
797-
cond(not(this.hasMoved), set(this.hasMoved, 1)),
798-
set(
799-
this.touchAbsolute,
800-
add(this.props.horizontal ? x : y, this.activationDistance)
801-
),
802-
onChange(this.touchAbsolute, this.checkAutoscroll)
803-
]
804-
)
805-
])
778+
cond(
779+
and(
780+
this.isHovering,
781+
eq(this.panGestureState, GestureState.ACTIVE),
782+
not(this.disabled)
783+
),
784+
[
785+
cond(not(this.hasMoved), set(this.hasMoved, 1)),
786+
set(
787+
this.touchAbsolute,
788+
add(this.props.horizontal ? x : y, this.activationDistance)
789+
)
790+
]
791+
)
806792
}
807793
]);
808794

809-
runHoverClock = cond(clockRunning(this.hoverClock), [
810-
spring(this.hoverClock, this.hoverAnimState, this.hoverAnimConfig),
811-
cond(eq(this.hoverAnimState.finished, 1), [
812-
stopClock(this.hoverClock),
813-
call(this.moveEndParams, this.onDragEnd),
814-
this.resetHoverSpring,
815-
set(this.hasMoved, 0)
816-
]),
817-
this.hoverAnimState.position
818-
]);
819-
820795
hoverComponentTranslate = cond(
821796
clockRunning(this.hoverClock),
822-
this.runHoverClock,
797+
this.hoverAnimState.position,
823798
this.hoverAnim
824799
);
800+
825801
hoverComponentOpacity = and(
826802
this.isHovering,
827803
neq(this.panGestureState, GestureState.CANCELLED)
@@ -964,6 +940,26 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
964940
/>
965941
{!!hoverComponent && this.renderHoverComponent()}
966942
{debug && this.renderDebug()}
943+
<Animated.Code>
944+
{() =>
945+
block([
946+
onChange(this.touchAbsolute, this.checkAutoscroll),
947+
cond(clockRunning(this.hoverClock), [
948+
spring(
949+
this.hoverClock,
950+
this.hoverAnimState,
951+
this.hoverAnimConfig
952+
),
953+
cond(eq(this.hoverAnimState.finished, 1), [
954+
stopClock(this.hoverClock),
955+
call(this.moveEndParams, this.onDragEnd),
956+
this.resetHoverSpring,
957+
set(this.hasMoved, 0)
958+
])
959+
])
960+
])
961+
}
962+
</Animated.Code>
967963
</Animated.View>
968964
</PanGestureHandler>
969965
</Animated.View>

0 commit comments

Comments
 (0)