Skip to main content

Animated.ValueXY

2D Value for driving 2D animations, such as pan gestures. Almost identical API to normal Animated.Value, but multiplexed. Contains two regular Animated.Values under the hood.

Example​


Reference

Methods​

setValue()​

React TSX
setValue(value: {x: number; y: number});

Directly set the value. This will stop any animations running on the value and update all the bound properties.

Parameters:

NameTypeRequiredDescription
value{x: number; y: number}YesValue

setOffset()​

React TSX
setOffset(offset: {x: number; y: number});

Sets an offset that is applied on top of whatever value is set, whether via setValue, an animation, or Animated.event. Useful for compensating things like the start of a pan gesture.

Parameters:

NameTypeRequiredDescription
offset{x: number; y: number}YesOffset value

flattenOffset()​

React TSX
flattenOffset();

Merges the offset value into the base value and resets the offset to zero. The final output of the value is unchanged.


extractOffset()​

React TSX
extractOffset();

Sets the offset value to the base value, and resets the base value to zero. The final output of the value is unchanged.


addListener()​

React TSX
addListener(callback: (value: {x: number; y: number}) => void);

Adds an asynchronous listener to the value so you can observe updates from animations. This is useful because there is no way to synchronously read the value because it might be driven natively.

Returns a string that serves as an identifier for the listener.

Parameters: