Closed JonnyBoy333 closed 4 years ago
Just adding a little color to this issue. I also tried converting my component to a class based component with a state and did not experience this issue. So it appears to happen only when I call update state hook functions.
To prove this out I've made a runnable snack with the class and function components you can switch between to see one functioning correctly and the other having problems. https://snack.expo.io/@jonnyboy333/slider-panel-issue
The problem with the hook version is the animated values are redefined every time state change and the component re-render. It might cause the panel calculates its position wrongly.
Move them into state should resolve the problem.
- const animatedValue1 = new Animated.Value(0);
- const animatedValue2 = new Animated.Value(0);
+ const [animatedValue1] = useState(new Animated.Value(0));
+ const [animatedValue2] = useState(new Animated.Value(0));
With the class version, you also moved the animation values outside of render()
so it didn't cause the issue.
I would also recommend using useRef to capture component's ref. Example:
const firstPanel = useRef(null);
<Panel ref={firstPanel} />
<TouchableOpacity onPress={() => firstPanel.current.show()} />
Well there you go, still getting used to hooks I guess. That fixes the issue, and thanks for the tip on using the useRef hook.
Issue Description
I'm having an issue where I have two sliders on the same screen. I have added the
animatedValue
per #132 which allows me to have two sliders running simultaneously. The issue occurs when I have a button inside the sliding panel that changes a state using theuseState
hook. This seems to only occur when the hook is involved, if the button simply alerts something or logs something there is no problem, but if I add a hook in there, there is a problem. After I click a button with a hook and click off the slider instead of animating downward it disappears immediately and everything on screen becomes unresponsive, almost as if the backdrop is still there but invisible.Steps to Reproduce / Code Snippets / Screenshots
Environment