我有大约<AnimatedButton />
个
我想动画它从isFullWidth
%宽度到40%宽度取决于一个称为isFullWidth
的布尔型props .
我有:
class AnimatedButton extends Component {
constructor(props) {
super(props);
this.state = { width: new Animated.Value(100) };
}
toggleWidth() {
const endWidth = this.props.isFullWidth ? 40 : 100;
Animated.timing(this.state.width, {
toValue: endWidth,
duration: 200,
easing: Easing.linear,
}).start();
}
render() {
<TouchableOpacity
style={{ width: `${this.state.width}%` }}
onPress={this.props.onPress}
>
// more stuff
</TouchableOpacity>
}
}
问题是,它只是跳转到适当的百分比,而没有设置动画.我试着将宽度设置为this.state.animatedValue
,而不是使用百分比,只使用像素,例如150到400以及后面的像素,它可以像预期的那样正常工作.
同样的问题也适用于rgba(220, 100, 50, 0.8)
?