diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 82fa4986a..1e492556e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -96,20 +96,25 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - setMeasuredDimension( + Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.onMeasure"); + try { + setMeasuredDimension( MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec)); - mWasMeasured = true; - // Check if we were waiting for onMeasure to attach the root view - if (mReactInstanceManager != null && !mIsAttachedToInstance) { - // Enqueue it to UIThread not to block onMeasure waiting for the catalyst instance creation - UiThreadUtil.runOnUiThread(new Runnable() { - @Override - public void run() { - attachToReactInstanceManager(); - } - }); + mWasMeasured = true; + // Check if we were waiting for onMeasure to attach the root view. + if (mReactInstanceManager != null && !mIsAttachedToInstance) { + // Enqueue it to UIThread not to block onMeasure waiting for the catalyst instance creation. + UiThreadUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + attachToReactInstanceManager(); + } + }); + } + } finally { + Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); } } @@ -204,27 +209,33 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView ReactInstanceManager reactInstanceManager, String moduleName, @Nullable Bundle initialProperties) { - UiThreadUtil.assertOnUiThread(); + Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "startReactApplication"); + try { + UiThreadUtil.assertOnUiThread(); - // TODO(6788889): Use POJO instead of bundle here, apparently we can't just use WritableMap - // here as it may be deallocated in native after passing via JNI bridge, but we want to reuse - // it in the case of re-creating the catalyst instance - Assertions.assertCondition( + // TODO(6788889): Use POJO instead of bundle here, apparently we can't just use WritableMap + // here as it may be deallocated in native after passing via JNI bridge, but we want to reuse + // it in the case of re-creating the catalyst instance + Assertions.assertCondition( mReactInstanceManager == null, "This root view has already been attached to a catalyst instance manager"); - mReactInstanceManager = reactInstanceManager; - mJSModuleName = moduleName; - mAppProperties = initialProperties; + mReactInstanceManager = reactInstanceManager; + mJSModuleName = moduleName; + mAppProperties = initialProperties; - if (!mReactInstanceManager.hasStartedCreatingInitialContext()) { - mReactInstanceManager.createReactContextInBackground(); - } + if (!mReactInstanceManager.hasStartedCreatingInitialContext()) { + mReactInstanceManager.createReactContextInBackground(); + } - // We need to wait for the initial onMeasure, if this view has not yet been measured, we set which - // will make this view startReactApplication itself to instance manager once onMeasure is called. - if (mWasMeasured) { - attachToReactInstanceManager(); + // We need to wait for the initial onMeasure, if this view has not yet been measured, we set + // which will make this view startReactApplication itself to instance manager once onMeasure + // is called. + if (mWasMeasured) { + attachToReactInstanceManager(); + } + } finally { + Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); } } @@ -315,13 +326,18 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView } private void attachToReactInstanceManager() { - if (mIsAttachedToInstance) { - return; - } + Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachToReactInstanceManager"); + try { + if (mIsAttachedToInstance) { + return; + } - mIsAttachedToInstance = true; - Assertions.assertNotNull(mReactInstanceManager).attachMeasuredRootView(this); - getViewTreeObserver().addOnGlobalLayoutListener(getCustomGlobalLayoutListener()); + mIsAttachedToInstance = true; + Assertions.assertNotNull(mReactInstanceManager).attachMeasuredRootView(this); + getViewTreeObserver().addOnGlobalLayoutListener(getCustomGlobalLayoutListener()); + } finally { + Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); + } } @Override