I have a component that is moved up on scrolling.
const [topBarHeight, setTopBarHeight] = useState(0);
const scrollY = useRef(new Animated.Value(0));
const scrollYClamped = diffClamp(scrollY.current, 0, topBarHeight);
const translateY = scrollYClamped.interpolate({
inputRange: [0, topBarHeight],
outputRange: [0, -topBarHeight]
});
const resetToInitialPosition = () => {
scrollY.current.setValue(0);
};
const handleScroll = Animated.event(
[
{
nativeEvent: {
contentOffset: { y: scrollY.current }
}
}
],
{
useNativeDriver: true
}
);
I have a problem with resetToInitialPosition. It works fine and sets animated value back to initial, however scrollYClamped and translateY are not being reset and the component goes all the way up immediately after any interaction with the scroll view. Any idea how to set those two variables back to initial values as well?