Java Code Examples for com.facebook.systrace.Systrace#beginSection()

The following examples show how to use com.facebook.systrace.Systrace#beginSection() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: react-native-GPay   File: NativeModuleRegistry.java    License: MIT License 6 votes vote down vote up
void notifyJSInstanceInitialized() {
  mReactApplicationContext.assertOnNativeModulesQueueThread("From version React Native v0.44, " +
    "native modules are explicitly not initialized on the UI thread. See " +
    "https://github.com/facebook/react-native/wiki/Breaking-Changes#d4611211-reactnativeandroidbreaking-move-nativemodule-initialization-off-ui-thread---aaachiuuu " +
    " for more details.");
  ReactMarker.logMarker(ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_START);
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyJSInstanceInitialized");
  try {
    for (ModuleHolder module : mModules.values()) {
      module.markInitializable();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_END);
  }
}
 
Example 2
Source Project: react-native-GPay   File: ReactInstanceManager.java    License: MIT License 6 votes vote down vote up
/**
 * Uses configured {@link ReactPackage} instances to create all view managers.
 */
public List<ViewManager> getOrCreateViewManagers(
    ReactApplicationContext catalystApplicationContext) {
  ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
  try {
    if (mViewManagers == null) {
      synchronized (mPackages) {
        if (mViewManagers == null) {
          mViewManagers = new ArrayList<>();
          for (ReactPackage reactPackage : mPackages) {
            mViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
          }
          return mViewManagers;
        }
      }
    }
    return mViewManagers;
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_VIEW_MANAGERS_END);
  }
}
 
