0

这是可行的吗?例如,检查此链接

我一直在努力让它发挥作用。这是我当前的代码:

constructor(props) {
    super(props);
    this.state = {
      animationValue: new Animated.Value(0)
    };
  }

<Animated.View 
  style={{ flex: 0.15, backgroundColor: `rgba(0,0,0,${background}` }} 
  onPress={this.removeBackground}
>
    <Text style={[{ textAlign: 'right' }>{hometeam.result} - {awayteam.result}</Text>
</Animated.View>

background是一个看起来像这样的变量:

const background = this.state.animationValue.interpolate({
  inputRange: [0, 1],
  outputRange: [0, 1] 
});

我想要发生的是当您单击动画视图时,我希望背景颜色褪色。所以我试图使用 rgba 并根据背景变量更改 alpha,这给了我一个错误。

这是我删除背景的功能:

removeBackground = () => {
  this.state.animationValue.setValue(0);
  Animated.timing(this.state.animationValue, {
    toValue: 1, 
    duration: 2000,
  }).start();
}

任何线索我怎么能做到这一点?

4

0 回答 0