@@ -10,10 +10,13 @@ import {
1010 calculateWindowCentre ,
1111 calculateElementCenterInViewport ,
1212 recalculateElementBoundingBoxFromScroll ,
13+ getWindowDimensions ,
1314} from '../../lib/dom' ;
1415import SimpleKeyframe from '../SimpleKeyframe' ;
1516import { standard , accelerate } from '../../lib/curves' ;
1617import { zIndexStack } from '../../lib/style' ;
18+ import { dynamic } from '../../lib/duration' ;
19+ import { Duration } from '../types' ;
1720
1821export interface CircleExpandProps extends CollectorChildrenProps {
1922 /**
@@ -24,7 +27,7 @@ export interface CircleExpandProps extends CollectorChildrenProps {
2427 /**
2528 * How long the animation should take over {duration}ms.
2629 */
27- duration : number ;
30+ duration : Duration ;
2831
2932 /**
3033 * zIndex to be applied to the moving element.
@@ -43,48 +46,54 @@ export interface CircleExpandProps extends CollectorChildrenProps {
4346 */
4447export default class CircleExpand extends React . Component < CircleExpandProps > {
4548 static defaultProps = {
46- duration : 500 ,
49+ duration : 'dynamic' ,
4750 zIndex : zIndexStack . circleExpand ,
4851 } ;
4952
5053 renderAnimation = ( data : AnimationData , options : { step ?: number ; onFinish : ( ) => void } ) => {
5154 const { duration, background, zIndex } = this . props ;
5255
5356 // Scroll could have changed between unmount and this prepare step, let's recalculate just in case.
54- const fromTargetSizeLocation = recalculateElementBoundingBoxFromScroll (
57+ const originBoundingBox = recalculateElementBoundingBoxFromScroll (
5558 data . origin . elementBoundingBox
5659 ) ;
57- const minSize = Math . min ( fromTargetSizeLocation . size . width , fromTargetSizeLocation . size . height ) ;
58- const fromTargetHypotenuse = calculateHypotenuse ( fromTargetSizeLocation . size ) ;
59- const fromTargetCenterInViewport = calculateElementCenterInViewport ( fromTargetSizeLocation ) ;
60+ const minSize = Math . min ( originBoundingBox . size . width , originBoundingBox . size . height ) ;
61+ const fromTargetHypotenuse = calculateHypotenuse ( originBoundingBox . size ) ;
62+ const fromTargetCenterInViewport = calculateElementCenterInViewport ( originBoundingBox ) ;
6063 const viewportCenter = calculateWindowCentre ( ) ;
61- const windowHypotenuse = calculateHypotenuse ( {
62- width : window . innerWidth ,
63- height : window . innerHeight ,
64- } ) ;
64+ const windowDimensions = getWindowDimensions ( ) ;
65+ const windowHypotenuse = calculateHypotenuse ( windowDimensions ) ;
6566 const difference = {
6667 width : viewportCenter . left - fromTargetCenterInViewport . left ,
6768 height : viewportCenter . top - fromTargetCenterInViewport . top ,
6869 } ;
6970 const hypotenuseDifference = calculateHypotenuse ( difference ) ;
7071 const scale = Math . ceil ( ( windowHypotenuse + hypotenuseDifference ) / minSize ) ;
72+ const calculatedDuration =
73+ duration === 'dynamic'
74+ ? dynamic ( originBoundingBox , {
75+ location : { left : 0 , top : 0 } ,
76+ size : windowDimensions ,
77+ raw : { } as any ,
78+ } )
79+ : duration ;
7180
7281 return (
7382 < SimpleKeyframe
7483 style = { {
7584 zIndex,
7685 left :
77- fromTargetSizeLocation . location . left -
78- ( fromTargetHypotenuse - fromTargetSizeLocation . size . width ) / 2 ,
86+ originBoundingBox . location . left -
87+ ( fromTargetHypotenuse - originBoundingBox . size . width ) / 2 ,
7988 top :
80- fromTargetSizeLocation . location . top -
81- ( fromTargetHypotenuse - fromTargetSizeLocation . size . height ) / 2 ,
89+ originBoundingBox . location . top -
90+ ( fromTargetHypotenuse - originBoundingBox . size . height ) / 2 ,
8291 width : fromTargetHypotenuse ,
8392 height : fromTargetHypotenuse ,
8493 borderRadius : '50%' ,
8594 position : 'absolute' ,
8695 background,
87- transition : `transform ${ accelerate ( ) } ${ duration } ms, opacity ${ standard ( ) } ${ duration /
96+ transition : `transform ${ accelerate ( ) } ${ calculatedDuration } ms, opacity ${ standard ( ) } ${ calculatedDuration /
8897 2 } ms`,
8998 transform : 'scale(1)' ,
9099 willChange : 'transform' ,
0 commit comments