Example 3
Source Project: react-native-GPay   File: ReactInstanceManager.java    License: MIT License 6 votes vote down vote up
private void attachRootViewToInstance(
    final ReactRootView rootView) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.attachRootViewToInstance()");
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachRootViewToInstance");
  UIManager uiManagerModule = UIManagerHelper.getUIManager(mCurrentReactContext, rootView.getUIManagerType());
  final int rootTag = uiManagerModule.addRootView(rootView);
  rootView.setRootViewTag(rootTag);
  rootView.runApplication();
  Systrace.beginAsyncSection(
    TRACE_TAG_REACT_JAVA_BRIDGE,
    "pre_rootView.onAttachedToReactInstance",
    rootTag);
  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      Systrace.endAsyncSection(
        TRACE_TAG_REACT_JAVA_BRIDGE,
        "pre_rootView.onAttachedToReactInstance",
        rootTag);
      rootView.onAttachedToReactInstance();
    }
  });
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 4
Source Project: react-native-GPay   File: UIViewOperationQueue.java    License: MIT License 6 votes vote down vote up
@Override
public void doFrameGuarded(long frameTimeNanos) {
  if (mIsInIllegalUIState) {
    FLog.w(
      ReactConstants.TAG,
      "Not flushing pending UI operations because of previously thrown Exception");
    return;
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "dispatchNonBatchedUIOperations");
  try {
    dispatchPendingNonBatchedOperations(frameTimeNanos);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  flushPendingBatches();

  ReactChoreographer.getInstance().postFrameCallback(
    ReactChoreographer.CallbackType.DISPATCH_UI, this);
}
 
Example 5
Source Project: react-native-GPay   File: EventDispatcher.java    License: MIT License 6 votes vote down vote up
@Override
public void doFrame(long frameTimeNanos) {
  UiThreadUtil.assertOnUiThread();

  if (mShouldStop) {
    mIsPosted = false;
  } else {
    post();
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback");
  try {
    moveStagedEventsToDispatchQueue();

    if (!mHasDispatchScheduled) {
      mHasDispatchScheduled = true;
      Systrace.startAsyncFlow(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
          "ScheduleDispatchFrameCallback",
          mHasDispatchScheduledCount.get());
      mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 6
Source Project: react-native-GPay   File: JavaModuleWrapper.java    License: MIT License 5 votes vote down vote up
@DoNotStrip
private void findMethods() {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "findMethods");
  Set<String> methodNames = new HashSet<>();

  Class<? extends NativeModule> classForMethods = mModuleHolder.getModule().getClass();
  Class<? extends NativeModule> superClass =
      (Class<? extends NativeModule>) classForMethods.getSuperclass();
  if (ReactModuleWithSpec.class.isAssignableFrom(superClass)) {
    // For java module that is based on generated flow-type spec, inspect the
    // spec abstract class instead, which is the super class of the given java
    // module.
    classForMethods = superClass;
  }
  Method[] targetMethods = classForMethods.getDeclaredMethods();

  for (Method targetMethod : targetMethods) {
    ReactMethod annotation = targetMethod.getAnnotation(ReactMethod.class);
    if (annotation != null) {
      String methodName = targetMethod.getName();
      if (methodNames.contains(methodName)) {
        // We do not support method overloading since js sees a function as an object regardless
        // of number of params.
        throw new IllegalArgumentException(
          "Java Module " + getName() + " method name already registered: " + methodName);
      }
      MethodDescriptor md = new MethodDescriptor();
      JavaMethodWrapper method = new JavaMethodWrapper(this, targetMethod, annotation.isBlockingSynchronousMethod());
      md.name = methodName;
      md.type = method.getType();
      if (md.type == BaseJavaModule.METHOD_TYPE_SYNC) {
        md.signature = method.getSignature();
        md.method = targetMethod;
      }
      mMethods.add(method);
      mDescs.add(md);
    }
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 7
Source Project: react-native-GPay   File: JavaModuleWrapper.java    License: MIT License 5 votes vote down vote up
@DoNotStrip
public @Nullable NativeMap getConstants() {
  if (!mModuleHolder.getHasConstants()) {
    return null;
  }

  final String moduleName = getName();
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "JavaModuleWrapper.getConstants")
    .arg("moduleName", moduleName)
    .flush();
  ReactMarker.logMarker(GET_CONSTANTS_START, moduleName);

  BaseJavaModule baseJavaModule = getModule();

  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "module.getConstants");
  Map<String, Object> map = baseJavaModule.getConstants();
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);

  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "create WritableNativeMap");
  ReactMarker.logMarker(CONVERT_CONSTANTS_START, moduleName);
  try {
    return Arguments.makeNativeMap(map);
  } finally {
    ReactMarker.logMarker(CONVERT_CONSTANTS_END);
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);

    ReactMarker.logMarker(GET_CONSTANTS_END);
    SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
  }
}
 
Example 8
Source Project: react-native-GPay   File: NativeModuleRegistry.java    License: MIT License 5 votes vote down vote up
void notifyJSInstanceDestroy() {
  mReactApplicationContext.assertOnNativeModulesQueueThread();
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyJSInstanceDestroy");
  try {
    for (ModuleHolder module : mModules.values()) {
      module.destroy();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 9
Source Project: react-native-GPay   File: ReactRootView.java    License: MIT License 5 votes vote down vote up
/**
 * Schedule rendering of the react component rendered by the JS application from the given JS
 * module (@{param moduleName}) using provided {@param reactInstanceManager} to attach to the
 * JS context of that manager. Extra parameter {@param launchOptions} can be used to pass initial
 * properties for the react component.
 */
public void startReactApplication(
    ReactInstanceManager reactInstanceManager,
    String moduleName,
    @Nullable Bundle initialProperties) {
  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(
      mReactInstanceManager == null,
      "This root view has already been attached to a catalyst instance manager");

    mReactInstanceManager = reactInstanceManager;
    mJSModuleName = moduleName;
    mAppProperties = initialProperties;

    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
      mReactInstanceManager.createReactContextInBackground();
    }

    attachToReactInstanceManager();

  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 10
Source Project: react-native-GPay   File: ReactRootView.java    License: MIT License 5 votes vote down vote up
/**
 * Calls into JS to start the React application. Can be called multiple times with the
 * same rootTag, which will re-render the application from the root.
 */
/* package */ void runApplication() {
    Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.runApplication");
    try {
      if (mReactInstanceManager == null || !mIsAttachedToInstance) {
        return;
      }

      ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
      if (reactContext == null) {
        return;
      }

      CatalystInstance catalystInstance = reactContext.getCatalystInstance();

      WritableNativeMap appParams = new WritableNativeMap();
      appParams.putDouble("rootTag", getRootViewTag());
      @Nullable Bundle appProperties = getAppProperties();
      if (appProperties != null) {
        appParams.putMap("initialProps", Arguments.fromBundle(appProperties));
      }
      if (getUIManagerType() == FABRIC) {
        appParams.putBoolean("fabric", true);
      }

      mShouldLogContentAppeared = true;

      String jsAppModuleName = getJSModuleName();
      catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
    } finally {
      Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    }
}
 
Example 11
Source Project: react-native-GPay   File: ReactRootView.java    License: MIT License 5 votes vote down vote up
private void attachToReactInstanceManager() {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachToReactInstanceManager");
  try {
    if (mIsAttachedToInstance) {
      return;
    }

    mIsAttachedToInstance = true;
    Assertions.assertNotNull(mReactInstanceManager).attachRootView(this);
    getViewTreeObserver().addOnGlobalLayoutListener(getCustomGlobalLayoutListener());
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 12
Source Project: react-native-GPay   File: EventDispatcher.java    License: MIT License 5 votes vote down vote up
@Override
public void run() {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "DispatchEventsRunnable");
  try {
    Systrace.endAsyncFlow(
        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
        "ScheduleDispatchFrameCallback",
        mHasDispatchScheduledCount.getAndIncrement());
    mHasDispatchScheduled = false;
    Assertions.assertNotNull(mReactEventEmitter);
    synchronized (mEventsToDispatchLock) {
      if (mEventsToDispatchSize > 0) {
        // We avoid allocating an array and iterator, and "sorting" if we don't need to.
        // This occurs when the size of mEventsToDispatch is zero or one.
        if (mEventsToDispatchSize > 1) {
          Arrays.sort(mEventsToDispatch, 0, mEventsToDispatchSize, EVENT_COMPARATOR);
        }
        for (int eventIdx = 0; eventIdx < mEventsToDispatchSize; eventIdx++) {
          Event event = mEventsToDispatch[eventIdx];
          // Event can be null if it has been coalesced into another event.
          if (event == null) {
            continue;
          }
          Systrace.endAsyncFlow(
              Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, event.getEventName(), event.getUniqueID());
          event.dispatch(mReactEventEmitter);
          event.dispose();
        }
        clearEventsToDispatch();
        mEventCookieToLastEventIdx.clear();
      }
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 13
Source Project: react-native-GPay   File: UIManagerModule.java    License: MIT License 5 votes vote down vote up
private static Map<String, Object> createConstants(ViewManagerResolver viewManagerResolver) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
  try {
    return UIManagerModuleConstantsHelper.createConstants(viewManagerResolver);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
  }
}
 
Example 14
Source Project: react-native-GPay   File: UIManagerModule.java    License: MIT License 5 votes vote down vote up
private static Map<String, Object> createConstants(
    List<ViewManager> viewManagers,
    @Nullable Map<String, Object> customBubblingEvents,
    @Nullable Map<String, Object> customDirectEvents) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
  try {
    return UIManagerModuleConstantsHelper.createConstants(
        viewManagers, customBubblingEvents, customDirectEvents);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
  }
}
 
Example 15
Source Project: react-native-GPay   File: UIManagerModule.java    License: MIT License 5 votes vote down vote up
/**
 * Registers a new root view. JS can use the returned tag with manageChildren to add/remove
 * children to this view.
 *
 * <p>Note that this must be called after getWidth()/getHeight() actually return something. See
 * CatalystApplicationFragment as an example.
 *
 * <p>TODO(6242243): Make addRootView thread safe NB: this method is horribly not-thread-safe.
 */
@Override
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
    final T rootView) {
  Systrace.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "UIManagerModule.addRootView");
  final int tag = ReactRootViewTagGenerator.getNextRootViewTag();
  final ReactApplicationContext reactApplicationContext = getReactApplicationContext();
  final ThemedReactContext themedRootContext =
    new ThemedReactContext(reactApplicationContext, rootView.getContext());

  mUIImplementation.registerRootView(rootView, tag, themedRootContext);

  rootView.setOnSizeChangedListener(
    new SizeMonitoringFrameLayout.OnSizeChangedListener() {
      @Override
      public void onSizeChanged(final int width, final int height, int oldW, int oldH) {
        reactApplicationContext.runOnNativeModulesQueueThread(
          new GuardedRunnable(reactApplicationContext) {
            @Override
            public void runGuarded() {
              updateNodeSize(tag, width, height);
            }
          });
      }
    });

  Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  return tag;
}
 
Example 16
Source Project: react-native-GPay   File: CoreModulesPackage.java    License: MIT License 5 votes vote down vote up
private UIManagerModule createUIManager(final ReactApplicationContext reactContext) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
  try {
    if (mLazyViewManagersEnabled) {
      UIManagerModule.ViewManagerResolver resolver = new UIManagerModule.ViewManagerResolver() {
        @Override
        public @Nullable ViewManager getViewManager(String viewManagerName) {
          return mReactInstanceManager.createViewManager(viewManagerName);
        }
        @Override
        public List<String> getViewManagerNames() {
          return mReactInstanceManager.getViewManagerNames();
        }
      };

      return new UIManagerModule(
          reactContext,
          resolver,
          mMinTimeLeftInFrameForNonBatchedOperationMs);
    } else {
      return new UIManagerModule(
          reactContext,
          mReactInstanceManager.getOrCreateViewManagers(reactContext),
          mMinTimeLeftInFrameForNonBatchedOperationMs);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
  }
}
 
Example 17
Source Project: react-native-GPay   File: ReactInstanceManager.java    License: MIT License 4 votes vote down vote up
private void setupReactContext(final ReactApplicationContext reactContext) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.setupReactContext()");
  ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_END);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext");
  synchronized (mReactContextLock) {
    mCurrentReactContext = Assertions.assertNotNull(reactContext);
  }
  CatalystInstance catalystInstance =
    Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_START);
  synchronized (mAttachedRootViews) {
    for (ReactRootView rootView : mAttachedRootViews) {
      attachRootViewToInstance(rootView);
    }
  }
  ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_END);

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  final ReactInstanceEventListener[] finalListeners =
      mReactInstanceEventListeners.toArray(listeners);

  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          for (ReactInstanceEventListener listener : finalListeners) {
            listener.onReactContextInitialized(reactContext);
          }
        }
      });
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
  reactContext.runOnJSQueueThread(
      new Runnable() {
        @Override
        public void run() {
          Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
        }
      });
  reactContext.runOnNativeModulesQueueThread(
      new Runnable() {
        @Override
        public void run() {
          Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
        }
      });
}
 
