Skip to content

Commit

Permalink
Unifying playback controls types
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Mar 7, 2023
1 parent 1f77c7c commit 88df7ea
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
3 changes: 1 addition & 2 deletions packages/framer-motion/src/animation/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { isMotionValue } from "../value/utils/is-motion-value"
* @public
*/
export interface AnimationPlaybackControls {
currentTime?: number | null
stop: () => void
isAnimating: () => boolean
}

/**
Expand Down Expand Up @@ -68,6 +68,5 @@ export function animate<V>(

return {
stop: () => value.stop(),
isAnimating: () => value.isAnimating(),
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export interface AnimationState<V> {
done: boolean
}

export interface PlaybackControls {
stop: () => void
}

/**
* An update function. It accepts a timestamp used to advance the animation.
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/framer-motion/src/animation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ export type ControlsAnimationDefinition =
| TargetAndTransition
| TargetResolver

export interface PlaybackControls {
stop: () => void
currentTime?: number
}

/**
* @public
*/
Expand Down
8 changes: 5 additions & 3 deletions packages/framer-motion/src/value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (v: T) => T

Expand All @@ -18,7 +18,9 @@ export type Subscriber<T> = (v: T) => void
*/
export type PassiveEffect<T> = (v: T, safeSetter: (v: T) => void) => void

export type StartAnimation = (complete: () => void) => PlaybackControls | void
export type StartAnimation = (
complete: () => void
) => AnimationPlaybackControls | void

export interface MotionValueEventCallbacks<V> {
animationStart: () => void
Expand Down Expand Up @@ -109,7 +111,7 @@ export class MotionValue<V = any> {
*
* @internal
*/
animation?: null | PlaybackControls
animation?: null | AnimationPlaybackControls

/**
* Tracks whether this value can output a velocity. Currently this is only true
Expand Down
4 changes: 2 additions & 2 deletions packages/framer-motion/src/value/use-spring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -32,7 +32,7 @@ export function useSpring(
config: SpringOptions = {}
) {
const { isStatic } = useContext(MotionConfigContext)
const activeSpringAnimation = useRef<PlaybackControls | null>(null)
const activeSpringAnimation = useRef<AnimationPlaybackControls | null>(null)
const value = useMotionValue(isMotionValue(source) ? source.get() : source)

const stopAnimation = () => {
Expand Down

0 comments on commit 88df7ea

Please sign in to comment.