Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: thumb not working when set disableTrackFollow #27

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/slide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
thumbWidth = 15,
}) {
const bubbleRef = useRef<BubbleRef>(null);

const isScrubbingInner = useSharedValue(false);
const prevX = useSharedValue(0);

const [sliderWidth, setSliderWidth] = useState(0);
Expand Down Expand Up @@ -295,7 +297,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
translateX = stepTimingOptions
? withTiming(markLeftArr.value[thumbIndex.value], stepTimingOptions)
: markLeftArr.value[thumbIndex.value];
} else if (disableTrackFollow) {
} else if (disableTrackFollow && isScrubbingInner.value) {
translateX = clamp(
thumbValue.value,
0,
Expand Down Expand Up @@ -447,6 +449,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
const onActiveSlider = useCallback(
(x: number) => {
'worklet';
isScrubbingInner.value = true;
if (isScrubbing) {
isScrubbing.value = true;
}
Expand Down Expand Up @@ -506,6 +509,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
disableTrackFollow,
hapticMode,
isScrubbing,
isScrubbingInner,
isTriggedHaptic,
markLeftArr.value,
onHapticFeedback,
Expand All @@ -530,6 +534,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
if (disable) {
return;
}
isScrubbingInner.value = true;
if (isScrubbing) {
isScrubbing.value = true;
}
Expand Down Expand Up @@ -561,8 +566,9 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
if (disable) {
return;
}
isScrubbingInner.value = false;
if (isScrubbing) {
isScrubbing.value = true;
isScrubbing.value = false;
}
if (panDirectionValue) {
panDirectionValue.value = PanDirectionEnum.END;
Expand All @@ -581,6 +587,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
disable,
disableTrackFollow,
isScrubbing,
isScrubbingInner,
onActiveSlider,
onSlidingComplete,
onSlidingStart,
Expand All @@ -606,6 +613,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
if (isFinished) {
onActiveSlider(x);
}
isScrubbingInner.value = true;
if (isScrubbing) {
isScrubbing.value = true;
}
Expand All @@ -619,6 +627,7 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
disable,
disableTapEvent,
isScrubbing,
isScrubbingInner,
onActiveSlider,
onSlidingComplete,
onTap,
Expand Down Expand Up @@ -655,9 +664,10 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
// setting thumbIndex
useAnimatedReaction(
() => {
if (isScrubbing && isScrubbing.value) {
if (isScrubbingInner.value) {
return undefined;
}

if (!step) {
return undefined;
}
Expand All @@ -682,7 +692,27 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
},
[isScrubbing, maximumValue, minimumValue, step, progress, width],
);

// setting thumbValue
useAnimatedReaction(
() => {
if (isScrubbingInner.value) {
return undefined;
}
if (step) {
return undefined;
}
const currentValue =
(progress.value / (minimumValue.value + maximumValue.value)) *
(width.value - (disableTrackFollow ? thumbWidth : 0));
return clamp(currentValue, 0, width.value - thumbWidth);
},
data => {
if (data !== undefined) {
thumbValue.value = data;
}
},
[thumbWidth, maximumValue, minimumValue, step, progress, width],
);
const onLayout = ({ nativeEvent }: LayoutChangeEvent) => {
const layoutWidth = nativeEvent.layout.width;
width.value = layoutWidth;
Expand Down