Giter Club home page Giter Club logo

Comments (10)

cltsang avatar cltsang commented on May 27, 2024 4

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.

nsdub avatar nsdub commented on May 27, 2024 3

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.

michalchudziak avatar michalchudziak commented on May 27, 2024

Hey @hery! Indeed it sounds interesting, please send a PR, and I'll be glad to ship it :)

from react-native-slider.

hery avatar hery commented on May 27, 2024

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.

orkunsenturk avatar orkunsenturk commented on May 27, 2024

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.

hery avatar hery commented on May 27, 2024

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.

a-c-sreedhar-reddy avatar a-c-sreedhar-reddy commented on May 27, 2024

Is anyone working on this? I would like to collaborate.

from react-native-slider.

thymikee avatar thymikee commented on May 27, 2024

@a-c-sreedhar-reddy please do!

from react-native-slider.

a-c-sreedhar-reddy avatar a-c-sreedhar-reddy commented on May 27, 2024

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.

BartoszKlonowski avatar BartoszKlonowski commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.