alantoa / react-native-awesome-slider

🚀 An anwesome <Slider/> that supports various features haptic, lottie, animation, ballon, etc.
MIT License
228 stars 28 forks source link

How to update current value? #57

Closed alexey-yarmosh closed 4 months ago

alexey-yarmosh commented 4 months ago

Probably I am missing something, but how to update current value from the outside? (e.g. if value comes from props). Updating progress.value doesn't have any effect.

import { useSharedValue } from 'react-native-reanimated';
import { Slider } from 'react-native-awesome-slider';

export const Slider = ({
  value,
  onChange,
}: {
  value: number;
  onChange: Function;
}) => {
  const theme = useTheme();
  const progress = useSharedValue(value);
  const min = useSharedValue(0);
  const max = useSharedValue(10);

  useEffect(() => {
    progress.value = value;
  }, [value]);

  return (
    <Slider
      style={styles.container}
      progress={progress}
      minimumValue={min}
      maximumValue={max}
    />
  );
};
alantoa commented 4 months ago

hey @alexey-yarmosh, you can check this.