Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value of the progress bar is not refreshing. #60

Open
caner219 opened this issue Feb 19, 2024 · 15 comments
Open

The value of the progress bar is not refreshing. #60

caner219 opened this issue Feb 19, 2024 · 15 comments

Comments

@caner219
Copy link

When setting the value of progress for the first time, it takes effect. However, when I retrieve data from the server and want to display it on the progress bar, the progress does not refresh. How can I solve this issue?

@caner219
Copy link
Author

1708333166028

@alantoa
Copy link
Owner

alantoa commented Feb 20, 2024

Can you please follow the example and give it a try?

export const Example = () => {
  const progress = useSharedValue(30);
  const min = useSharedValue(0);
  const max = useSharedValue(100);
  return (
    <Slider
      style={styles.container}
      progress={progress}
      minimumValue={min}
      maximumValue={max}
    />
  );
};

@caner219
Copy link
Author

I made the changes as you suggested, but the progress bar's progress is still not refreshing. The printed value of "progressValue called with = " is changing, but the progress bar itself is still not changing.
截屏2024-02-21 上午9 50 55

@alantoa
Copy link
Owner

alantoa commented Feb 21, 2024

but the progress bar's progress is still not refreshing.

Are you saying that you have already dragged the thumb, but the slider did not change at all?

@caner219
Copy link
Author

When I manually drag the progress bar, that works fine. The problem is when I get the data from the server and then go to set the progress value, the progress value changes but the progress bar UI does not refresh, it stays at the initial value it was set to.

@amalpsojancodiac
Copy link

amalpsojancodiac commented Feb 26, 2024

maybe this will help you :)

export const Example = () => {
const progress = useSharedValue(30);
 const min = useSharedValue(0);
 const max = useSharedValue(100);
  return (
    <Slider
      style={styles.container}
      progress={progress}
      minimumValue={min}
      maximumValue={max}
      cache={progress}
    />
  );
};

@caner219
Copy link
Author

caner219 commented Feb 26, 2024

Hi,I made the modifications as you instructed, but the UI of progress still has not refreshed.

@caner219
Copy link
Author

截屏2024-02-26 下午4 44 53
截屏2024-02-26 下午4 45 10

@manuelxaguilar
Copy link

@caner219 Any luck with this?

@TikshaK
Copy link

TikshaK commented May 7, 2024

I am facing the same issue.... anyone found the solution?

@alantoa
Copy link
Owner

alantoa commented May 8, 2024

@caner219, doesn't it work for you if you set the progress SharedValue? Typically, if you only want to change the progress value, you can simply do progress.value = number;.

@domalouf
Copy link

I had a similar issue when trying to use the Slider inside a modal. I couldn't get the progress spot to change based on parameters passed into the modal. I think it has something to do with useSharedValue variables updating asynchronously.

Here is a link to the documentation (the first code block under remarks is where the problem comes from I think), https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue/

@nrcaz
Copy link

nrcaz commented May 30, 2024

Having the same problem here, you can just repro the issue with a button setting the sharedValue in progress. It does not update the slider.

@glairnarra31
Copy link

Can confirm the bug occurs when snapToStep is set to true

@fform
Copy link

fform commented Oct 29, 2024

Had this same problem. In the meantime, an easy fix is to force the whole component to re-render if you are setting the progress from somewhere else. Easiest way to do that is change the key. So

const progress = useSharedValue(0);
useEffect(()=>{
   progress.value = outsideValue;
}, [outsideValue]);
...
<Slider
  key={`slider-${outsideValue}`}
  steps={stepsSV}
/>

The key can be whatever but just making a new key forces a full unmount/remount instead of the managed internal state not picking up the new outsideValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants