clean up NativeAnimatedModule
Reviewed By: achen1 Differential Revision: D4883111 fbshipit-source-id: 63873d46db8d2736672a6d102e86dabfbf4f4610
This commit is contained in:
parent
346fe33077
commit
1c440dbcae
|
@ -13,7 +13,6 @@ import javax.annotation.Nullable;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
|
@ -82,33 +81,25 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
|||
}
|
||||
|
||||
private final Object mOperationsCopyLock = new Object();
|
||||
private @Nullable GuardedFrameCallback mAnimatedFrameCallback;
|
||||
private @Nullable ReactChoreographer mReactChoreographer;
|
||||
private final GuardedFrameCallback mAnimatedFrameCallback;
|
||||
private final ReactChoreographer mReactChoreographer;
|
||||
private ArrayList<UIThreadOperation> mOperations = new ArrayList<>();
|
||||
private volatile @Nullable ArrayList<UIThreadOperation> mReadyOperations = null;
|
||||
|
||||
private @Nullable NativeAnimatedNodesManager mNodesManager;
|
||||
|
||||
public NativeAnimatedModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
getReactApplicationContext().addLifecycleEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
if (mReactChoreographer == null) {
|
||||
// Safe to acquire choreographer here, as onHostResume() is invoked from UI thread.
|
||||
mReactChoreographer = ReactChoreographer.getInstance();
|
||||
|
||||
ReactApplicationContext reactCtx = getReactApplicationContext();
|
||||
UIManagerModule uiManager = reactCtx.getNativeModule(UIManagerModule.class);
|
||||
|
||||
final NativeAnimatedNodesManager nodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
mAnimatedFrameCallback = new GuardedFrameCallback(reactCtx) {
|
||||
mAnimatedFrameCallback = new GuardedFrameCallback(reactContext) {
|
||||
@Override
|
||||
protected void doFrameGuarded(final long frameTimeNanos) {
|
||||
if (mNodesManager == null) {
|
||||
UIManagerModule uiManager = getReactApplicationContext()
|
||||
.getNativeModule(UIManagerModule.class);
|
||||
mNodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
}
|
||||
|
||||
ArrayList<UIThreadOperation> operations;
|
||||
synchronized (mOperationsCopyLock) {
|
||||
|
@ -118,12 +109,12 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
|||
|
||||
if (operations != null) {
|
||||
for (int i = 0, size = operations.size(); i < size; i++) {
|
||||
operations.get(i).execute(nodesManager);
|
||||
operations.get(i).execute(mNodesManager);
|
||||
}
|
||||
}
|
||||
|
||||
if (nodesManager.hasActiveAnimations()) {
|
||||
nodesManager.runUpdates(frameTimeNanos);
|
||||
if (mNodesManager.hasActiveAnimations()) {
|
||||
mNodesManager.runUpdates(frameTimeNanos);
|
||||
}
|
||||
|
||||
// TODO: Would be great to avoid adding this callback in case there are no active animations
|
||||
|
@ -136,6 +127,14 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
getReactApplicationContext().addLifecycleEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
enqueueFrameCallback();
|
||||
}
|
||||
|
||||
|
@ -162,10 +161,6 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
|
|||
|
||||
@Override
|
||||
public void onHostPause() {
|
||||
if (mReactChoreographer == null) {
|
||||
FLog.e(NAME, "Called NativeAnimated.onHostPause() with a null ReactChoreographer.");
|
||||
return;
|
||||
}
|
||||
clearFrameCallback();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue