Class VisualElement<Instance, RenderState, Options>Abstract

A VisualElement is an imperative abstraction around UI elements such as HTMLElement, SVGElement, Three.Object3D etc.

Type Parameters

  • Instance = unknown

  • RenderState = unknown

  • Options extends {} = {}

Constructors

Properties

animationState?: AnimationState$1

The AnimationState, this is hydrated by the animation Feature.

baseTarget: any

When values are removed from all animation props we need to search for a fallback value to animate to. These values are tracked in baseTarget.

bindToMotionValue: any
blockInitialAnimation: boolean

This can be set by AnimatePresence to force components that mount at the same time as it to mount as if they have initial={false} set.

children: Set<VisualElement<unknown, unknown, {}>>

A set containing references to this VisualElement's children.

current: null | Instance

A reference to the current underlying Instance, e.g. a HTMLElement or Three.Mesh etc.

depth: number

The depth of this VisualElement within the overall VisualElement tree.

events: any

An object containing a SubscriptionManager for each active event.

features: any

Cleanup functions for active features (hover/tap/exit etc)

initialValues: any

Create an object of the values we initially animated from (if initial prop present).

isControllingVariants: boolean
isVariantNode: boolean

Determine what role this visual element should take in the variant tree.

latestValues: ResolvedValues

An object containing the latest static values for each of this VisualElement's MotionValues.

manuallyAnimateOnMount: boolean

Normally, if a component is controlled by a parent's variants, it can rely on that ancestor to trigger animations further down the tree. However, if a component is created after its parent is mounted, the parent won't trigger that mount animation so the child needs to.

TODO: This might be better replaced with a method isParentMounted

notifyUpdate: (() => void)

Type declaration

    • (): void
    • Returns void

options: any

The options used to create this VisualElement. The Options type is defined by the inheriting VisualElement and is passed straight through to the render functions.

parent: undefined | VisualElement<unknown, unknown, {}>

A reference to the parent VisualElement (if exists).

presenceContext: null | PresenceContextProps
prevMotionValues: any

A reference to the previously-provided motion values as returned from scrapeMotionValuesFromProps. We use the keys in here to determine if any motion values need to be removed after props are updated.

prevPresenceContext?: null | PresenceContextProps
prevProps?: MotionProps
projection?: IProjectionNode<unknown>

A reference to this VisualElement's projection node, used in layout animations.

propEventSubscriptions: any

An object containing an unsubscribe function for each prop event subscription. For example, every "Update" event can have multiple subscribers via VisualElement.on(), but only one of those can be defined via the onUpdate prop.

A reference to the latest props provided to the VisualElement's host React component.

reducedMotionConfig: any

A reference to the ReducedMotionConfig passed to the VisualElement's host React component.

removeFromVariantTree: any

On mount, this will be hydrated with a callback to disconnect this visual element from its parent on unmount.

render: (() => void)

Type declaration

    • (): void
    • Returns void

renderState: RenderState

The current render state of this VisualElement. Defined by inherting VisualElements.

scheduleRender: (() => Process)

Type declaration

    • (): Process
    • Returns Process

shouldReduceMotion: null | boolean

Decides whether this VisualElement should animate in reduced motion mode.

TODO: This is currently set on every individual VisualElement but feels like it could be set globally.

type: string

VisualElements are arranged in trees mirroring that of the React tree. Each type of VisualElement has a unique name, to detect when we're crossing type boundaries within that tree.

valueSubscriptions: any

A map of every subscription that binds the provided or generated motion values onChange listeners to this visual element.

values: Map<string, MotionValue<any>>

A map of all motion values attached to this visual element. Motion values are source of truth for any given animated value. A motion value might be provided externally by the component via props.

variantChildren?: Set<VisualElement<unknown, unknown, {}>>

If this component is part of the variant tree, it should track any children that are also part of the tree. This is essentially a shadow tree to simplify logic around how to stagger over children.

