mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 09:30:10 +08:00
loosen the ReactChoreographer UI thread assert
Reviewed By: achen1 Differential Revision: D4873553 fbshipit-source-id: 7dbf771e744f6b33e6edb3ad4c227c3a63c3e3e3
This commit is contained in:
committed by
Facebook Github Bot
parent
c9826ba4a9
commit
b9b03435c4
@@ -61,6 +61,7 @@ import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
||||
import com.facebook.react.modules.appregistry.AppRegistry;
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.UIImplementationProvider;
|
||||
@@ -348,6 +349,9 @@ public class ReactInstanceManager {
|
||||
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
|
||||
mLazyViewManagersEnabled = lazyViewManagersEnabled;
|
||||
mUseStartupThread = useStartupThread;
|
||||
|
||||
// Instantiate ReactChoreographer in UI thread.
|
||||
ReactChoreographer.initialize();
|
||||
}
|
||||
|
||||
public DevSupportManager getDevSupportManager() {
|
||||
|
||||
@@ -12,8 +12,8 @@ package com.facebook.react.modules.core;
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
|
||||
/**
|
||||
@@ -65,11 +65,15 @@ public class ReactChoreographer {
|
||||
|
||||
private static ReactChoreographer sInstance;
|
||||
|
||||
public static ReactChoreographer getInstance() {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
public static void initialize() {
|
||||
if (sInstance == null) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
sInstance = new ReactChoreographer();
|
||||
}
|
||||
}
|
||||
|
||||
public static ReactChoreographer getInstance() {
|
||||
Assertions.assertNotNull(sInstance, "ReactChoreographer needs to be initialized.");
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@@ -89,8 +93,9 @@ public class ReactChoreographer {
|
||||
}
|
||||
}
|
||||
|
||||
public void postFrameCallback(CallbackType type, ChoreographerCompat.FrameCallback frameCallback) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
public synchronized void postFrameCallback(
|
||||
CallbackType type,
|
||||
ChoreographerCompat.FrameCallback frameCallback) {
|
||||
mCallbackQueues[type.getOrder()].addLast(frameCallback);
|
||||
mTotalCallbacks++;
|
||||
Assertions.assertCondition(mTotalCallbacks > 0);
|
||||
@@ -100,8 +105,9 @@ public class ReactChoreographer {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFrameCallback(CallbackType type, ChoreographerCompat.FrameCallback frameCallback) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
public synchronized void removeFrameCallback(
|
||||
CallbackType type,
|
||||
ChoreographerCompat.FrameCallback frameCallback) {
|
||||
if (mCallbackQueues[type.getOrder()].removeFirstOccurrence(frameCallback)) {
|
||||
mTotalCallbacks--;
|
||||
maybeRemoveFrameCallback();
|
||||
@@ -122,15 +128,17 @@ public class ReactChoreographer {
|
||||
|
||||
@Override
|
||||
public void doFrame(long frameTimeNanos) {
|
||||
mHasPostedCallback = false;
|
||||
for (int i = 0; i < mCallbackQueues.length; i++) {
|
||||
int initialLength = mCallbackQueues[i].size();
|
||||
for (int callback = 0; callback < initialLength; callback++) {
|
||||
mCallbackQueues[i].removeFirst().doFrame(frameTimeNanos);
|
||||
mTotalCallbacks--;
|
||||
synchronized (ReactChoreographer.this) {
|
||||
mHasPostedCallback = false;
|
||||
for (int i = 0; i < mCallbackQueues.length; i++) {
|
||||
int initialLength = mCallbackQueues[i].size();
|
||||
for (int callback = 0; callback < initialLength; callback++) {
|
||||
mCallbackQueues[i].removeFirst().doFrame(frameTimeNanos);
|
||||
mTotalCallbacks--;
|
||||
}
|
||||
}
|
||||
maybeRemoveFrameCallback();
|
||||
}
|
||||
maybeRemoveFrameCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user