moveToResumedLifecycleState must be called from UI thread

Summary:
I was seeing a SoftException in our apps due to this method being called as part of ReactInstanceManager's init. It seems inconsistent that we would call this from a background thread when all other `onHost*` methods are marked as confined to the UI thread.

Changelog: [Internal]

Reviewed By: ryancat

Differential Revision: D34340210

fbshipit-source-id: 0104eda66b2ca6bb315e64e806e9a30409d0d45c
This commit is contained in:
Pieter De Baets 2022-02-18 11:01:00 -08:00 коммит произвёл Facebook GitHub Bot
Родитель bb7214b9c4
Коммит fc35a65a7e
2 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -1175,7 +1175,6 @@ public class ReactInstanceManager {
mDevSupportManager.onNewReactContextCreated(reactContext);
mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
moveReactContextToCurrentLifecycleState();
ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_START);
for (ReactRoot reactRoot : mAttachedReactRoots) {
@ -1197,6 +1196,8 @@ public class ReactInstanceManager {
new Runnable() {
@Override
public void run() {
moveReactContextToCurrentLifecycleState();
for (com.facebook.react.ReactInstanceEventListener listener : finalListeners) {
// Sometimes this listener is null - probably due to race
// condition between allocating listeners with a certain
@ -1208,10 +1209,6 @@ public class ReactInstanceManager {
}
}
});
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
// Mark end of bridge loading
ReactMarker.logMarker(ReactMarkerConstants.REACT_BRIDGE_LOADING_END);
reactContext.runOnJSQueueThread(
new Runnable() {
@Override
@ -1227,6 +1224,11 @@ public class ReactInstanceManager {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
// Mark end of bridge loading
ReactMarker.logMarker(ReactMarkerConstants.REACT_BRIDGE_LOADING_END);
}
private void attachRootViewToInstance(final ReactRoot reactRoot) {

Просмотреть файл

@ -254,6 +254,7 @@ public class ReactContext extends ContextWrapper {
}
/** Should be called by the hosting Fragment in {@link Fragment#onResume} */
@ThreadConfined(UI)
public void onHostResume(@Nullable Activity activity) {
mLifecycleState = LifecycleState.RESUMED;
mCurrentActivity = new WeakReference(activity);
@ -282,6 +283,7 @@ public class ReactContext extends ContextWrapper {
}
/** Should be called by the hosting Fragment in {@link Fragment#onPause} */
@ThreadConfined(UI)
public void onHostPause() {
mLifecycleState = LifecycleState.BEFORE_RESUME;
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_PAUSE_START);