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 suport native animated support for Animated.add. Animated.add lets you declare node that outputs a sum of it input nodes. **Test Plan** Play with the following playground app: https://gist.github.com/39de37faf07480fcd7d1 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#6641 Differential Revision: D3195963 fb-gh-sync-id: bb1e1a36821a0e071ad0e7d0fa99ce0d6b088b0a fbshipit-source-id: bb1e1a36821a0e071ad0e7d0fa99ce0d6b088b0a
- Loading branch information
Showing
6 changed files
with
272 additions
and
2 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/AnimatedAddition.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 that plays a role of value aggregator. It takes two or more value nodes as an input | ||
* and outputs a sum of values outputted by those nodes. | ||
*/ | ||
/*package*/ class AdditionAnimatedNode extends ValueAnimatedNode { | ||
|
||
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager; | ||
private final int[] mInputNodes; | ||
|
||
public AdditionAnimatedNode( | ||
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 = 0; | ||
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.Add 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
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