我们正在大量使用Animated和react-native-animatable,并开始注意到一些旧设备上的速度很慢。所有动画都设置了useNativeDriver,这让我们相信我们可能有一些过多的动画。
有没有办法覆盖Animated原型以完全禁用动画?我调查了一下,它看起来并不简单。
我正在考虑的另一个选择是保留我的淡入淡出动画,但将constructor中的初始值设置为最终值。这种方法肯定不会显示任何动画,但它是否也会绕过本机桥中的动画,因为值不会改变?
class Item extends Component {
constructor(props) {
super(props);
this.state = {
opacity: 1 // Notice how this is set to 1
}
}
componentDidMount() {
setTimeout(() => {
this.setState({opacity: 1})
}, 1000)
}
render() {
return (
<Animatable.View style={{opacity}} easing='ease-in' transition='opacity' duration={500} useNativeDriver={true} />
)
}
}发布于 2017-09-22 16:19:53
只需为它创建一个包装组件,并使用它而不是Animated.View
export default const AnimatedViewWrapper = (props) => {
if (/* slow device check */) {
return React.createElement(View, props)
} else {
return React.createElement(Animated.View, props)
}
}您可能需要过滤收到的道具,因为View没有Animated.View拥有的许多道具。你可以通过View.propTypes获取它们。仅当__DEV__为真时才需要执行此操作,因为propTypes在生产构建中已被剥离
https://stackoverflow.com/questions/45180420
复制相似问题