Skip to content

Commit

Permalink
Merge branch 'framer:main' into fix/animatepresence
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeSeoKim authored Jun 9, 2022
2 parents 3eb1ba9 + b12b137 commit 4229490
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Framer Motion adheres to [Semantic Versioning](http://semver.org/).

## [6.3.11] 2022-06-08

### Fixed

- Fixed scale correction during rotation & layout animations.

## [6.3.10] 2022-06-03

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions dev/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "framer-motion--dev",
"version": "6.3.10",
"version": "6.3.11",
"private": true,
"scripts": {
"dev": "webpack serve --config ./webpack/config.js --hot"
},
"dependencies": {
"@react-three/drei": "^7.27.3",
"@react-three/fiber": "^7.0.24",
"framer-motion": "^6.3.10",
"framer-motion-3d": "^6.3.10",
"framer-motion": "^6.3.11",
"framer-motion-3d": "^6.3.11",
"path-browserify": "^1.0.1",
"popmotion": "11.0.3",
"react": "^17.0.2",
Expand Down
117 changes: 117 additions & 0 deletions dev/projection/shared-promote-new-mix-rotate-scale-correction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<html>
<head>
<style>
body {
padding: 0;
margin: 0;
}

#container-a {
position: relative;
width: 300px;
height: 300px;
}

#box-a {
width: 100px;
height: 100px;
background-color: #00cc88;
}

#container-b {
position: relative;
width: 300px;
height: 600px;
}

#box-b {
position: absolute;
top: 100px;
left: 100px;
width: 200px;
height: 300px;
background-color: #09f;
}

#trigger-overflow {
width: 1px;
height: 1px;
position: absolute;
top: 2000px;
left: 2000px;
}

[data-layout-correct="false"] {
background: #dd1144 !important;
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container-a"><div id="box-a"></div></div>
<div id="trigger-overflow"></div>

<script src="../../packages/framer-motion/dist/projection.dev.js"></script>
<script src="./script-assert.js"></script>
<script src="./script-animate.js"></script>
<script>
const { createNode } = window.Animate
const {
matchViewportBox,
matchVisibility,
matchOpacity,
matchBorderRadius,
matchRotate,
} = window.Assert

const container = document.getElementById("container-a")
const containerProjection = createNode(container, undefined, {
layoutId: "container",
})

const box = document.getElementById("box-a")
const boxProjection = createNode(box, containerProjection, {
layoutId: "box",
})

containerProjection.willUpdate()
boxProjection.willUpdate()

const newContainer = document.createElement("div")
newContainer.id = "container-b"
document.body.appendChild(newContainer)
const newContainerProjection = createNode(newContainer, undefined, {
layoutId: "container",
})

const newBox = document.createElement("div")
newBox.id = "box-b"
newContainer.appendChild(newBox)
const newBoxProjection = createNode(
newBox,
newContainerProjection,
{ layoutId: "box" }
)

boxProjection.setValue("opacity", 0.8)
newBoxProjection.setValue("borderRadius", 20)
newBoxProjection.setValue("rotate", 40)

newBoxProjection.root.didUpdate()

sync.postRender(() => {
const bbox = newBox.getBoundingClientRect()
matchViewportBox(box, bbox)
matchVisibility(box, "visible")
matchVisibility(newBox, "visible")
matchOpacity(box, 0.8)
matchOpacity(newBox, 1)
matchRotate(box, 20)
matchRotate(newBox, 20)

matchBorderRadius(box, "6.66667% / 5%")
matchBorderRadius(newBox, "6.66667% / 5%")
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "6.3.10",
"version": "6.3.11",
"packages": [
"packages/*"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/framer-motion-3d/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "framer-motion-3d",
"version": "6.3.10",
"version": "6.3.11",
"description": "A simple and powerful React animation library for @react-three/fiber",
"main": "dist/cjs/index.js",
"module": "dist/es/index.mjs",
Expand Down Expand Up @@ -48,7 +48,7 @@
"postpublish": "git push --tags"
},
"dependencies": {
"framer-motion": "^6.3.10",
"framer-motion": "^6.3.11",
"react-merge-refs": "^1.1.0"
},
"peerDependencies": {
Expand Down Expand Up @@ -88,5 +88,5 @@
"webpack": "^5.27.2",
"yarn-deduplicate": "^1.1.1"
},
"gitHead": "aa9cc093d1baa2c80016ced3a3a165f02e15e0e6"
"gitHead": "3c00433cc9c4193988de4f956c5ec334746c1746"
}
6 changes: 3 additions & 3 deletions packages/framer-motion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "framer-motion",
"version": "6.3.10",
"version": "6.3.11",
"description": "A simple and powerful React animation library",
"main": "dist/cjs/index.js",
"module": "dist/es/index.mjs",
Expand Down Expand Up @@ -103,8 +103,8 @@
},
{
"path": "./dist/size-webpack-dom-max.js",
"maxSize": "31.5 kB"
"maxSize": "31.6 kB"
}
],
"gitHead": "aa9cc093d1baa2c80016ced3a3a165f02e15e0e6"
"gitHead": "3c00433cc9c4193988de4f956c5ec334746c1746"
}
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ export function createProjectionNode<I>({
}

const measured = this.measure()

roundBox(measured)

const prevLayout = this.layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ describe("buildProjectionTransform", () => {
},
}
expect(buildProjectionTransform(delta, { x: 1, y: 1 })).toEqual(
"translate3d(100px, 300px, 0) scale(2, 4)"
"translate3d(100px, 300px, 0) scale(1, 1) scale(2, 4)"
)

expect(buildProjectionTransform(delta, { x: 2, y: 0.5 })).toEqual(
"translate3d(50px, 600px, 0) scale(2, 4)"
"translate3d(50px, 600px, 0) scale(0.5, 2) scale(4, 2)"
)

expect(
buildProjectionTransform(delta, { x: 2, y: 0.5 }, { rotate: 45 })
).toEqual(
"translate3d(50px, 600px, 0) scale(0.5, 2) rotate(45deg) scale(4, 2)"
)
})
})
17 changes: 15 additions & 2 deletions packages/framer-motion/src/projection/styles/transform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ResolvedValues } from "../../render/types"
import { Delta, Point } from "../geometry/types"

