Skip to content

Commit aa8b154

Browse files
committed
remove TapGestureHandler
1 parent 1be5c33 commit aa8b154

File tree

1 file changed

+57
-105
lines changed

1 file changed

+57
-105
lines changed

src/index.tsx

Lines changed: 57 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import {
1313
TapGestureHandler,
1414
State as GestureState,
1515
FlatList,
16-
TapGestureHandlerGestureEvent,
17-
TapGestureHandlerEventExtra,
1816
GestureHandlerGestureEventNativeEvent,
1917
PanGestureHandlerEventExtra
2018
} from "react-native-gesture-handler";
2119
import Animated from "react-native-reanimated";
22-
import { getOnCellTap, springFill, setupCell } from "./procs";
20+
import { springFill, setupCell } from "./procs";
2321

2422
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
2523

@@ -130,7 +128,6 @@ type CellData = {
130128
currentIndex: Animated.Value<number>;
131129
onLayout: () => void;
132130
onUnmount: () => void;
133-
onCellTap: (event: TapGestureHandlerGestureEvent) => void;
134131
};
135132

136133
// Run callback on next paint:
@@ -292,9 +289,12 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
292289
if (index !== undefined) {
293290
this.spacerIndex.setValue(index);
294291
this.activeIndex.setValue(index);
292+
this.touchCellOffset.setValue(0);
293+
this.isPressedIn.native.setValue(1);
295294
}
296295
const cellData = this.cellData.get(this.state.activeKey);
297296
if (cellData) {
297+
this.touchAbsolute.setValue(sub(cellData.offset, this.scrollOffset));
298298
this.activeCellSize.setValue(cellData.measurements.size);
299299
}
300300
}
@@ -449,6 +449,7 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
449449
const transform = this.props.horizontal
450450
? [{ translateX: anim }]
451451
: [{ translateY: anim }];
452+
452453
const style = {
453454
transform
454455
};
@@ -463,28 +464,6 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
463464
if (this.state.activeKey !== key) this.measureCell(key);
464465
},
465466
onUnmount: () => initialized.setValue(0),
466-
onCellTap: event([
467-
{
468-
nativeEvent: ({
469-
state,
470-
y,
471-
x
472-
}: TapGestureHandlerEventExtra &
473-
GestureHandlerGestureEventNativeEvent) =>
474-
getOnCellTap(
475-
state,
476-
tapState,
477-
this.disabled,
478-
offset,
479-
this.scrollOffset,
480-
this.hasMoved,
481-
this.hoverTo,
482-
this.touchCellOffset,
483-
this.onGestureRelease,
484-
this.props.horizontal ? x : y
485-
)
486-
}
487-
]),
488467
measurements: {
489468
size: 0,
490469
offset: 0
@@ -727,23 +706,6 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
727706
)
728707
];
729708

