React Addons: GSAP Transition Group
Use GSAP animations for transitions which work in any browser both GSAP and React support. Uses React GSAP Enhancer to add GSAP support to React Components, and extends ReactTransitionGroup to create an element which adds GSAP powered transitions which even work in IE8.
Usage
<ReactGSAPTransitionGroup
tweenAppear={ tweenAppearFactory :function }
tweenEnter={ tweenEnterFactory :function }
tweenLeave={ tweenLeaveFactory :function }
transitionAppear={ shouldAppear :boolean }
transitionEnter={ shouldEnter :boolean }
transitionLeave={ shouldLeave :boolean }
></ReactGSAPTransitionGroup>
Functions more or less like ReactCSSTransitionGroup, although rather than transitionName
, the three properties are used to specify the transitions.
- The Tween Props
- These should be set to functions which take an arguments object that has the properties
target
andoptions
and return a TweenLite, TweenMax, TimelineLite, or TimelineMax instance. See the Example section for a simple case of a use ofTweenMax.fromTo
. - Note: If you need to target a specific element within, use
utils.target.find
and other such element finding/filtering functions. See React GSAP Enhancer's documents for more details on this. tweenAppear: function({ target, options }): (TweenLite|TweenMax|TimelineLite|TimelineMax)
optionaltweenEnter: function({ target, options }): (TweenLite|TweenMax|TimelineLite|TimelineMax)
tweenLeave: function({ target, options }): (TweenLite|TweenMax|TimelineLite|TimelineMax)
- These should be set to functions which take an arguments object that has the properties
- The Transition Props
- These specify whether a transition should be played at a given life cycle point, in much the same way the same props work in ReactCSSTransitionGroup.
tweenAppear: boolean = false
determines whether or nottweenAppear
is called.tweenEnter: boolean = true
determines whether or nottweenEnter
is called.tweenLeave: boolean = true
determines whether or nottweenLeave
is called.
Example
Note: This example is written in ES6, sorta.
let React = ;let ReactGSAPTransitionGroup = ;let TweenMax = ; //////// Transition factories// See react-gsap-enhancer (https://github.com/azazdeaz/react-gsap-enhancer) for how these functions should be structured. { return TweenMax;} { return TweenMax;} //////// A grouping component const TransitioningList = React;
ES5 Example of the Factory Functions
{ return TweenMax;} { return TweenMax;}
Considerations when targeting legacy browsers
- You should add core-js to ensure things such as
Map
,Array#map
, and other sundry ES5 things. - If targeting ES3 environments (mostly IE8), you should at least add a transform to make property name access ES3 safe, such as es3ify if using Browserify.