export const identityProjection = "translate3d(0px, 0px, 0) scale(1, 1)"
export const identityProjection =
"translate3d(0px, 0px, 0) scale(1, 1) scale(1, 1)"

export function buildProjectionTransform(
delta: Delta,
Expand All @@ -18,14 +19,26 @@ export function buildProjectionTransform(
const yTranslate = delta.y.translate / treeScale.y
let transform = `translate3d(${xTranslate}px, ${yTranslate}px, 0) `

/**
* Apply scale correction for the tree transform.
* This will apply scale to the screen-orientated axes.
*/
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `

if (latestTransform) {
const { rotate, rotateX, rotateY } = latestTransform
if (rotate) transform += `rotate(${rotate}deg) `
if (rotateX) transform += `rotateX(${rotateX}deg) `
if (rotateY) transform += `rotateY(${rotateY}deg) `
}

transform += `scale(${delta.x.scale}, ${delta.y.scale})`
/**
* Apply scale to match the size of the element to the size we want it.
* This will apply scale to the element-orientated axes.
*/
const elementScaleX = delta.x.scale * treeScale.x
const elementScaleY = delta.y.scale * treeScale.y
transform += `scale(${elementScaleX}, ${elementScaleY})`

return transform === identityProjection ? "none" : transform
}
2 changes: 1 addition & 1 deletion packages/framer-motion/src/value/use-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function useTransform<I, O>(
* export const MyComponent = () => {
* const x = useMotionValue(0)
* const y = useMotionValue(0)
* const z = useTransform([x, y], [latestX, latestY] => latestX * latestY)
* const z = useTransform([x, y], ([latestX, latestY]) => latestX * latestY)
*
* return <motion.div style={{ x, y, z }} />
* }
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7599,8 +7599,8 @@ __metadata:
cache-loader: ^1.2.5
convert-tsconfig-paths-to-webpack-aliases: ^0.9.2
fork-ts-checker-webpack-plugin: ^6.2.0
framer-motion: ^6.3.10
framer-motion-3d: ^6.3.10
framer-motion: ^6.3.11
framer-motion-3d: ^6.3.11
path-browserify: ^1.0.1
popmotion: 11.0.3
react: ^17.0.2
Expand Down Expand Up @@ -7665,7 +7665,7 @@ __metadata:
languageName: unknown
linkType: soft

"framer-motion-3d@^6.3.10, framer-motion-3d@workspace:packages/framer-motion-3d":
"framer-motion-3d@^6.3.11, framer-motion-3d@workspace:packages/framer-motion-3d":
version: 0.0.0-use.local
resolution: "framer-motion-3d@workspace:packages/framer-motion-3d"
dependencies:
Expand All @@ -7681,7 +7681,7 @@ __metadata:
"@types/react-dom": ^17.0.11
bundlesize: ^0.18.0
convert-tsconfig-paths-to-webpack-aliases: ^0.9.2
framer-motion: ^6.3.10
framer-motion: ^6.3.11
jest: ^24.8.0
jest-dom: ^3.5.0
jest-junit: ^6.4.0
Expand All @@ -7708,7 +7708,7 @@ __metadata:
languageName: unknown
linkType: soft

"framer-motion@^6.3.10, framer-motion@workspace:packages/framer-motion":
"framer-motion@^6.3.11, framer-motion@workspace:packages/framer-motion":
version: 0.0.0-use.local
resolution: "framer-motion@workspace:packages/framer-motion"
dependencies:
Expand Down

0 comments on commit 4229490

Please sign in to comment.