alantoa / react-native-awesome-slider

🚀 An anwesome <Slider/> that supports various features haptic, lottie, animation, ballon, etc.
MIT License
228 stars 28 forks source link

Thumb is not synced with slider #70

Closed SorooshDeveloper closed 1 month ago

SorooshDeveloper commented 1 month ago

Hello when i use custom renderThumb, thumb will get an offset from the slider as the image below shows when progress is 100 thumb should be exactly on the last step but it has a margin! Screenshot 2024-04-30 at 11 57 57 PM

this my render thumb :

         renderThumb={() => (
                <View
                  style={{
                    height: 10,
                    width: 10,
                    backgroundColor: theme.background,
                    borderWidth: 1,
                    borderColor:
                      orderSide === 'buy' ? theme.marketGreen : theme.marketRed,
                    transform: [{rotate: '45deg'}],
                  }}
                />
              )}
SorooshDeveloper commented 1 month ago

A simple workaround is to manually add a margin


const SliderThumb = ({orderSide, progress}) => {
  const {theme} = useTheme();
  const backColor = orderSide === 'buy' ? theme.marketGreen : theme.marketRed;

  const animatedStyle = useAnimatedStyle(() => {
    return {
      marginLeft: interpolate(progress.value, [0, 100], [0, 8]),
    };
  });
  return (
    <Animated.View
      style={[
        animatedStyle,
        {
          height: 10,
          width: 10,
          backgroundColor: theme.background,
          borderWidth: 1,
          borderColor: backColor,
          transform: [{rotate: '45deg'}],
          zIndex: 99999,
        },
      ]}
    />
  );
};
alantoa commented 1 month ago

@SorooshDeveloper hey, what if you added the thumbWidth prop to the Slider?

SorooshDeveloper commented 1 month ago

@alantoa i needed to set both mark width and thumbwidth to fix the issue!

SorooshDeveloper commented 1 month ago

@alantoa this is fixed i will close this issue, thanks for the help.