使用set()设置不透明度的简单情况不起作用

时间:2020-03-10 12:57:14

标签: react-native react-native-reanimated

单击按钮时,文本会更改,因此我知道更改状态是可行的。但是set(this.opacity)行不起作用,因为该组件从不显示。

class TestAnimation extends React.Component {

  constructor(props) {
    super(props);
    this.state = { show: false };
    this.opacity = new Value(0);
  }

  render () {
    return (
      <Wrapper
        position={this.props.position}
        margin={this.props.margin}
        bottom={this.props.bottom}
        top={this.props.top}
        right={this.props.right}
        left={this.props.left}
        debug={this.props.debug}
      >
        <Animated.Code>
          {() => set(this.opacity, this.state.show ? 1 : 0)}
        </Animated.Code>
        <Animated.View
          style={{
            position: "absolute",
            opacity: this.opacity,
            top: 0,
            width: 230,
            height: 230
          }}
        >
          <Circle />
        </Animated.View>
        <Touchable
          onPress={() => this.setState({show: !this.state.show})}
        >
          <Text>
            Showing {this.state.show ? 'yes' : 'no'}
          </Text>
        </Touchable>
      </Wrapper>
    )
  }
}

0 个答案:

没有答案
相关问题