Skip to content

Commit

Permalink
Converting time correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Apr 11, 2023
1 parent c7c91b8 commit 5d74f69
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions dev/optimized-appear/interrupt-tween-transforms.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,22 @@
const duration = 0.5
const y = motionValue(0)

let isFirstFrame = true
y.on("change", (latest) => {
if (latest < 50) {
showError(
document.getElementById("box"),
`y transform should never be less than 50, but was ${latest}`
)
}

if (isFirstFrame && latest === 100) {
showError(
document.getElementById("box"),
`y transform shouldn't be 100 on the first frame`
)
}
isFirstFrame = false
})

// This is the tree to be rendered "server" and client-side.
Expand Down
11 changes: 10 additions & 1 deletion dev/optimized-appear/interrupt-tween-x.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,22 @@
const duration = 0.5
const x = motionValue(0)

let isFirstFrame = true
x.onChange((latest) => {
if (latest < 50) {
showError(
document.getElementById("box"),
`x transform should never be less than 50`
)
}

if (latest === 100 && isFirstFrame) {
showError(
document.getElementById("box"),
`x transform shouldn't be 100 on the first frame`
)
}
isFirstFrame = false
})

// This is the tree to be rendered "server" and client-side.
Expand Down Expand Up @@ -76,7 +85,7 @@
// Emulate server rendering of element
root.innerHTML = ReactDOMServer.renderToString(Component)

// Start Motion One animation
// Start WAAPI animation
const animation = startOptimizedAppearAnimation(
document.getElementById("box"),
"transform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export function handoffOptimizedAppearAnimation(
*/
sync.update(() => {
if (value.animation) {
value.animation.time =
performance.now() - millisecondsToSeconds(sampledTime)
value.animation.time = millisecondsToSeconds(
performance.now() - sampledTime
)
}
})

Expand Down

0 comments on commit 5d74f69

Please sign in to comment.