Comments (10)
Very preliminary way to wrap Slider to enable this:
const renderSlider = (optionsArray, initialValue, onSlidingComplete) => (
<Slider
minimumValue={0}
maximumValue={optionsArray.length - 1}
step={1}
value={optionsArray.indexOf(initialValue)}
onSlidingComplete={(value) => onSlidingComplete(optionsArray[value])}
/>
);
from react-native-slider.
Until this is formally supported, here's a workaround that worked well for my use case:
Slider component...
<Slider
style={{width: '100%', height: 40}}
step={0}
minimumValue={5}
maximumValue={60}
onValueChange={(value) => {this.sliderValueChange(value)}}
/>
And the sliderValueChange function...
sliderValueChange = (value) => {
// Array of desired values
const array = [5, 10, 15, 30, 45, 60]
const output = array.reduce((prev, curr) => Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev)
console.log(output)
// ... Pass output to UI, state, whatever
}
from react-native-slider.
Hey @hery! Indeed it sounds interesting, please send a PR, and I'll be glad to ship it :)
from react-native-slider.
Good to hear thanks! iOS is ready but I'm a bit slower with Android. Quick question, should I remove androidx
from my implementation?
from react-native-slider.
Hi @hery ,
I was looking for a slider component exactly like you mentioned.
Here is a use case.
I am trying to make a small utility for ER doctors to determine very quickly the amount of a medicine which stops heavy bleedings.
And there is a slider i need there which has the values like 2.0 - 2.1 - 2.3 - 2.8 - 3.1 - 3.3 - 3.7 and so, without a contstant amount of increments.
When do you think this feature will be implemented?
Thank you very much.
from react-native-slider.
Hi @orkunsenturk, it's ready on iOS but I'm still figuring out a few things on Android.
The logic is a bit different on Android so my implementation is a little buggy, but I'll try to fix it soon.
from react-native-slider.
Is anyone working on this? I would like to collaborate.
from react-native-slider.
@a-c-sreedhar-reddy please do!
from react-native-slider.
Hi guys! Where is the code of android which takes care of steps when dragging so that UI does not change until you reach a step?
from react-native-slider.
I'm posting here some examples and thoughts of @gkupsaw given in the duplicate issue:
I'm not sure if this is already exists, but it would be nice to have the option to use discrete values for the slider instead of continuous options.
It would probably be easiest to emulate the code of existing discrete slider implementations on the web. I haven't thought too deeply about the implementation yet, but would gladly look into it if it's something to be added.Related Issues
An example of this kind of slider: https://material-ui.com/components/slider/#discrete-sliders
(Unmanaged) implementation in RN: https://www.npmjs.com/package/react-native-snap-slider
from react-native-slider.
Related Issues (20)
- How to use Tap in Android? HOT 2
- useState callback do not execute inside onSlidingComplete using tap. HOT 1
- Custom thumb image in Android becomes huge in contrary of iOS which is the the requested size HOT 2
- Clarification on `onValueChange` Behavior Across Platforms HOT 2
- lowerLimit for web HOT 1
- Wrong in Task :react-native-community_slider:compileReleaseJavaWithJavac FAILED
- Issue with Thumb Positioning in Web Implementation
- onValueChange triggers an extra time after onSlidingCompleted on Android HOT 2
- Android: StackOverflow when `lowerLimit` is greater than `upperLimit` (and, on some devices, when the slider first loads) HOT 3
- Customize Thumb component HOT 1
- update the targetSdk version
- StepMarker is not a prop at least on index.d.ts how to add a custom step marker? HOT 3
- trackStyle HOT 1
- trackStyle and thumbStyle HOT 2
- Callback for component `RNCSlider` HOT 4
- It doesn't work in portrait mode on maps component
- Android build failure - C++ errors, buildCMakeDebug HOT 5
- Unable to resolve module react-native/Libraries/NativeComponent/ViewConfigIgnore HOT 3
- how can i adjust the thickness of the slider HOT 1
- Secondary Progress / Buffered time HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-slider.