gpt4 book ai didi

animation - 在 React Native Animated 中使用 useNativeDriver 时出错

转载 作者:行者123 更新时间:2023-12-04 14:55:03 28 4
gpt4 key购买 nike

当我使用 useNativeDriver在 React Native 动画中

state = {
chevronUp: new Animated.Value(-50),
};
Animated.spring(this.state.chevronUp, {
toValue: 50,
friction: 5,
useNativeDriver: true, // <----- this line
}).start();
并渲染
<Animated.View style={{bottom: this.state.chevronUp,position: "absolute", right: 20, width: 50, height: 50}}>
<Icon name="chevron-up" size={28} color="#666"/>
</Animated.View>
这些错误给了我

Style property 'bottom' is not supported by native animated module



Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

最佳答案

您需要使用 "translateY"属性而不是 "bottom" native 驱动程序支持它,因此您的初始值将如下所示:

state = {
chevronUp: new Animated.Value(50),
}

Animated.spring(this.state.chevronUp, {
toValue: -50,
friction: 5,
useNativeDriver: true, // <----- this line
}).start();
并在渲染方法中:
<Animated.View style={{translateY: this.state.chevronUp,position: "absolute", right: 20, width: 50, height: 50}}>
<Icon name="chevron-up" size={28} color="#666"/>
</Animated.View>

关于animation - 在 React Native Animated 中使用 useNativeDriver 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51017852/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com