Example 18
Source Project: react-native-GPay   File: ReactInstanceManager.java    License: MIT License 4 votes vote down vote up
/**
 * @return instance of {@link ReactContext} configured a {@link CatalystInstance} set
 */
private ReactApplicationContext createReactContext(
    JavaScriptExecutor jsExecutor,
    JSBundleLoader jsBundleLoader) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.createReactContext()");
  ReactMarker.logMarker(CREATE_REACT_CONTEXT_START, jsExecutor.getName());
  final ReactApplicationContext reactContext = new ReactApplicationContext(mApplicationContext);

  NativeModuleCallExceptionHandler exceptionHandler = mNativeModuleCallExceptionHandler != null
      ? mNativeModuleCallExceptionHandler
      : mDevSupportManager;
  reactContext.setNativeModuleCallExceptionHandler(exceptionHandler);

  NativeModuleRegistry nativeModuleRegistry = processPackages(reactContext, mPackages, false);

  CatalystInstanceImpl.Builder catalystInstanceBuilder = new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(jsExecutor)
    .setRegistry(nativeModuleRegistry)
    .setJSBundleLoader(jsBundleLoader)
    .setNativeModuleCallExceptionHandler(exceptionHandler);

  ReactMarker.logMarker(CREATE_CATALYST_INSTANCE_START);
  // CREATE_CATALYST_INSTANCE_END is in JSCExecutor.cpp
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createCatalystInstance");
  final CatalystInstance catalystInstance;
  try {
    catalystInstance = catalystInstanceBuilder.build();
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_CATALYST_INSTANCE_END);
  }
  if (mJSIModulePackage != null) {
    catalystInstance.addJSIModules(mJSIModulePackage
      .getJSIModules(reactContext, catalystInstance.getJavaScriptContextHolder()));
  }

  if (mBridgeIdleDebugListener != null) {
    catalystInstance.addBridgeIdleDebugListener(mBridgeIdleDebugListener);
  }
  if (Systrace.isTracing(TRACE_TAG_REACT_APPS | TRACE_TAG_REACT_JS_VM_CALLS)) {
    catalystInstance.setGlobalVariable("__RCTProfileIsProfiling", "true");
  }
  ReactMarker.logMarker(ReactMarkerConstants.PRE_RUN_JS_BUNDLE_START);
  catalystInstance.runJSBundle();
  reactContext.initializeWithInstance(catalystInstance);

  return reactContext;
}
 
