I want to move the label with respect to slider thumb just like this one:
Right now my slider is like this:
I want to display the label shown as 30 km with respect to the slider thumb such that as the slider moves, the label should move accordingly.
I am using Native React Slider component.
this is my code:
<Slider
style={styles.slider}
thumbTintColor='rgb(252, 228, 149)'
step={1}
maximumValue={5}
thumbTintColor='rgb(252, 228, 149)'
maximumTrackTintColor='#494A48'
minimumTrackTintColor='rgb(252, 228, 149)' />
Solution to your problem:
Styles:
Output:
Working Snippet: https://snack.expo.io/Syrt3Bs7z
Built in
<Slider />
doesn't provide those flexibility to customize what you want.This should works, react-native-slider, which is a drop-in replacement of official
<Slider />
.What you need is very similar to it's demo style #4.
For your Slider Label of value, you can modify its function _renderThumbImage() to replace default
<Image />
.I think react-native-multi-slider will solve your problem . You can change the slider thumb by sending your custom designed component to the
customMarker
prop that is available. Then you can wrap theMultislider
in another component, maintain the state(for slider position value) there and send value as prop to your custom designed marker everytime the thumb position changes which can be detected usingonValuesChange
prop.This link might also help you.
You can adjust left of the text to the value of the slider.
measure the size and position of the slider View
2.Now in "onValueChange" callback of slider.
Show the slider Value txt on Calculated positions.
.............. that will do the job, but You might have to tweak it little bit.