mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 10:23:24 +00:00
fix slider resetting while sliding
This commit is contained in:
@@ -54,10 +54,13 @@ const VideoSlider = ({ onSlidingComplete }: VideoSliderProps) => {
|
||||
};
|
||||
const valueX = valueToX(value);
|
||||
const translateX = useSharedValue(valueToX(value));
|
||||
const isDragging = useSharedValue(false);
|
||||
|
||||
useEffect(() => {
|
||||
translateX.value = clamp(valueX, 0, width - knobSize_);
|
||||
}, [valueX]);
|
||||
if (!isDragging.value) {
|
||||
translateX.value = clamp(valueX, 0, width - knobSize_);
|
||||
}
|
||||
}, [valueX, isDragging.value]);
|
||||
|
||||
const _onSlidingComplete = (xValue: number) => {
|
||||
"worklet";
|
||||
@@ -66,16 +69,26 @@ const VideoSlider = ({ onSlidingComplete }: VideoSliderProps) => {
|
||||
|
||||
const _onActive = (value: number) => {
|
||||
"worklet";
|
||||
isDragging.value = true;
|
||||
translateX.value = clamp(value, 0, width - knobSize_);
|
||||
runOnJS(setIsIdle)(false);
|
||||
};
|
||||
|
||||
const _onEnd = () => {
|
||||
"worklet";
|
||||
isDragging.value = false;
|
||||
_onSlidingComplete(translateX.value);
|
||||
};
|
||||
|
||||
const onGestureEvent = useAnimatedGestureHandler<
|
||||
PanGestureHandlerGestureEvent,
|
||||
{ offsetX: number }
|
||||
>({
|
||||
onStart: (_, ctx) => (ctx.offsetX = translateX.value),
|
||||
onActive: (event, ctx) => _onActive(event.translationX + ctx.offsetX),
|
||||
onEnd: _onEnd,
|
||||
onCancel: _onEnd,
|
||||
onFinish: _onEnd,
|
||||
});
|
||||
|
||||
const onTapEvent = (
|
||||
|
Reference in New Issue
Block a user