Giter Site home page Giter Site logo

Comments (8)

alantoa avatar alantoa commented on May 24, 2024 1

Thanks for all of your feedback! I have just merged @computerjazz's PR and did a tiny improment, and i have also released a new version here!

from react-native-awesome-slider.

efstathiosntonas avatar efstathiosntonas commented on May 24, 2024

How volumeLevel is fed to useSharedValue? Is it coming from state? What happens if you hard code this value?

from react-native-awesome-slider.

wilmxre avatar wilmxre commented on May 24, 2024

yes, it is coming from a state passed from its father component. i tried hardcoding 1 or 2, but the slider stays at step 0
if i console log the progress.value i get the value of the actual volumeLevel
in #46 i just saw that if you don't specify the step prop, it works like intended, so i tried it out and it works that way

from react-native-awesome-slider.

wilmxre avatar wilmxre commented on May 24, 2024

i don't really know how the slider was implemented, but i noticed that if i pass the progress.value directly to const thumbIndex = useSharedValue(progress.value - 1); (in my case progress.value -1, because i am starting from 1 instead of 0) it works how it is supposed to

also i am using:

"react-native-reanimated": "~3.3.0",
"react-native-gesture-handler": "~2.12.0",

if this issue is related to the version of reanimated at all

from react-native-awesome-slider.

wilmxre avatar wilmxre commented on May 24, 2024

i also realized that if the progress is fed from a state, it doesn't jump to the respective step at all.
so let's say the parent component can control the value of progress from outside, the useSharedValue of the progress variable will not update the slider component at all, because it will always stay at the initial value of the state passed from the parent

from react-native-awesome-slider.

efstathiosntonas avatar efstathiosntonas commented on May 24, 2024

check useDerivedValue https://docs.swmansion.com/react-native-reanimated/docs/2.x/api/hooks/useDerivedValue/

something like this:

 const progress = useSharedValue(volumeLevel);

  const derived = useDerivedValue(() => {
    return progress
  }, [volumeLabel]);

<Slider
          step={4}
          progress={derived}

from react-native-awesome-slider.

wilmxre avatar wilmxre commented on May 24, 2024

i tried it out with:

const progress = useSharedValue(volumeLevel);

const derived = useDerivedValue(() => {
    'worklet';
    return progress.value;
  }, [volumeLevel]);
  
  <Slider
          step={4}
          progress={derived}

but the value still stays at the initially passed one.
these are my logs when the volumeLevel changes:

 DEBUG   [ANDROID] VolumeLevel:  1
 LOG   [ANDROID] Progress:  1
 INFO   [ANDROID] Derived:  1
 
 DEBUG   [ANDROID] VolumeLevel:  3
 LOG   [ANDROID] Progress:  1
 INFO   [ANDROID] Derived:  1
 
 DEBUG   [ANDROID] VolumeLevel:  4
 LOG   [ANDROID] Progress:  1
 INFO   [ANDROID] Derived:  1

from react-native-awesome-slider.

computerjazz avatar computerjazz commented on May 24, 2024

I think the issue is that thumbIndex is only updated within the gesture callback, but it is used to set the slider index.

I changed this line:

const thumbIndex = useSharedValue(0);

to:

  const thumbIndex = useSharedValue(snapToStep && step ? progress.value - 1 : 0);

and it started working as expected. Not sure if this fix is correct in every case (ie do we want to set the thumbIndex whenever progress value changes?)

from react-native-awesome-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.