Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit a3dbf96

Browse files
committed
feat(fade-move): adds props to disable scaling
1 parent ed53719 commit a3dbf96

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

packages/core/src/motions/CrossFadeMove/__docs__/docs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as Styled from './styled';
1313
# CrossFadeMove
1414

1515
Is a composite motion of CrossFade and [Move](/move).
16-
Useful for moving an element moving from one position to another when the elements have **stark visual differences** to each other, but is still of a similar aspect ratio.
16+
Useful for moving an element moving from one position to another when the elements have **stark visual differences** to each other.
1717

1818
## Usage
1919

packages/core/src/motions/FadeMove/index.tsx

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Collector, {
55
CollectorActions,
66
MotionData,
77
} from '../../Collector';
8-
import * as math from '../../lib/math';
98
import { recalculateElementBoundingBoxFromScroll } from '../../lib/dom';
109
import noop from '../../lib/noop';
1110
import { standard } from '../../lib/curves';
@@ -28,6 +27,18 @@ export interface FadeMoveProps extends CollectorChildrenProps {
2827
* Timing function to be used in the transition.
2928
*/
3029
timingFunction: string;
30+
31+
/**
32+
* Enables scaling of the x-axis.
33+
* Defaults to true.
34+
*/
35+
scaleX?: boolean;
36+
37+
/**
38+
* Enables scaling of the y-axis.
39+
* Defaults to true.
40+
*/
41+
scaleY?: boolean;
3142
}
3243

3344
export default class FadeMove extends React.Component<FadeMoveProps> {
@@ -40,25 +51,21 @@ export default class FadeMove extends React.Component<FadeMoveProps> {
4051
calculatedDuration: number = 0;
4152

4253
renderMotion = (data: MotionData, options: { moveToTarget?: boolean } = {}) => {
43-
const { timingFunction, duration, zIndex } = this.props;
44-
// Scroll could have changed between unmount and this prepare step, let's recalculate
45-
// just in case.
46-
const fromTargetSizeLocation = recalculateElementBoundingBoxFromScroll(
47-
data.origin.elementBoundingBox
48-
);
49-
const fromEndXOffset =
50-
data.destination.elementBoundingBox.location.left - fromTargetSizeLocation.location.left;
51-
const fromEndYOffset =
52-
data.destination.elementBoundingBox.location.top - fromTargetSizeLocation.location.top;
54+
const { timingFunction, duration, zIndex, scaleY, scaleX } = this.props;
55+
// Scroll could have changed between unmount and this prepare step, let's recalculate just in case.
56+
const originTarget = recalculateElementBoundingBoxFromScroll(data.origin.elementBoundingBox);
57+
const destinationTarget = data.destination.elementBoundingBox;
58+
const translateToX = destinationTarget.location.left - originTarget.location.left;
59+
const translateToY = destinationTarget.location.top - originTarget.location.top;
5360
this.calculatedDuration =
54-
duration === 'dynamic'
55-
? dynamic(fromTargetSizeLocation, data.destination.elementBoundingBox)
56-
: duration;
61+
duration === 'dynamic' ? dynamic(originTarget, destinationTarget) : duration;
62+
const scaleToX = scaleX ? originTarget.size.width / destinationTarget.size.width : 1;
63+
const scaleToY = scaleY ? originTarget.size.height / destinationTarget.size.height : 1;
5764

5865
return data.origin.render({
5966
ref: noop,
6067
style: {
61-
...fromTargetSizeLocation.location,
68+
...originTarget.location,
6269
zIndex,
6370
transition: `transform ${this.calculatedDuration}ms ${timingFunction}, opacity ${this
6471
.calculatedDuration / 2}ms ${timingFunction}`,
@@ -68,17 +75,11 @@ export default class FadeMove extends React.Component<FadeMoveProps> {
6875
opacity: 1,
6976
// Elminate any margins so they don't affect the transition.
7077
margin: 0,
71-
height: `${fromTargetSizeLocation.size.height}px`,
72-
width: `${fromTargetSizeLocation.size.width}px`,
78+
height: `${originTarget.size.height}px`,
79+
width: `${originTarget.size.width}px`,
7380
...(options.moveToTarget
7481
? {
75-
transform: `translate3d(${fromEndXOffset}px, ${fromEndYOffset}px, 0) scale3d(${math.percentageDifference(
76-
data.destination.elementBoundingBox.size.width,
77-
fromTargetSizeLocation.size.width
78-
)}, ${math.percentageDifference(
79-
data.destination.elementBoundingBox.size.height,
80-
fromTargetSizeLocation.size.height
81-
)}, 1)`,
82+
transform: `translate3d(${translateToX}px, ${translateToY}px, 0) scale3d(${scaleToX}, ${scaleToY}, 1)`,
8283
opacity: 0,
8384
}
8485
: {}),

0 commit comments

Comments
 (0)