forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 facebook#7071 Differential Revision: D3197663 fb-gh-sync-id: 35f64244a2482c487a81e5e7cd08f3c0e56d9b78 fbshipit-source-id: 35f64244a2482c487a81e5e7cd08f3c0e56d9b78
- Loading branch information
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters