为什么React-Semantic-UI Transition无法为组件设置动画?

时间:2019-03-08 12:20:58

标签: reactjs semantic-ui-react react-transition-group

我有一个Modal警报的组件。为了给模态动画,我使用了来自语义UI反应的Transition。但是只有少数动画(pulsebounceflash)有效,并且仅在安装Component时有效,而在关闭Modal时无效。此外,duration属性也不起作用。

class Alert extends React.Component {
  state = {
    open: true
  };

  close = () => {
    this.setState({
      open: false
    });
  };

  render() {
    const { open } = this.state;
    return (
      <Transition animation="fade" duration={1000} visible={open}>
        <Modal
          size="mini"
          closeOnDimmerClick={false}
          closeOnEscape={false}
          open={this.state.open}
          onClose={this.close}>

          <Modal.Content>
            <p>
              Hello user
            </p>
          </Modal.Content>
          <Modal.Actions>
            <Button color="blue" onClick={this.close}>
              Ok
            </Button>
          </Modal.Actions>
        </Modal>
      </Transition>
    );
  }
}

为什么会有这种奇怪的行为?我在做什么错了?

1 个答案:

答案 0 :(得分:1)

Modal是在Transition进行动画之前的卸载方式,一种方法是让Transition卸载模态:

class Alert extends React.Component {
  state = {
    open: true
  };

  close = () => {
    this.setState({
      open: false
    });
  };

  render() {
    const { open } = this.state;
    return (
      <Transition
        animation="fade"
        duration={1000}
        unmountOnHide={true}
        visible={open}
      >
        <Modal
          size="mini"
          closeOnDimmerClick={false}
          closeOnEscape={false}
          open={true}
          onClose={this.close}
        >
          <Modal.Content>
            <p>Hello user</p>
          </Modal.Content>
          <Modal.Actions>
            <Button color="blue" onClick={this.close}>
              Ok
            </Button>
          </Modal.Actions>
        </Modal>
      </Transition>
    );
  }
}

Edit Alert

希望对您有帮助!