Skip to content

Commit 1214fd6

Browse files
authored
fix(activity): scrolling issue for ActivityFiltered screen (#884)
1 parent 197999c commit 1214fd6

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

src/components/DetectSwipe.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import React, { memo, ReactElement, useRef } from 'react';
2-
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
1+
import React, { memo, MutableRefObject, ReactElement, useRef } from 'react';
2+
import {
3+
GestureDetector,
4+
Gesture,
5+
GestureType,
6+
} from 'react-native-gesture-handler';
37

48
export interface IDetectSwipe {
9+
panGestureRef?: MutableRefObject<GestureType>;
510
onSwipeLeft?: () => void;
611
onSwipeRight?: () => void;
712
onSwipeUp?: () => void;
@@ -14,6 +19,7 @@ export interface IDetectSwipe {
1419
}
1520

1621
const DetectSwipe = ({
22+
panGestureRef,
1723
onSwipeLeft,
1824
onSwipeRight,
1925
onSwipeUp,
@@ -24,41 +30,41 @@ const DetectSwipe = ({
2430
swipeDownSensitivity = 600,
2531
children,
2632
}: IDetectSwipe): ReactElement => {
27-
const acticated = useRef(false);
33+
const activated = useRef(false);
2834

29-
const gesture = Gesture.Pan()
35+
let gesture = Gesture.Pan()
3036
.runOnJS(true)
3137
.minDistance(10)
3238
.onUpdate((event) => {
33-
if (acticated.current) {
39+
if (activated.current) {
3440
return;
3541
}
3642

3743
if (onSwipeLeft && event.velocityX <= -swipeLeftSensitivity) {
38-
//Swiping left
3944
onSwipeLeft();
40-
acticated.current = true;
45+
activated.current = true;
4146
}
4247
if (onSwipeRight && event.velocityX >= swipeRightSensitivity) {
43-
//Swiping right.
4448
onSwipeRight();
45-
acticated.current = true;
49+
activated.current = true;
4650
}
4751
if (onSwipeUp && event.velocityY <= -swipeUpSensitivity) {
48-
//Swiping up
4952
onSwipeUp();
50-
acticated.current = true;
53+
activated.current = true;
5154
}
5255
if (onSwipeDown && event.velocityY >= swipeDownSensitivity) {
53-
//Swiping down.
5456
onSwipeDown();
55-
acticated.current = true;
57+
activated.current = true;
5658
}
5759
})
5860
.onFinalize(() => {
59-
acticated.current = false;
61+
activated.current = false;
6062
});
6163

64+
if (panGestureRef) {
65+
gesture = gesture.withRef(panGestureRef);
66+
}
67+
6268
return <GestureDetector gesture={gesture}>{children}</GestureDetector>;
6369
};
6470

src/screens/Activity/ActivityFiltered.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { ReactElement, memo, useMemo, useState } from 'react';
1+
import React, { ReactElement, memo, useMemo, useState, useRef } from 'react';
22
import { useSafeAreaInsets } from 'react-native-safe-area-context';
3+
import { Gesture, GestureType } from 'react-native-gesture-handler';
34
import {
45
StyleSheet,
56
TouchableOpacity,
@@ -56,6 +57,7 @@ const ActivityFiltered = ({
5657
navigation,
5758
}: WalletScreenProps<'ActivityFiltered'>): ReactElement => {
5859
const insets = useSafeAreaInsets();
60+
const panGestureRef = useRef<GestureType>(Gesture.Pan());
5961
const [radiusContainerHeight, setRadiusContainerHeight] = useState(0);
6062
const [currentTab, setCurrentTab] = useState(0);
6163
const [search, setSearch] = useState('');
@@ -135,10 +137,16 @@ const ActivityFiltered = ({
135137
</BlurView>
136138
</View>
137139

138-
<DetectSwipe onSwipeLeft={onSwipeLeft} onSwipeRight={onSwipeRight}>
140+
<DetectSwipe
141+
panGestureRef={panGestureRef}
142+
swipeLeftSensitivity={1500}
143+
swipeRightSensitivity={1500}
144+
onSwipeLeft={onSwipeLeft}
145+
onSwipeRight={onSwipeRight}>
139146
<View style={styles.txListContainer}>
140147
<ActivityList
141148
style={styles.txList}
149+
panGestureRef={panGestureRef}
142150
showTitle={false}
143151
contentContainerStyle={activityPadding}
144152
progressViewOffset={radiusContainerHeight + 10}

src/screens/Activity/ActivityList.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import React, {
44
useCallback,
55
useState,
66
useMemo,
7+
MutableRefObject,
78
} from 'react';
89
import {
9-
FlatList,
1010
NativeScrollEvent,
1111
NativeSyntheticEvent,
1212
StyleProp,
@@ -15,6 +15,7 @@ import {
1515
} from 'react-native';
1616
import { useSelector } from 'react-redux';
1717
import { useNavigation } from '@react-navigation/native';
18+
import { FlatList, GestureType } from 'react-native-gesture-handler';
1819

1920
import { RefreshControl } from '../../styles/components';
2021
import { Caption13Up, Subtitle, Text01S } from '../../styles/text';
@@ -34,19 +35,21 @@ const ListHeaderComponent = memo(
3435
);
3536

3637
const ActivityList = ({
37-
onScroll,
3838
style,
39+
panGestureRef,
3940
contentContainerStyle,
4041
progressViewOffset,
4142
showTitle = true,
4243
filter = {},
44+
onScroll,
4345
}: {
44-
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
4546
style?: StyleProp<ViewStyle>;
47+
panGestureRef?: MutableRefObject<GestureType>;
4648
contentContainerStyle?: StyleProp<ViewStyle>;
4749
progressViewOffset?: number;
4850
showTitle?: boolean;
4951
filter?: {};
52+
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
5053
}): ReactElement => {
5154
const navigation = useNavigation<RootNavigationProp>();
5255
const items = useSelector(activityItemsSelector);
@@ -91,13 +94,17 @@ const ActivityList = ({
9194
setRefreshing(false);
9295
};
9396

97+
const simultaneousHandlers = panGestureRef ? [panGestureRef] : [];
98+
9499
return (
95100
<FlatList
96-
onScroll={onScroll}
97101
style={[styles.content, style]}
102+
simultaneousHandlers={simultaneousHandlers}
98103
contentContainerStyle={contentContainerStyle}
104+
showsVerticalScrollIndicator={false}
99105
data={groupedItems}
100106
renderItem={renderItem}
107+
onScroll={onScroll}
101108
keyExtractor={(item): string => {
102109
return typeof item === 'string' ? item : item.id;
103110
}}

0 commit comments

Comments
 (0)