这是我基于滚动动画组件的代码:
const scrollY = useRef(new Animated.Value(0));
const scrollYClamped = diffClamp(scrollY.current, 0, topBarHeight);
const translateY = scrollYClamped.interpolate({
inputRange: [0, topBarHeight],
outputRange: [0, -topBarHeight]
});
console.log('scrollY', scrollY, scrollYClamped);
useEffect(() => {
console.log('in use effect');
}, []);
const handleScroll = Animated.event(
[
{
nativeEvent: {
contentOffset: { y: scrollY.current }
}
}
],
{
useNativeDriver: true
}
);
我想要实现的事情是在scrollY
调用方法时将其重置为初始值。就像是:
const resetValue = () => { scrollY = useRef(new Animated.Value(0)); }
知道如何实现吗?
您可以setValue
在动画值上使用该方法。像下面这样的东西应该适合你:
scrollY.current.setValue(0);
您可以在此处阅读有关 setValue 的更多信息:https ://reactnative.dev/docs/animatedvalue#setvalue
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句