From 88df7ead9ef7fffd37cc3decb843d70c55159f16 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Fri, 3 Mar 2023 13:35:18 +0000 Subject: [PATCH] Unifying playback controls types --- packages/framer-motion/src/animation/animate.ts | 3 +-- .../src/animation/legacy-popmotion/inertia.ts | 4 ++-- .../framer-motion/src/animation/legacy-popmotion/types.ts | 4 ---- packages/framer-motion/src/animation/types.ts | 5 ----- packages/framer-motion/src/value/index.ts | 8 +++++--- packages/framer-motion/src/value/use-spring.ts | 4 ++-- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/framer-motion/src/animation/animate.ts b/packages/framer-motion/src/animation/animate.ts index 8ee63cba44..877e9cd3ca 100644 --- a/packages/framer-motion/src/animation/animate.ts +++ b/packages/framer-motion/src/animation/animate.ts @@ -7,8 +7,8 @@ import { isMotionValue } from "../value/utils/is-motion-value" * @public */ export interface AnimationPlaybackControls { + currentTime?: number | null stop: () => void - isAnimating: () => boolean } /** @@ -68,6 +68,5 @@ export function animate( return { stop: () => value.stop(), - isAnimating: () => value.isAnimating(), } } diff --git a/packages/framer-motion/src/animation/legacy-popmotion/inertia.ts b/packages/framer-motion/src/animation/legacy-popmotion/inertia.ts index 63b2921a2d..18b9a0d07d 100644 --- a/packages/framer-motion/src/animation/legacy-popmotion/inertia.ts +++ b/packages/framer-motion/src/animation/legacy-popmotion/inertia.ts @@ -1,8 +1,8 @@ -import { PlaybackControls } from "./types" import { animateValue } from "." import { velocityPerSecond } from "../../utils/velocity-per-second" import { frameData } from "../../frameloop/data" import { AnimationOptions } from "../types" +import { AnimationPlaybackControls } from "../animate" export function inertia({ keyframes, @@ -21,7 +21,7 @@ export function inertia({ onStop, }: AnimationOptions) { const origin = keyframes[0] - let currentAnimation: PlaybackControls + let currentAnimation: AnimationPlaybackControls function isOutOfBounds(v: number) { return (min !== undefined && v < min) || (max !== undefined && v > max) diff --git a/packages/framer-motion/src/animation/legacy-popmotion/types.ts b/packages/framer-motion/src/animation/legacy-popmotion/types.ts index 1e6279711e..c9da71c7bc 100644 --- a/packages/framer-motion/src/animation/legacy-popmotion/types.ts +++ b/packages/framer-motion/src/animation/legacy-popmotion/types.ts @@ -12,10 +12,6 @@ export interface AnimationState { done: boolean } -export interface PlaybackControls { - stop: () => void -} - /** * An update function. It accepts a timestamp used to advance the animation. */ diff --git a/packages/framer-motion/src/animation/types.ts b/packages/framer-motion/src/animation/types.ts index bbc941f44c..5c317e4f95 100644 --- a/packages/framer-motion/src/animation/types.ts +++ b/packages/framer-motion/src/animation/types.ts @@ -76,11 +76,6 @@ export type ControlsAnimationDefinition = | TargetAndTransition | TargetResolver -export interface PlaybackControls { - stop: () => void - currentTime?: number -} - /** * @public */ diff --git a/packages/framer-motion/src/value/index.ts b/packages/framer-motion/src/value/index.ts index 79ca65df19..6b86da1844 100644 --- a/packages/framer-motion/src/value/index.ts +++ b/packages/framer-motion/src/value/index.ts @@ -3,8 +3,8 @@ import { FrameData } from "../frameloop/types" import { sync } from "../frameloop" import { SubscriptionManager } from "../utils/subscription-manager" import { velocityPerSecond } from "../utils/velocity-per-second" -import { PlaybackControls } from "../animation/types" import { warnOnce } from "../utils/warn-once" +import { AnimationPlaybackControls } from "../animation/animate" export type Transformer = (v: T) => T @@ -18,7 +18,9 @@ export type Subscriber = (v: T) => void */ export type PassiveEffect = (v: T, safeSetter: (v: T) => void) => void -export type StartAnimation = (complete: () => void) => PlaybackControls | void +export type StartAnimation = ( + complete: () => void +) => AnimationPlaybackControls | void export interface MotionValueEventCallbacks { animationStart: () => void @@ -109,7 +111,7 @@ export class MotionValue { * * @internal */ - animation?: null | PlaybackControls + animation?: null | AnimationPlaybackControls /** * Tracks whether this value can output a velocity. Currently this is only true diff --git a/packages/framer-motion/src/value/use-spring.ts b/packages/framer-motion/src/value/use-spring.ts index b705e5a5c7..71ae8710b4 100644 --- a/packages/framer-motion/src/value/use-spring.ts +++ b/packages/framer-motion/src/value/use-spring.ts @@ -3,10 +3,10 @@ import { MotionValue } from "../value" import { isMotionValue } from "./utils/is-motion-value" import { useMotionValue } from "./use-motion-value" import { MotionConfigContext } from "../context/MotionConfigContext" -import { PlaybackControls } from "../animation/legacy-popmotion/types" import { animateValue } from "../animation/legacy-popmotion" import { SpringOptions } from "../animation/types" import { useIsomorphicLayoutEffect } from "../utils/use-isomorphic-effect" +import { AnimationPlaybackControls } from "../animation/animate" /** * Creates a `MotionValue` that, when `set`, will use a spring animation to animate to its new state. @@ -32,7 +32,7 @@ export function useSpring( config: SpringOptions = {} ) { const { isStatic } = useContext(MotionConfigContext) - const activeSpringAnimation = useRef(null) + const activeSpringAnimation = useRef(null) const value = useMotionValue(isMotionValue(source) ? source.get() : source) const stopAnimation = () => {