@@ -79,11 +79,10 @@ export class AnimationFeature extends Feature {
7979 } )
8080
8181 const factories = this . createAnimationFactories ( prevTarget , animationOptions , controlDelay )
82- const { getChildAnimations, childAnimations } = this . setupChildAnimations ( animationOptions , this . state . activeStates , isFallback )
82+ const { getChildAnimations } = this . setupChildAnimations ( animationOptions , this . state . activeStates , isFallback )
8383 return this . executeAnimations ( {
8484 factories,
8585 getChildAnimations,
86- childAnimations,
8786 transition : animationOptions ,
8887 controlActiveState,
8988 isExit,
@@ -100,7 +99,6 @@ export class AnimationFeature extends Feature {
10099 } : {
101100 factories : AnimationFactory [ ]
102101 getChildAnimations : ( ) => Promise < any >
103- childAnimations : ( ( ) => Promise < any > ) [ ]
104102 transition : $Transition | undefined
105103 controlActiveState : Partial < Record < string , boolean > > | undefined
106104 isExit : boolean
@@ -149,30 +147,33 @@ export class AnimationFeature extends Feature {
149147 controlActiveState : Partial < Record < string , boolean > > | undefined ,
150148 isFallback : boolean ,
151149 ) {
152- if ( ! this . state . visualElement . variantChildren ?. size || ! controlActiveState )
153- return { getChildAnimations : ( ) => Promise . resolve ( ) , childAnimations : [ ] }
150+ const visualElement = this . state . visualElement
151+ if ( ! visualElement . variantChildren ?. size || ! controlActiveState )
152+ return { getChildAnimations : ( ) => Promise . resolve ( ) }
154153
155154 const { staggerChildren = 0 , staggerDirection = 1 , delayChildren = 0 } = transition || { }
156- const maxStaggerDuration = ( this . state . visualElement . variantChildren . size - 1 ) * staggerChildren
157- const generateStaggerDuration = staggerDirection === 1
158- ? ( i = 0 ) => i * staggerChildren
159- : ( i = 0 ) => maxStaggerDuration - i * staggerChildren
155+ const numChildren = visualElement . variantChildren . size
156+ const maxStaggerDuration = ( numChildren - 1 ) * staggerChildren
157+ const delayIsFunction = typeof delayChildren === 'function'
158+ const generateStaggerDuration = delayIsFunction
159+ ? ( i : number ) => delayChildren ( i , numChildren )
160+ // Support deprecated staggerChildren,will be removed in next major version
161+ : staggerDirection === 1
162+ ? ( i = 0 ) => i * staggerChildren
163+ : ( i = 0 ) => maxStaggerDuration - i * staggerChildren
160164
161- const childAnimations = Array . from ( this . state . visualElement . variantChildren )
165+ const childAnimations = Array . from ( visualElement . variantChildren )
162166 . map ( ( child : VisualElement & { state : MotionState } , index ) => {
163- const childDelay = delayChildren + generateStaggerDuration ( index )
164167 return child . state . animateUpdates ( {
165168 controlActiveState,
166- controlDelay : isFallback ? 0 : childDelay ,
169+ controlDelay : ( delayIsFunction ? 0 : delayChildren ) + generateStaggerDuration ( index ) ,
167170 } )
168171 } )
169- . filter ( Boolean ) as ( ( ) => Promise < any > ) [ ]
170172
171173 return {
172- getChildAnimations : ( ) => Promise . all ( childAnimations . map ( ( animation ) => {
173- return animation ?. ( )
174+ getChildAnimations : ( ) => Promise . all ( childAnimations . map ( ( animation : ( ) => Promise < any > ) => {
175+ return animation ( )
174176 } ) ) ,
175- childAnimations,
176177 }
177178 }
178179
0 commit comments