Skip to content

Commit efee5a4

Browse files
committed
fix: gesture firing on tap & example
1 parent 9789706 commit efee5a4

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

example/app/index.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "@codeherence/react-native-graph";
77
import { LinearGradient, vec } from "@shopify/react-native-skia";
88
import { useCallback, useMemo, useReducer } from "react";
9-
import { Button, StyleSheet, Text, View, useWindowDimensions } from "react-native";
9+
import { Button, ScrollView, StyleSheet, Text, View } from "react-native";
1010
import { useAnimatedProps, useSharedValue } from "react-native-reanimated";
1111
import { useSafeAreaInsets } from "react-native-safe-area-context";
1212

@@ -44,13 +44,14 @@ const priceMap = {
4444
export default () => {
4545
const [counter, increment] = useReducer((s: number) => s + 1, 0);
4646

47-
const { width } = useWindowDimensions();
48-
const { top, bottom } = useSafeAreaInsets();
49-
50-
const symbol: "msft" | "aapl" = counter % 2 === 0 ? "msft" : "aapl";
51-
const data: [number, number][] = useMemo(() => priceMap[symbol], [symbol]);
47+
const { top, bottom, left, right } = useSafeAreaInsets();
5248

5349
const latestPrice = useSharedValue("0");
50+
const symbol: "msft" | "aapl" = counter % 2 === 0 ? "msft" : "aapl";
51+
const data: [number, number][] = useMemo(() => {
52+
latestPrice.value = uiFormatter(priceMap[symbol][priceMap[symbol].length - 1]![1]);
53+
return priceMap[symbol];
54+
}, [symbol]);
5455

5556
const onHoverChangeWorklet = useCallback((evt: HoverGestureHandlerOnChangeEventPayload) => {
5657
"worklet";
@@ -72,12 +73,21 @@ export default () => {
7273
}, []);
7374

7475
return (
75-
<View style={[styles.container, { paddingTop: top, paddingBottom: bottom }]}>
76+
<ScrollView
77+
style={styles.container}
78+
contentContainerStyle={{
79+
paddingTop: top,
80+
paddingBottom: bottom,
81+
paddingLeft: left,
82+
paddingRight: right,
83+
}}
84+
showsVerticalScrollIndicator={false}
85+
>
7686
<Button title={`Showing ${symbol}. Click to switch.`} onPress={increment} />
7787
<AnimatedText style={styles.price} animatedProps={animatedProps} />
7888
<LineChart
7989
points={data}
80-
style={[styles.chart, { width }]}
90+
style={styles.chart}
8191
TopAxisLabel={AxisLabel}
8292
BottomAxisLabel={AxisLabel}
8393
onPanGestureChange={onGestureChangeWorklet}
@@ -93,12 +103,12 @@ export default () => {
93103
/>
94104
)}
95105
/>
96-
</View>
106+
</ScrollView>
97107
);
98108
};
99109

100110
const styles = StyleSheet.create({
101111
container: { flex: 1 },
102-
chart: { flex: 1, maxHeight: 400 },
112+
chart: { flex: 1, minHeight: 400 },
103113
price: { fontSize: 32 },
104114
});

src/components/LineChart/useGestures.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export const useGestures = ({
7777
onHoverGestureEnd,
7878
}: UseGestureProps) => {
7979
const panGesture = Gesture.Pan()
80-
.onBegin((event) => {
80+
.activeOffsetX([-5, 5])
81+
.onStart((event) => {
8182
x.value = event.x;
8283
y.value = getYForX({ path, x: event.x });
8384
const point = interpolate(
@@ -103,7 +104,7 @@ export const useGestures = ({
103104
});
104105

105106
const hoverGesture = Gesture.Hover()
106-
.onBegin((event) => {
107+
.onStart((event) => {
107108
x.value = event.x;
108109
y.value = getYForX({ path, x: event.x });
109110
const point = interpolate(

0 commit comments

Comments
 (0)