mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-10 10:00:16 +08:00
Revert D5556439: [react-native][PR] Native Animated - Restore default values when removing props on Android
Differential Revision: D5556439 fbshipit-source-id: dc0e4c1db25ec7f3631e6f684f9497962f2adc7b
This commit is contained in:
committed by
Facebook Github Bot
parent
aa9a40f68f
commit
259eac8c30
@@ -17,20 +17,17 @@ import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.LifecycleEventListener;
|
||||
import com.facebook.react.bridge.OnBatchCompleteListener;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.uimanager.GuardedFrameCallback;
|
||||
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||
import com.facebook.react.uimanager.UIBlock;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.UIManagerModuleListener;
|
||||
|
||||
/**
|
||||
* Module that exposes interface for creating and managing animated nodes on the "native" side.
|
||||
@@ -75,7 +72,7 @@ import com.facebook.react.uimanager.UIManagerModuleListener;
|
||||
*/
|
||||
@ReactModule(name = NativeAnimatedModule.NAME)
|
||||
public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
LifecycleEventListener, UIManagerModuleListener {
|
||||
OnBatchCompleteListener, LifecycleEventListener {
|
||||
|
||||
protected static final String NAME = "NativeAnimatedModule";
|
||||
|
||||
@@ -83,10 +80,11 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
void execute(NativeAnimatedNodesManager animatedNodesManager);
|
||||
}
|
||||
|
||||
private final Object mOperationsCopyLock = new Object();
|
||||
private final GuardedFrameCallback mAnimatedFrameCallback;
|
||||
private final ReactChoreographer mReactChoreographer;
|
||||
private ArrayList<UIThreadOperation> mOperations = new ArrayList<>();
|
||||
private ArrayList<UIThreadOperation> mPreOperations = new ArrayList<>();
|
||||
private volatile @Nullable ArrayList<UIThreadOperation> mReadyOperations = null;
|
||||
|
||||
private @Nullable NativeAnimatedNodesManager mNodesManager;
|
||||
|
||||
@@ -97,9 +95,26 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
mAnimatedFrameCallback = new GuardedFrameCallback(reactContext) {
|
||||
@Override
|
||||
protected void doFrameGuarded(final long frameTimeNanos) {
|
||||
NativeAnimatedNodesManager nodesManager = getNodesManager();
|
||||
if (nodesManager.hasActiveAnimations()) {
|
||||
nodesManager.runUpdates(frameTimeNanos);
|
||||
if (mNodesManager == null) {
|
||||
UIManagerModule uiManager = getReactApplicationContext()
|
||||
.getNativeModule(UIManagerModule.class);
|
||||
mNodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
}
|
||||
|
||||
ArrayList<UIThreadOperation> operations;
|
||||
synchronized (mOperationsCopyLock) {
|
||||
operations = mReadyOperations;
|
||||
mReadyOperations = null;
|
||||
}
|
||||
|
||||
if (operations != null) {
|
||||
for (int i = 0, size = operations.size(); i < size; i++) {
|
||||
operations.get(i).execute(mNodesManager);
|
||||
}
|
||||
}
|
||||
|
||||
if (mNodesManager.hasActiveAnimations()) {
|
||||
mNodesManager.runUpdates(frameTimeNanos);
|
||||
}
|
||||
|
||||
// TODO: Would be great to avoid adding this callback in case there are no active animations
|
||||
@@ -115,10 +130,7 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
ReactApplicationContext reactCtx = getReactApplicationContext();
|
||||
UIManagerModule uiManager = reactCtx.getNativeModule(UIManagerModule.class);
|
||||
reactCtx.addLifecycleEventListener(this);
|
||||
uiManager.addUIManagerListener(this);
|
||||
getReactApplicationContext().addLifecycleEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,32 +139,24 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void willDispatchViewUpdates(final UIManagerModule uiManager) {
|
||||
if (mOperations.isEmpty() && mPreOperations.isEmpty()) {
|
||||
return;
|
||||
public void onBatchComplete() {
|
||||
// Note: The order of executing onBatchComplete handler (especially in terms of onBatchComplete
|
||||
// from the UIManagerModule) doesn't matter as we only enqueue operations for the UI thread to
|
||||
// be executed from here. Thanks to ReactChoreographer all the operations from here are going
|
||||
// to be executed *after* all the operations enqueued by UIManager as the callback type that we
|
||||
// use for ReactChoreographer (CallbackType.NATIVE_ANIMATED_MODULE) is run after callbacks that
|
||||
// UIManager uses.
|
||||
ArrayList<UIThreadOperation> operations = mOperations.isEmpty() ? null : mOperations;
|
||||
if (operations != null) {
|
||||
mOperations = new ArrayList<>();
|
||||
synchronized (mOperationsCopyLock) {
|
||||
if (mReadyOperations == null) {
|
||||
mReadyOperations = operations;
|
||||
} else {
|
||||
mReadyOperations.addAll(operations);
|
||||
}
|
||||
}
|
||||
}
|
||||
final ArrayList<UIThreadOperation> preOperations = mPreOperations;
|
||||
final ArrayList<UIThreadOperation> operations = mOperations;
|
||||
mPreOperations = new ArrayList<>();
|
||||
mOperations = new ArrayList<>();
|
||||
uiManager.prependUIBlock(new UIBlock() {
|
||||
@Override
|
||||
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
|
||||
NativeAnimatedNodesManager nodesManager = getNodesManager();
|
||||
for (UIThreadOperation operation : preOperations) {
|
||||
operation.execute(nodesManager);
|
||||
}
|
||||
}
|
||||
});
|
||||
uiManager.addUIBlock(new UIBlock() {
|
||||
@Override
|
||||
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
|
||||
NativeAnimatedNodesManager nodesManager = getNodesManager();
|
||||
for (UIThreadOperation operation : operations) {
|
||||
operation.execute(nodesManager);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,15 +174,6 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
return NAME;
|
||||
}
|
||||
|
||||
private NativeAnimatedNodesManager getNodesManager() {
|
||||
if (mNodesManager == null) {
|
||||
UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class);
|
||||
mNodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
}
|
||||
|
||||
return mNodesManager;
|
||||
}
|
||||
|
||||
private void clearFrameCallback() {
|
||||
Assertions.assertNotNull(mReactChoreographer).removeFrameCallback(
|
||||
ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
|
||||
@@ -191,11 +186,6 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
mAnimatedFrameCallback);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setNodesManager(NativeAnimatedNodesManager nodesManager) {
|
||||
mNodesManager = nodesManager;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void createAnimatedNode(final int tag, final ReadableMap config) {
|
||||
mOperations.add(new UIThreadOperation() {
|
||||
@@ -346,12 +336,6 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
||||
|
||||
@ReactMethod
|
||||
public void disconnectAnimatedNodeFromView(final int animatedNodeTag, final int viewTag) {
|
||||
mPreOperations.add(new UIThreadOperation() {
|
||||
@Override
|
||||
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
|
||||
animatedNodesManager.restoreDefaultValues(animatedNodeTag, viewTag);
|
||||
}
|
||||
});
|
||||
mOperations.add(new UIThreadOperation() {
|
||||
@Override
|
||||
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
|
||||
|
||||
Reference in New Issue
Block a user