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:
Jani Eväkallio 2017-02-03 12:05:45 -08:00 committed by Facebook Github Bot
parent 5c84caaa86
commit e93d496f6d
1 changed files with 5 additions and 0 deletions

View File

@ -999,6 +999,11 @@ class AnimatedValueXY extends AnimatedWithChildren {
this.y.flattenOffset(); this.y.flattenOffset();
} }
extractOffset(): void {
this.x.extractOffset();
this.y.extractOffset();
}
__getValue(): {x: number, y: number} { __getValue(): {x: number, y: number} {
return { return {
x: this.x.__getValue(), x: this.x.__getValue(),