Methods

  • Add a motion value and bind it to this visual element.

    Parameters

    Returns void

  • Add a child visual element to our set of children.

    Parameters

    Returns undefined | (() => boolean)

  • Run before a React or VisualElement render, builds the latest motion values into an Instance-specific format. For example, HTMLVisualElement will use this step to build style and var values.

    Parameters

    Returns void

  • Find the base target for a value thats been removed from all animation props.

    Parameters

    • key: string

    Returns any

  • When a value has been removed from all animation props we need to pick a target to animate back to. For instance, for HTMLElements we can look in the style prop.

    Parameters

    Returns undefined | string | number | MotionValue<any>

  • Returns undefined | VisualElement<unknown, unknown, {}>

  • Returns the defined default transition on this component.

    Returns undefined | Transition

  • Returns MotionProps

  • Parameters

    • key: string

    Returns string | number

  • Returns any

  • Get a motion value for this key. If called with a default value, we'll create one if none exists.

    Parameters

    • key: string

    Returns undefined | MotionValue<any>

  • Parameters

    • key: string
    • defaultValue: string | number

    Returns MotionValue<any>

  • Returns the variant definition with a given name.

    Parameters

    • name: string

    Returns undefined | Variant

  • Parameters

    • Optional startAtParent: boolean

    Returns undefined | VariantStateContext

  • If the component child is provided as a motion value, handle subscriptions with the renderer-specific VisualElement.

    Returns void

  • Check whether we have a motion value for this key

    Parameters

    • key: string

    Returns boolean

  • Parameters

    Returns undefined | ComponentType<MotionProps>

  • Make a target animatable by Popmotion. For instance, if we're trying to animate width from 100px to 100vw we need to measure 100vw in pixels to determine what we really need to animate to. This is also pluggable to support Framer's custom value types like Color, and CSS variables.

    Parameters

    Returns TargetAndTransition

  • Take a target and make it animatable. For instance if provided height: "auto" we need to measure height in pixels and animate that instead.

    Parameters

    Returns TargetAndTransition

  • Measure the viewport-relative bounding box of the Instance.

    Returns Framer.Box

  • Measure the current viewport box with or without transforms. Only measures axis-aligned boxes, rotate and skew must be manually removed with a re-render to work.

    Returns Framer.Box

  • Parameters

    Returns void

  • Type Parameters

    • EventName extends keyof VisualElementEventCallbacks

    Parameters

    Returns void

  • Type Parameters

    • EventName extends keyof VisualElementEventCallbacks

    Parameters

    Returns VoidFunction

  • If we're trying to animate to a previously unencountered value, we need to check for it in our state and as a last resort read it directly from the instance (which might have performance implications).

    Parameters

    • key: string

    Returns undefined | null | string | number | MotionValue<any>

  • When we first animate to a value we need to animate it from a value. Often this have been specified via the initial prop but it might be that the value needs to be read from the Instance.

    Parameters

    Returns undefined | null | string | number

  • Remove a motion value and unbind any active subscriptions.

    Parameters

    • key: string

    Returns void

  • When a value has been removed from the VisualElement we use this to remove it from the inherting class' unique render state.

    Parameters

    Returns void

  • Apply the built values to the Instance. For example, HTMLElements will have styles applied via setProperty and the style attribute, whereas SVGElements will have values applied to attributes.

    Parameters

    Returns void

  • This method takes React props and returns found MotionValues. For example, HTML MotionValues will be found within the style prop, whereas for Three.js within attribute arrays.

    This isn't an abstract method as it needs calling in the constructor, but it is intended to be one.

    Parameters

    Returns {
        [key: string]: MotionValue | string | number;
    }

  • Set the base target to later animate back to. This is currently only hydrated on creation and when we first read a value.

    Parameters

    • key: string
    • value: string | number

    Returns void

  • Parameters

    • key: string
    • value: string | number

    Returns void

  • An Array.sort compatible function that will compare two Instances and compare their respective positions within the tree.

    Parameters

    Returns number

  • Parameters

    Returns number

  • Returns void

  • Returns void

  • Update the provided props. Ensure any newly-added motion values are added to our map, old ones removed, and listeners updated.

    Parameters

    • props: MotionProps
    • presenceContext: null | PresenceContextProps

    Returns void

  • Returns void

Generated using TypeDoc