|
1 | | -import React, { useRef, useState } from 'react'; |
| 1 | +import React, { useMemo, useRef, useState } from 'react'; |
2 | 2 | import { StyleSheet, View } from 'react-native'; |
3 | 3 | import { Gesture, GestureDetector } from 'react-native-gesture-handler'; |
4 | 4 | import Animated, { |
@@ -92,28 +92,32 @@ export const ProgressControl = (props: ProgressControlProps) => { |
92 | 92 | state.value = newProgress; |
93 | 93 | } |
94 | 94 | }, |
95 | | - [progress, isSliding.current], |
| 95 | + [progress, isSliding], |
96 | 96 | ); |
97 | 97 |
|
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 | + ); |
117 | 121 |
|
118 | 122 | const filledColor = filledColorFromProp || filledColorFromTheme; |
119 | 123 |
|
|
0 commit comments