How to use React TransitionMotion willEnter()

后端 未结 1 596
清歌不尽
清歌不尽 2021-02-09 15:58

Using React Motion\'s TransitionMotion, I want to animate 1 or more boxes in and out. When a box enters the view, it\'s width and height should go from 0 pixels to 200 pixels an

1条回答
  •  走了就别回头了
    2021-02-09 16:39

    As per the documentation of styles under the TransitionMotion section (and I don't claim to have understood all of it entirely :)):

    styles: ... an array of TransitionStyle ...

    The key thing to note here is that there are 2 types of style objects that this library deals with (or at least this TransitionMotion part of it) and it calls them TransitionStyle and TransitionPlainStyle.

    The previous values passed into styles attribute were of TransitionPlainStyle. Changing them to TransitionStyle magically starts animating the Enter sequence.

    You can read more about 2 different types mentioned above over here.

    styles={this.state.items.map(item => ({
      key: item.key,
      style: {
        width: spring(item.width), 
        height: spring(item.height),
        opacity: spring(item.opacity)
      }
    }))}
    

    Forked codepen demo.

    Again, I do not fully understand the inner workings of it just yet. I just know that your styles had to be changed in the above way to make it work.

    I will be happy if someone can educate me on this as well.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题