Skip to content

Commit

Permalink
Add Animated.ValueXY.extractOffset
Browse files Browse the repository at this point in the history
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 facebook#12193

Differential Revision: D4508717

Pulled By: mkonicek

fbshipit-source-id: 0976cf1ab68538e59023ffaa2539eb62779ad874
  • Loading branch information
jevakallio authored and nicktate committed Feb 9, 2017
1 parent d8eb6d3 commit 41c9e9e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Libraries/Animated/src/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 41c9e9e

Please sign in to comment.