730-
onContainerTapStateChange = event([
731-
{
732-
nativeEvent: ({
733-
state,
734-
x,
735-
y
736-
}: GestureHandlerGestureEventNativeEvent & TapGestureHandlerEventExtra) =>
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)
742-
])
743-
])
744-
}
745-
]);
746-
747709
onPanStateChange = event([
748710
{
749711
nativeEvent: ({
@@ -857,13 +819,12 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
857819
if (!this.cellData.get(key)) this.setCellData(key, index);
858820
const cellData = this.cellData.get(key);
859821
if (!cellData) return null;
860-
const { style, onLayout: onCellLayout, onCellTap } = cellData;
822+
const { style, onLayout: onCellLayout } = cellData;
861823
let ref = this.cellRefs.get(key);
862824
if (!ref) {
863825
ref = React.createRef();
864826
this.cellRefs.set(key, ref);
865827
}
866-
867828
const isActiveCell = activeKey === key;
868829
return (
869830
<Animated.View onLayout={onLayout} style={style}>
@@ -873,15 +834,13 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
873834
flexDirection: horizontal ? "row" : "column"
874835
}}
875836
>
876-
<TapGestureHandler onHandlerStateChange={onCellTap}>
877-
<Animated.View
878-
ref={ref}
879-
onLayout={onCellLayout}
880-
style={isActiveCell ? { opacity: 0 } : undefined}
881-
>
882-
{children}
883-
</Animated.View>
884-
</TapGestureHandler>
837+
<Animated.View
838+
ref={ref}
839+
onLayout={onCellLayout}
840+
style={isActiveCell ? { opacity: 0 } : undefined}
841+
>
842+
{children}
843+
</Animated.View>
885844
</Animated.View>
886845
</Animated.View>
887846
);
@@ -910,60 +869,53 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
910869
: { activeOffsetY: activeOffset };
911870
}
912871
return (
913-
<TapGestureHandler
914-
ref={this.tapGestureHandlerRef}
915-
onHandlerStateChange={this.onContainerTapStateChange}
872+
<PanGestureHandler
873+
ref={this.panGestureHandlerRef}
874+
onGestureEvent={this.onPanGestureEvent}
875+
onHandlerStateChange={this.onPanStateChange}
876+
{...dynamicProps}
916877
>
917-
<Animated.View style={styles.flex}>
918-
<PanGestureHandler
919-
ref={this.panGestureHandlerRef}
920-
onGestureEvent={this.onPanGestureEvent}
921-
onHandlerStateChange={this.onPanStateChange}
922-
{...dynamicProps}
923-
>
924-
<Animated.View
925-
style={styles.flex}
926-
ref={this.containerRef}
927-
onLayout={this.onContainerLayout}
928-
>
929-
<AnimatedFlatList
930-
{...this.props}
931-
CellRendererComponent={this.CellRendererComponent}
932-
ref={this.flatlistRef}
933-
onContentSizeChange={this.onListContentSizeChange}
934-
scrollEnabled={!hoverComponent && scrollEnabled}
935-
renderItem={this.renderItem}
936-
extraData={this.state}
937-
keyExtractor={this.keyExtractor}
938-
onScroll={this.onScroll}
939-
scrollEventThrottle={1}
940-
/>
941-
{!!hoverComponent && this.renderHoverComponent()}
942-
{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-
])
878+
<Animated.View
879+
style={styles.flex}
880+
ref={this.containerRef}
881+
onLayout={this.onContainerLayout}
882+
>
883+
<AnimatedFlatList
884+
{...this.props}
885+
CellRendererComponent={this.CellRendererComponent}
886+
ref={this.flatlistRef}
887+
onContentSizeChange={this.onListContentSizeChange}
888+
scrollEnabled={!hoverComponent && scrollEnabled}
889+
renderItem={this.renderItem}
890+
extraData={this.state}
891+
keyExtractor={this.keyExtractor}
892+
onScroll={this.onScroll}
893+
scrollEventThrottle={1}
894+
/>
895+
{!!hoverComponent && this.renderHoverComponent()}
896+
{debug && this.renderDebug()}
897+
<Animated.Code>
898+
{() =>
899+
block([
900+
onChange(this.touchAbsolute, this.checkAutoscroll),
901+
cond(clockRunning(this.hoverClock), [
902+
spring(
903+
this.hoverClock,
904+
this.hoverAnimState,
905+
this.hoverAnimConfig
906+
),
907+
cond(eq(this.hoverAnimState.finished, 1), [
908+
stopClock(this.hoverClock),
909+
call(this.moveEndParams, this.onDragEnd),
910+
this.resetHoverSpring,
911+
set(this.hasMoved, 0)
960912
])
961-
}
962-
</Animated.Code>
963-
</Animated.View>
964-
</PanGestureHandler>
913+
])
914+
])
915+
}
916+
</Animated.Code>
965917
</Animated.View>
966-
</TapGestureHandler>
918+
</PanGestureHandler>
967919
);
968920
}
969921
}

0 commit comments

Comments
 (0)