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

Fix bug with double thumb background color #414

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

sfreeman28
Copy link
Contributor

#396

Fixes a bug when using double thumb slider and updating the slider value from an external input (eg TextField).
The background color of the slider is not updating correctly, this PR fixes that issue.

Here is the patch-package patch file for those interested

diff --git a/node_modules/@miblanchard/react-native-slider/lib/index.js b/node_modules/@miblanchard/react-native-slider/lib/index.js
index 379639a..ff6cf06 100644
--- a/node_modules/@miblanchard/react-native-slider/lib/index.js
+++ b/node_modules/@miblanchard/react-native-slider/lib/index.js
@@ -442,6 +442,7 @@ export class Slider extends PureComponent {
         const minTrackWidth = _startFromZero
             ? Math.abs(_value) * sliderWidthCoefficient - thumbSize.width / 2
             : interpolatedTrackValues[0];
+        const maxTrackWidth = interpolatedTrackValues[1];
         const clearBorderRadius = {};
         if (_startFromZero && _value < 0 + step) {
             clearBorderRadius.borderBottomRightRadius = 0;
@@ -455,10 +456,10 @@ export class Slider extends PureComponent {
             position: 'absolute',
             left: interpolatedTrackValues.length === 1
                 ? new Animated.Value(startPositionOnTrack)
-                : Animated.add(minThumbValue, thumbSize.width / 2),
+                : Animated.add(minTrackWidth, thumbSize.width / 2),
             width: interpolatedTrackValues.length === 1
                 ? Animated.add(minTrackWidth, thumbSize.width / 2)
-                : Animated.add(Animated.multiply(minThumbValue, -1), maxThumbValue),
+                : Animated.add(Animated.multiply(minTrackWidth, -1), maxTrackWidth),
             backgroundColor: minimumTrackTintColor,
             ...valueVisibleStyle,
             ...clearBorderRadius,

@miblanchard miblanchard merged commit 516c820 into miblanchard:main Sep 6, 2023
Neiso pushed a commit to Neiso/react-native-slider that referenced this pull request Oct 4, 2023
…me time, set the current thumb to the closest of the touch event
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

Successfully merging this pull request may close these issues.

2 participants