Skip to content

Commit 538b3df

Browse files
committed
fix: scrolling activation behaviour
1 parent 14d9c6d commit 538b3df

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/react-native-sdk/src/components/MarkdownReactiveScrollView.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactNode } from 'react';
1+
import { type ReactNode, useRef } from 'react';
22
import Animated, {
33
clamp,
44
scrollTo,
@@ -17,9 +17,28 @@ export const MarkdownReactiveScrollView = ({
1717
const contentWidth = useSharedValue(0);
1818
const visibleContentWidth = useSharedValue(0);
1919
const offsetBeforeScroll = useSharedValue(0);
20+
const touchStart = useSharedValue<{ x: number; y: number } | null>(null);
2021

2122
const panGesture = Gesture.Pan()
22-
.activeOffsetX([-5, 5])
23+
.onBegin((event) => {
24+
touchStart.value = { x: event.x, y: event.y };
25+
})
26+
.onTouchesMove((event, state) => {
27+
if (!touchStart.value || !event.changedTouches.length) {
28+
state.fail();
29+
return;
30+
}
31+
32+
const xDiff = Math.abs(event.changedTouches[0]!.x - touchStart.value.x);
33+
const yDiff = Math.abs(event.changedTouches[0]!.y - touchStart.value.y);
34+
const isHorizontalPanning = xDiff > yDiff;
35+
36+
if (isHorizontalPanning) {
37+
state.activate();
38+
} else {
39+
state.fail();
40+
}
41+
})
2342
.onUpdate((event) => {
2443
const { translationX } = event;
2544

0 commit comments

Comments
 (0)