0
根據最佳實踐,組件狀態意味着不可變。然而,至少在表面上,反應本地的Animated類似乎違反了這個要求。反應本地動畫示例違反最佳做法?
我們應該在組件狀態之外設置動畫值嗎?
//from the example in https://facebook.github.io/react-native/docs/animations.html
componentDidMount() {
//look ma, you're changing a stateful value directly!
this.state.bounceValue.setValue(1.5);
//not sure how this works under the hood, but it looks to be doing the same thing
Animated.spring(this.state.bounceValue, {
toValue: 0.8,
friction: 1,
}).start()
}