Example 19
Source Project: react-native-GPay   File: ReactInstanceManager.java    License: MIT License 4 votes vote down vote up
private NativeModuleRegistry processPackages(
  ReactApplicationContext reactContext,
  List<ReactPackage> packages,
  boolean checkAndUpdatePackageMembership) {
  NativeModuleRegistryBuilder nativeModuleRegistryBuilder = new NativeModuleRegistryBuilder(
    reactContext,
    this);

  ReactMarker.logMarker(PROCESS_PACKAGES_START);

  // TODO(6818138): Solve use-case of native modules overriding
  synchronized (mPackages) {
    for (ReactPackage reactPackage : packages) {
      if (checkAndUpdatePackageMembership && mPackages.contains(reactPackage)) {
        continue;
      }
      Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAndProcessCustomReactPackage");
      try {
        if (checkAndUpdatePackageMembership) {
          mPackages.add(reactPackage);
        }
        processPackage(reactPackage, nativeModuleRegistryBuilder);
      } finally {
        Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
      }
    }
  }
  ReactMarker.logMarker(PROCESS_PACKAGES_END);

  ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry");
  NativeModuleRegistry nativeModuleRegistry;
  try {
    nativeModuleRegistry = nativeModuleRegistryBuilder.build();
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END);
  }

  return nativeModuleRegistry;
}
 
