Skip to content

ReactCSSTransitionGroup - add transition lifecycle hooks #5914

@RandScullard

Description

@RandScullard

I'm using ReactCSSTransitionGroup to implement a simple nested expand-collapse UI. Since I'm animating element height and you can't animate to an "auto" value in CSS, I need to get the auto height from the DOM and set it as an explicit height. Then, because of the nesting, when a child expands or collapses, I need to communicate this height change to the child's ancestors. I'm also using the iScroll library to implement scrolling, and when any height transition completes, I need to refresh the iScroll component.

This is easy to implement with CSS transitions and ReactCSSTransitionGroup, but it does require that ReactCSSTransitionGroup notify its child component when transitions begin and end, much the way the low-level ReactTransitionGroup calls lifecycle hooks on its child. I propose that ReactCSSTransitionGroup call the following functions on its child component:

componentWillTransition(animationType)
componentDidTransition(animationType)

where animationType is 'appear', 'enter', or 'leave'.

componentWillTransition is called just before the first CSS transition class (e.g., 'example-enter' or 'example-leave') is added to the element, and componentDidTransition is called just after both CSS transition classes are removed from the element.

I've implemented this with a few simple code changes to ReactCSSTransitionGroupChild.js. Please see pull request #5915. Feedback is welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions