mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-10 18:05:26 +08:00
Java unit tests for native animated module.
Summary:This change adds some basic unit tests for native animated traversal algorithm. The following tests are added: 1) Build simple animated nodes graph, verify that frame-based animation execute updates and when it runs out of the frames we no longer schedule updates for the native view 2) Build simple animated nodes graph and start short timing animation, verify that animation JS callback gets called. As a part of this change I'm fixing an issue that tests allowed me to discover, where I forgot to clear updates queue at the end of `runUpdates` method. It was causing the view to be updated even if there was no active animation for it (actually it was mitigated by another bug in `hasActiveAnimations` I'm fixing here too). I'm also adding Nullable annotation in a bunch of places. To lazy to send it as a separate change - sorry. Going forward I'm planning on adding more tests. Currently the number of nodes is pretty limited so it's difficult to construct more complex graphs, but once I land Add/Multiply Closes https://github.com/facebook/react-native/pull/6858 Differential Revision: D3168549 Pulled By: astreet fb-gh-sync-id: 5295c75f3c7817775b5154bb808888650ff74e12 fbshipit-source-id: 5295c75f3c7817775b5154bb808888650ff74e12
This commit is contained in:
committed by
Facebook Github Bot 4
parent
cbd72ad06c
commit
21b3180a4c
24
ReactAndroid/src/main/java/com/facebook/react/animated/BUCK
Normal file
24
ReactAndroid/src/main/java/com/facebook/react/animated/BUCK
Normal file
@@ -0,0 +1,24 @@
|
||||
include_defs('//ReactAndroid/DEFS')
|
||||
|
||||
android_library(
|
||||
name = 'animated',
|
||||
srcs = glob([
|
||||
'*.java',
|
||||
]),
|
||||
deps = [
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
react_native_target('java/com/facebook/react/uimanager:uimanager'),
|
||||
|
||||
react_native_target('java/com/facebook/react/uimanager/annotations:annotations'),
|
||||
react_native_dep('third-party/java/infer-annotations:infer-annotations'),
|
||||
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
||||
react_native_dep('third-party/android/support/v4:lib-support-v4'),
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
)
|
||||
|
||||
project_config(
|
||||
src_target = ':animated',
|
||||
)
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
package com.facebook.react.animated;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
@@ -20,7 +20,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.GuardedChoreographerFrameCallback;
|
||||
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||
import com.facebook.react.uimanager.ReactChoreographer;
|
||||
import com.facebook.react.uimanager.UIImplementation;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
|
||||
@@ -17,13 +17,14 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||
import com.facebook.react.uimanager.UIImplementation;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Queue;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This is the main class that coordinates how native animated JS implementation drives UI changes.
|
||||
*
|
||||
@@ -49,12 +50,12 @@ import java.util.Queue;
|
||||
mUIImplementation = uiImplementation;
|
||||
}
|
||||
|
||||
/*package*/ AnimatedNode getNodeById(int id) {
|
||||
/*package*/ @Nullable AnimatedNode getNodeById(int id) {
|
||||
return mAnimatedNodes.get(id);
|
||||
}
|
||||
|
||||
public boolean hasActiveAnimations() {
|
||||
return !mActiveAnimations.isEmpty();
|
||||
return !mActiveAnimations.isEmpty() || !mUpdatedNodes.isEmpty();
|
||||
}
|
||||
|
||||
public void createAnimatedNode(int tag, ReadableMap config) {
|
||||
@@ -315,6 +316,8 @@ import java.util.Queue;
|
||||
+ activeNodesCount + " but toposort visited only " + updatedNodesCount);
|
||||
}
|
||||
|
||||
// Clean mUpdatedNodes queue
|
||||
mUpdatedNodes.clear();
|
||||
|
||||
// Cleanup finished animations. Iterate over the array of animations and override ones that has
|
||||
// finished, then resize `mActiveAnimations`.
|
||||
|
||||
@@ -20,6 +20,8 @@ import com.facebook.react.uimanager.UIManagerModule;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Animated node that represents view properties. There is a special handling logic implemented for
|
||||
* the nodes of this type in {@link NativeAnimatedNodesManager} that is responsible for extracting
|
||||
@@ -50,7 +52,7 @@ import java.util.Map;
|
||||
}
|
||||
JavaOnlyMap propsMap = new JavaOnlyMap();
|
||||
for (Map.Entry<String, Integer> entry : mPropMapping.entrySet()) {
|
||||
AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(entry.getValue());
|
||||
@Nullable AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(entry.getValue());
|
||||
if (node == null) {
|
||||
throw new IllegalArgumentException("Mapped property node does not exists");
|
||||
} else if (node instanceof StyleAnimatedNode) {
|
||||
|
||||
@@ -16,6 +16,8 @@ import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Native counterpart of style animated node (see AnimatedStyle class in AnimatedImplementation.js)
|
||||
*/
|
||||
@@ -38,7 +40,7 @@ import java.util.Map;
|
||||
|
||||
public void collectViewUpdates(JavaOnlyMap propsMap) {
|
||||
for (Map.Entry<String, Integer> entry : mPropMapping.entrySet()) {
|
||||
AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(entry.getValue());
|
||||
@Nullable AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(entry.getValue());
|
||||
if (node == null) {
|
||||
throw new IllegalArgumentException("Mapped style node does not exists");
|
||||
} else if (node instanceof ValueAnimatedNode) {
|
||||
|
||||
Reference in New Issue
Block a user