mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-04 22:56:32 +08:00
Add extractOffset to Animated
Summary: `flattenOffset` has proven extremely useful, especially when dealing with pan responders and other gesture based animations, but I've also found a number of use cases for the inverse. This diff introduces `extractOffset`, which sets the offset value to the base value, and resets the base value to zero. A common use case would be to extractOffset onGrant and flattenOffset onRelease. Closes https://github.com/facebook/react-native/pull/10721 Differential Revision: D4145744 fbshipit-source-id: dc2aa31652df0b31450556f611db43548180c7dd
This commit is contained in:
committed by
Facebook Github Bot
parent
bf2b435322
commit
6535858c71
@@ -262,6 +262,16 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
});
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void extractAnimatedNodeOffset(final int tag) {
|
||||
mOperations.add(new UIThreadOperation() {
|
||||
@Override
|
||||
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
|
||||
animatedNodesManager.extractAnimatedNodeOffset(tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void startAnimatingNode(
|
||||
final int animationId,
|
||||
|
||||
@@ -157,6 +157,15 @@ import javax.annotation.Nullable;
|
||||
((ValueAnimatedNode) node).flattenOffset();
|
||||
}
|
||||
|
||||
public void extractAnimatedNodeOffset(int tag) {
|
||||
AnimatedNode node = mAnimatedNodes.get(tag);
|
||||
if (node == null || !(node instanceof ValueAnimatedNode)) {
|
||||
throw new JSApplicationIllegalArgumentException("Animated node with tag " + tag +
|
||||
" does not exists or is not a 'value' node");
|
||||
}
|
||||
((ValueAnimatedNode) node).extractOffset();
|
||||
}
|
||||
|
||||
public void startAnimatingNode(
|
||||
int animationId,
|
||||
int animatedNodeTag,
|
||||
|
||||
@@ -40,6 +40,11 @@ import javax.annotation.Nullable;
|
||||
mOffset = 0;
|
||||
}
|
||||
|
||||
public void extractOffset() {
|
||||
mOffset += mValue;
|
||||
mValue = 0;
|
||||
}
|
||||
|
||||
public void onValueUpdate() {
|
||||
if (mValueListener == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user