mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-19 09:01:46 +08:00
Add Animated.ValueXY.extractOffset
Summary:
The `extractOffset` method is previously implemented on `Animated.Value`, along with `setOffset` and `flattenOffset`. Both of the latter methods are proxied on `Animated.ValueXY`, but `extractOffset` is not. This commit adds the missing method.
When creating draggable elements in XY space, in order to compensate for previous gestures' offsets, we currently need to do something like the following at the beginning or end of each gesture:
```
xy.setOffset(xy.__getValue());
xy.setValue({x: 0, y: 0});
```
After this commit, the API is equivalent to using a plain `Animated.Value`:
```
xy.extractOffset();
```
Closes https://github.com/facebook/react-native/pull/12193
Differential Revision: D4508717
Pulled By: mkonicek
fbshipit-source-id: 0976cf1ab68538e59023ffaa2539eb62779ad874
This commit is contained in:
committed by
Facebook Github Bot
parent
5c84caaa86
commit
e93d496f6d
@@ -999,6 +999,11 @@ class AnimatedValueXY extends AnimatedWithChildren {
|
||||
this.y.flattenOffset();
|
||||
}
|
||||
|
||||
extractOffset(): void {
|
||||
this.x.extractOffset();
|
||||
this.y.extractOffset();
|
||||
}
|
||||
|
||||
__getValue(): {x: number, y: number} {
|
||||
return {
|
||||
x: this.x.__getValue(),
|
||||
|
||||
Reference in New Issue
Block a user