mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 22:40:55 +08:00
Support for Animated.multiply node
Summary:This change adds native animated support for Animated.multiply nodes. Animated.multiply allows for defining nodes that would output a product of values of the input nodes. **Test Plan** Run JS tests: `npm test Libraries/Animated/src/__tests__/AnimatedNative-test.js` Run java tests: `buck test ReactAndroid/src/test/java/com/facebook/react/animated` Closes https://github.com/facebook/react-native/pull/7071 Differential Revision: D3197663 fb-gh-sync-id: 35f64244a2482c487a81e5e7cd08f3c0e56d9b78 fbshipit-source-id: 35f64244a2482c487a81e5e7cd08f3c0e56d9b78
This commit is contained in:
committed by
Facebook Github Bot 0
parent
3e2a3ca466
commit
ec5dfbf8c7
@@ -0,0 +1,40 @@
|
||||
package com.facebook.react.animated;
|
||||
|
||||
import com.facebook.react.bridge.JSApplicationCausedNativeException;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
||||
/**
|
||||
* Animated node which takes two or more value node as an input and outputs a product of their
|
||||
* values
|
||||
*/
|
||||
/*package*/ class MultiplicationAnimatedNode extends ValueAnimatedNode {
|
||||
|
||||
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager;
|
||||
private final int[] mInputNodes;
|
||||
|
||||
public MultiplicationAnimatedNode(
|
||||
ReadableMap config,
|
||||
NativeAnimatedNodesManager nativeAnimatedNodesManager) {
|
||||
mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
|
||||
ReadableArray inputNodes = config.getArray("input");
|
||||
mInputNodes = new int[inputNodes.size()];
|
||||
for (int i = 0; i < mInputNodes.length; i++) {
|
||||
mInputNodes[i] = inputNodes.getInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
mValue = 1;
|
||||
for (int i = 0; i < mInputNodes.length; i++) {
|
||||
AnimatedNode animatedNode = mNativeAnimatedNodesManager.getNodeById(mInputNodes[i]);
|
||||
if (animatedNode != null && animatedNode instanceof ValueAnimatedNode) {
|
||||
mValue *= ((ValueAnimatedNode) animatedNode).mValue;
|
||||
} else {
|
||||
throw new JSApplicationCausedNativeException("Illegal node ID set as an input for " +
|
||||
"Animated.multiply node");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,8 @@ import javax.annotation.Nullable;
|
||||
node = new PropsAnimatedNode(config, this);
|
||||
} else if ("addition".equals(type)) {
|
||||
node = new AdditionAnimatedNode(config, this);
|
||||
} else if ("multiplication".equals(type)) {
|
||||
node = new MultiplicationAnimatedNode(config, this);
|
||||
} else {
|
||||
throw new JSApplicationIllegalArgumentException("Unsupported node type: " + type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user