githuboftigran / rn-range-slider

A native slider with range
MIT License
237 stars 133 forks source link

There is a way to format the textFormat? #31

Closed alecpo closed 4 years ago

alecpo commented 4 years ago

For exemple the value is 500000 and I wanna show "500 thousand" in the label. (value / 1000).

What I mean is: I need a way to get the number of the thumb that I'm currently changing and use this as a parameter inside the textFormat prop.

So I would be able to show a formatted number and a dynamic complementary string around this number.

githuboftigran commented 4 years ago

@alecpo , you can't define an executable code on JS side and execute it on native side, textFormat is just a simple text formatter which is passed to String.format on Android side and NSString stringWithFormat. But you can set min and max to your minValue / 1000 and maxValue / 1000 and step to step / 1000 and in onValueChanged multiply values by 1000 again.

alecpo commented 4 years ago

@githuboftigran this solve part of my problem but this doesn't allow me to show "thousand" or "million" in the textFormat depending of the scale of my min or maxValue. =/

githuboftigran commented 4 years ago

@alecpo, you can set textFormat to %d million or %d thousand depending on values. BTW I'd recommend K and M instead of thousand or million. That's a better UI :)

alecpo commented 4 years ago

@githuboftigran But this is the point, how can I get the value to set texFormat depending of something?

should be something like:

textFormat={value => value > 1000000 ? '%d M' : '%d K'}

but I get the error JSON value '1' of type NSNumber cannot be converted to NSString

githuboftigran commented 4 years ago

@alecpo , no, textFormat prop must be string. textFormat={this.state.currentValue >= 1000000 ? '%d M' : '%d K'}

alecpo commented 4 years ago

@alecpo , no, textFormat prop must be string. textFormat={this.state.currentValue > 1000000 ? '%d M' : '%d K'}

I think this will not work because I'm using two thumbs for min and max value. If I was using just one thumb this probably would work.

githuboftigran commented 4 years ago

That's right. In fact I believe it's a better UI/UX to have both values in the same format. Anyway I'm closing this issue, because this is not a bug or an issue.