ken*_*n4z 18 javascript animation react-native
使用案例
我有一张卡片列表,我正在尝试创建左/右滑块式滑动功能.我已经使用panResponder进行了滑动,但遇到了动画backgroundColor的问题
建立
constructor() {
super();
this.state = {
bgColor: new Animated.Value(0),
};
}
onPanResponderMove: (evt, gestureState) => {
Animated.timing(this.state.bgColor, {
toValue: 1,
duration: 100,
}).start();
}
render() {
const s = this.state;
const p = this.props;
const bgColor = s.bgColor.interpolate({
inputRange: [0, 1],
outputRange: [colors.gray.one, colors.primary.light]
})
return(
<View style={ [styles.wrapper, pushLeft(s.dx)] }>
<View {...this._panResponder.panHandlers} style={ styles.content } onLayout={ this.onLayout }>
{ this.props.children }
<View style={ [styles.overlay, { backgroundColor: bgColor } ]}/>
</View>
</View>
)
}
Run Code Online (Sandbox Code Playgroud)
错误
一旦我开始拖动卡片,我就会得到
"无法添加属性_tracking,对象不可扩展"
补充说明
如果我用bgColor下面的代码替换插值赋值我没有得到错误,但显然失去了颜色的动画.
const bgColor = s.bgColor._value === 0 ? colors.gray.one : colors.primary.light;
Run Code Online (Sandbox Code Playgroud)
题
关于为什么会抛出错误以及如何解决错误的想法?
小智 52
要使用Animated,您需要一个特殊的"可动画"组件(或者Animated.View,Animated.Text或者Animated.Image,内置的,或使用新的组件Animated.createAnimatedComponent()).这可能是你的问题吗?
| 归档时间: |
|
| 查看次数: |
9271 次 |
| 最近记录: |