Animated.ValueXY
sunnylqm(100.00%)
本文档贡献者:2D Value for driving 2D animations, such as pan gestures. Almost identical API to normal Animated.Value
, but multiplexed. Contains two regular Animated.Value
s under the hood.
示例
文档
方法
setValue()
setValue(value);
Directly set the value. This will stop any animations running on the value and update all the bound properties.
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
value | number | 是 |
setOffset()
setOffset(offset);
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.
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
offset | number | 是 |
flattenOffset()
flattenOffset();
Merges the offset value into the base value and resets the offset to zero. The final output of the value is unchanged.
extractOffset()
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()
addListener(callback);
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.
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | function | 是 | The callback function which will receive an object with a value key set to the new value. |
removeListener()
removeListener(id);
Unregister a listener. The id
param shall match the identifier previously returned by addListener()
.
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
id | string | 是 | Id for the listener being removed. |
removeAllListeners()
removeAllListeners();
Remove all registered listeners.
stopAnimation()
stopAnimation([callback]);
Stops any running animation or tracking. callback
is invoked with the final value after stopping the animation, which is useful for updating state to match the animation position with layout.
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | function | 否 | A function that will receive the final value. |
resetAnimation()
resetAnimation([callback]);
Stops any animation and resets the value to its original.
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | function | 否 | A function that will receive the original value. |
getLayout()
getLayout();
Converts {x, y}
into {left, top}
for use in style, e.g.
style={this.state.anim.getLayout()}
getTranslateTransform()
getTranslateTransform();
Converts {x, y}
into a useable translation transform, e.g.
style={{
transform: this.state.anim.getTranslateTransform()
}}