Skip to content

Commit fb510ec

Browse files
committed
fix: progresscontrol dep change
1 parent f19df7c commit fb510ec

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

package/src/components/ProgressControl/ProgressControl.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useState } from 'react';
1+
import React, { useMemo, useRef, useState } from 'react';
22
import { StyleSheet, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44
import Animated, {
@@ -92,28 +92,32 @@ export const ProgressControl = (props: ProgressControlProps) => {
9292
state.value = newProgress;
9393
}
9494
},
95-
[progress, isSliding.current],
95+
[progress, isSliding],
9696
);
9797

98-
const pan = Gesture.Pan()
99-
.maxPointers(1)
100-
.onStart(() => {
101-
isSliding.current = true;
102-
if (onStartDrag) {
103-
runOnJS(onStartDrag)(state.value);
104-
}
105-
})
106-
.onUpdate((event) => {
107-
const newProgress = Math.max(0, Math.min(event.x / widthInNumbers, 1));
108-
state.value = newProgress;
109-
})
110-
.onEnd(() => {
111-
isSliding.current = false;
112-
if (onEndDrag) {
113-
runOnJS(onEndDrag)(state.value);
114-
}
115-
})
116-
.withTestId(testID);
98+
const pan = useMemo(
99+
() =>
100+
Gesture.Pan()
101+
.maxPointers(1)
102+
.onStart(() => {
103+
isSliding.current = true;
104+
if (onStartDrag) {
105+
runOnJS(onStartDrag)(state.value);
106+
}
107+
})
108+
.onUpdate((event) => {
109+
const newProgress = Math.max(0, Math.min(event.x / widthInNumbers, 1));
110+
state.value = newProgress;
111+
})
112+
.onEnd(() => {
113+
isSliding.current = false;
114+
if (onEndDrag) {
115+
runOnJS(onEndDrag)(state.value);
116+
}
117+
})
118+
.withTestId(testID),
119+
[onEndDrag, onStartDrag, state, testID, widthInNumbers],
120+
);
117121

118122
const filledColor = filledColorFromProp || filledColorFromTheme;
119123

0 commit comments

Comments
 (0)