@@ -213,10 +213,14 @@ class FlipMove extends Component<ConvertedProps, FlipMoveState> {
213
213
this . doesChildNeedToBeAnimated ,
214
214
) ;
215
215
216
- dynamicChildren . forEach ( ( child , n ) => {
216
+ // Splitting DOM reads and writes to be peformed in batches
217
+ const childrenInitialStyles = dynamicChildren . map ( child =>
218
+ this . computeInitialStyles ( child ) ,
219
+ ) ;
220
+ dynamicChildren . forEach ( ( child , index ) => {
217
221
this . remainingAnimations += 1 ;
218
222
this . childrenToAnimate . push ( getKey ( child ) ) ;
219
- this . animateChild ( child , n ) ;
223
+ this . animateChild ( child , index , childrenInitialStyles [ index ] ) ;
220
224
} ) ;
221
225
222
226
if ( typeof this . props . onStartAll === 'function' ) {
@@ -382,7 +386,7 @@ class FlipMove extends Component<ConvertedProps, FlipMoveState> {
382
386
} ) ;
383
387
}
384
388
385
- animateChild ( child : ChildData , index : number ) {
389
+ animateChild ( child : ChildData , index : number , childInitialStyles : Styles ) {
386
390
const { domNode } = this . getChildData ( getKey ( child ) ) ;
387
391
if ( ! domNode ) {
388
392
return ;
@@ -396,7 +400,7 @@ class FlipMove extends Component<ConvertedProps, FlipMoveState> {
396
400
// In FLIP terminology, this is the 'Invert' stage.
397
401
applyStylesToDOMNode ( {
398
402
domNode,
399
- styles : this . computeInitialStyles ( child ) ,
403
+ styles : childInitialStyles ,
400
404
} ) ;
401
405
402
406
// Start by invoking the onStart callback for this child.
@@ -553,19 +557,24 @@ class FlipMove extends Component<ConvertedProps, FlipMoveState> {
553
557
554
558
this . parentData . boundingBox = this . props . getPosition ( parentDomNode ) ;
555
559
560
+ // Splitting DOM reads and writes to be peformed in batches
561
+ const childrenBoundingBoxes = [ ] ;
562
+
556
563
this . state . children . forEach ( child => {
557
564
const childKey = getKey ( child ) ;
558
565
559
566
// It is possible that a child does not have a `key` property;
560
567
// Ignore these children, they don't need to be moved.
561
568
if ( ! childKey ) {
569
+ childrenBoundingBoxes . push ( null ) ;
562
570
return ;
563
571
}
564
572
565
573
// In very rare circumstances, for reasons unknown, the ref is never
566
574
// populated for certain children. In this case, avoid doing this update.
567
575
// see: https://github.com/joshwcomeau/react-flip-move/pull/91
568
576
if ( ! this . hasChildData ( childKey ) ) {
577
+ childrenBoundingBoxes . push ( null ) ;
569
578
return ;
570
579
}
571
580
@@ -574,15 +583,30 @@ class FlipMove extends Component<ConvertedProps, FlipMoveState> {
574
583
// If the child element returns null, we need to avoid trying to
575
584
// account for it
576
585
if ( ! childData . domNode || ! child ) {
586
+ childrenBoundingBoxes . push ( null ) ;
577
587
return ;
578
588
}
579
589
580
- this . setChildData ( childKey , {
581
- boundingBox : getRelativeBoundingBox ( {
590
+ childrenBoundingBoxes . push (
591
+ getRelativeBoundingBox ( {
582
592
childDomNode : childData . domNode ,
583
593
parentDomNode,
584
594
getPosition : this . props . getPosition ,
585
595
} ) ,
596
+ ) ;
597
+ } ) ;
598
+
599
+ this . state . children . forEach ( ( child , index ) => {
600
+ const childKey = getKey ( child ) ;
601
+
602
+ const childBoundingBox = childrenBoundingBoxes [ index ] ;
603
+
604
+ if ( ! childKey ) {
605
+ return ;
606
+ }
607
+
608
+ this . setChildData ( childKey , {
609
+ boundingBox : childBoundingBox ,
586
610
} ) ;
587
611
} ) ;
588
612
}
0 commit comments