Example 20
Source Project: react-native-GPay   File: UIImplementation.java    License: MIT License 4 votes vote down vote up
protected void updateViewHierarchy() {
  Systrace.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "UIImplementation.updateViewHierarchy");
  try {
    for (int i = 0; i < mShadowNodeRegistry.getRootNodeCount(); i++) {
      int tag = mShadowNodeRegistry.getRootTag(i);
      ReactShadowNode cssRoot = mShadowNodeRegistry.getNode(tag);

      if (mMeasuredRootNodes.contains(tag)) {
        SystraceMessage.beginSection(
                Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
                "UIImplementation.notifyOnBeforeLayoutRecursive")
            .arg("rootTag", cssRoot.getReactTag())
            .flush();
        try {
          notifyOnBeforeLayoutRecursive(cssRoot);
        } finally {
          Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
        }

        calculateRootLayout(cssRoot);
        SystraceMessage.beginSection(
                Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIImplementation.applyUpdatesRecursive")
            .arg("rootTag", cssRoot.getReactTag())
            .flush();
        try {
          applyUpdatesRecursive(cssRoot, 0f, 0f);
        } finally {
          Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
        }

        if (mLayoutUpdateListener != null) {
          mLayoutUpdateListener.onLayoutUpdated(cssRoot);
        }
      }
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}