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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical sliders don't work unless trackClickable is true #455

Open
elliottkember opened this issue Nov 7, 2024 · 0 comments
Open

Vertical sliders don't work unless trackClickable is true #455

elliottkember opened this issue Nov 7, 2024 · 0 comments

Comments

@elliottkember
Copy link
Contributor

elliottkember commented Nov 7, 2024

I just set trackClickable to false on my vertical slider, and suddenly I can't scrub it downwards. Upwards works okay, but scrubbing downwards is broken.

I've tracked this down to the _getThumbLeft function, which uses vertical to discern between container width and height. However, my container seems to have a "width" of its visible height – not of its visible width. So the "width" is the draggable axis of the slider?

So the X and Y values are already flipped, but the function seems to be calculating incorrectly.

When the track is clickable, this resolves itself because clicking the track automatically jumps to the right position. But without that prop, the handle isn't scrubbable in a vertical context.

Anyway, this seems to fix it:

diff --git src/index.tsx src/index.tsx
index d288b65..3f5a8b1 100644
--- src/index.tsx
+++ src/index.tsx
@@ -392,16 +392,11 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
     };
     _getThumbLeft = (value: number) => {
         const {containerSize, thumbSize} = this.state;
-        const {vertical} = this.props;
 
         const standardRatio = this._getRatio(value);
 
         const ratio = I18nManager.isRTL ? 1 - standardRatio : standardRatio;
-        return (
-            ratio *
-            ((vertical ? containerSize.height : containerSize.width) -
-                thumbSize.width)
-        );
+        return ratio * (containerSize.width - thumbSize.width);
     };
     _getValue = (gestureState: {dx: number; dy: number}) => {
         const {containerSize, thumbSize, values} = this.state;

Snack: https://snack.expo.dev/@elliottkember/cf066c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant