Java Code Examples for com.facebook.systrace.SystraceMessage

The following examples show how to use com.facebook.systrace.SystraceMessage. 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   Source File: JavaMethodWrapper.java    License: MIT License 6 votes vote down vote up
private void processArguments() {
  if (mArgumentsProcessed) {
    return;
  }
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "processArguments")
    .arg("method", mModuleWrapper.getName() + "." + mMethod.getName())
    .flush();
  try {
    mArgumentsProcessed = true;
    mArgumentExtractors = buildArgumentExtractors(mParameterTypes);
    mSignature = buildSignature(
        mMethod,
        mParameterTypes,
        (mType.equals(BaseJavaModule.METHOD_TYPE_SYNC)));
    // Since native methods are invoked from a message queue executed on a single thread, it is
    // safe to allocate only one arguments object per method that can be reused across calls
    mArguments = new Object[mParameterTypes.length];
    mJSArgumentsNeeded = calculateJSArgumentsNeeded();
  } finally {
    SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
  }
}
 
Example 2
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node,
 *     including its children set (note that the children nodes will not be cloned).
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNode(ReactShadowNode node) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNode \n\tnode: " + node);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNode")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopy(node.getInstanceHandle());
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 3
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     children set will be empty.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewChildren")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopyWithNewChildren(node.getInstanceHandle());
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 4
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     props will be overridden with the {@link ReadableMap} received by parameter.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewProps(
    ReactShadowNode node, @Nullable ReadableNativeMap newProps) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewProps")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopyWithNewProps(node.getInstanceHandle(),
          newProps == null ? null : new ReactStylesDiffMap(newProps));
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 5
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     props will be overridden with the {@link ReadableMap} received by parameter and its
 *     children set will be empty.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewChildrenAndProps(
    ReactShadowNode node, ReadableNativeMap newProps) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewChildrenAndProps")
    .flush();
  try {
    ReactShadowNode clone =
        node.mutableCopyWithNewChildrenAndProps(node.getInstanceHandle(),
            newProps == null ? null : new ReactStylesDiffMap(newProps));
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 6
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 6 votes vote down vote up
/**
 * Appends the child {@link ReactShadowNode} to the children set of the parent {@link
 * ReactShadowNode}.
 */
@Nullable
@DoNotStrip
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
  if (DEBUG) {
    FLog.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.appendChild")
    .flush();
  try {
    // If the child to append was already committed (child.isSealed()),
    // then we add a mutation of it. In the future this will be performed by FabricJS / Fiber.
    //TODO: T27926878 avoid cloning shared child
    if (child.isSealed()) {
      child = child.mutableCopy(child.getInstanceHandle());
    }
    parent.addChildAt(child, parent.getChildCount());
  } catch (Throwable t) {
    handleException(parent, t);
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 7
Source Project: react-native-GPay   Source File: LazyReactPackage.java    License: MIT License 6 votes vote down vote up
@Override
public final List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();
  for (ModuleSpec holder : getNativeModules(reactContext)) {
    NativeModule nativeModule;
    SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule")
      .arg("module", holder.getType())
      .flush();
    ReactMarker.logMarker(
      ReactMarkerConstants.CREATE_MODULE_START,
      holder.getClassName());
    try {
      nativeModule = holder.getProvider().get();
    } finally {
      ReactMarker.logMarker(ReactMarkerConstants.CREATE_MODULE_END);
      SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
    }
    modules.add(nativeModule);
  }
  return modules;
}
 
Example 8
Source Project: react-native-GPay   Source File: ReactInstanceManager.java    License: MIT License 6 votes vote down vote up
private void processPackage(
  ReactPackage reactPackage,
  NativeModuleRegistryBuilder nativeModuleRegistryBuilder) {
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "processPackage")
    .arg("className", reactPackage.getClass().getSimpleName())
    .flush();
  if (reactPackage instanceof ReactPackageLogger) {
    ((ReactPackageLogger) reactPackage).startProcessPackage();
  }
  nativeModuleRegistryBuilder.processPackage(reactPackage);

  if (reactPackage instanceof ReactPackageLogger) {
    ((ReactPackageLogger) reactPackage).endProcessPackage();
  }
  SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
}
 
Example 9
Source Project: react-native-GPay   Source File: UIImplementation.java    License: MIT License 6 votes vote down vote up
/**
 * Invoked at the end of the transaction to commit any updates to the node hierarchy.
 */
public void dispatchViewUpdates(int batchId) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "UIImplementation.dispatchViewUpdates")
    .arg("batchId", batchId)
    .flush();
  final long commitStartTime = SystemClock.uptimeMillis();
  try {
    updateViewHierarchy();
    mNativeViewHierarchyOptimizer.onBatchComplete();
    mOperationsQueue.dispatchViewUpdates(batchId, commitStartTime, mLastCalculateLayoutTime);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 10
Source Project: react-native-GPay   Source File: UIManagerModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod(isBlockingSynchronousMethod = true)
public @Nullable WritableMap getConstantsForViewManager(final String viewManagerName) {
  ViewManager targetView =
      viewManagerName != null ? mUIImplementation.resolveViewManager(viewManagerName) : null;
  if (targetView == null) {
    return null;
  }

  SystraceMessage.beginSection(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIManagerModule.getConstantsForViewManager")
      .arg("ViewManager", targetView.getName())
      .arg("Lazy", true)
      .flush();
  try {
    Map<String, Object> viewManagerConstants =
        UIManagerModuleConstantsHelper.createConstantsForViewManager(
            targetView, null, null, null, mCustomDirectEvents);
    if (viewManagerConstants != null) {
      return Arguments.makeNativeMap(viewManagerConstants);
    }
    return null;
  } finally {
    SystraceMessage.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE).flush();
  }
}
 
Example 11
Source Project: react-native-GPay   Source File: UIManagerModule.java    License: MIT License 6 votes vote down vote up
/**
 * To implement the transactional requirement mentioned in the class javadoc, we only commit
 * UI changes to the actual view hierarchy once a batch of JS->Java calls have been completed.
 * We know this is safe because all JS->Java calls that are triggered by a Java->JS call (e.g.
 * the delivery of a touch event or execution of 'renderApplication') end up in a single
 * JS->Java transaction.
 *
 * A better way to do this would be to have JS explicitly signal to this module when a UI
 * transaction is done. Right now, though, this is how iOS does it, and we should probably
 * update the JS and native code and make this change at the same time.
 *
 * TODO(5279396): Make JS UI library explicitly notify the native UI module of the end of a UI
 *                transaction using a standard native call
 */
@Override
public void onBatchComplete() {
  int batchId = mBatchId;
  mBatchId++;

  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "onBatchCompleteUI")
        .arg("BatchId", batchId)
        .flush();
  for (UIManagerModuleListener listener : mListeners) {
    listener.willDispatchViewUpdates(this);
  }
  try {
    mUIImplementation.dispatchViewUpdates(batchId);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 12
Source Project: react-native-GPay   Source File: ModuleHolder.java    License: MIT License 5 votes vote down vote up
private NativeModule create() {
  SoftAssertions.assertCondition(mModule == null, "Creating an already created module.");
  ReactMarker.logMarker(CREATE_MODULE_START, mName, mInstanceKey);
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ModuleHolder.createModule")
    .arg("name", mName)
    .flush();
  PrinterHolder.getPrinter()
      .logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
  NativeModule module;
  try {
    module = assertNotNull(mProvider).get();
    mProvider = null;
    boolean shouldInitializeNow = false;
    synchronized(this) {
      mModule = module;
      if (mInitializable && !mIsInitializing) {
        shouldInitializeNow = true;
      }
    }
    if (shouldInitializeNow) {
      doInitialize(module);
    }
  } finally {
    ReactMarker.logMarker(CREATE_MODULE_END, mInstanceKey);
    SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
  }
  return module;
}
 
Example 13
Source Project: react-native-GPay   Source File: ModuleHolder.java    License: MIT License 5 votes vote down vote up
private void doInitialize(NativeModule module) {
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ModuleHolder.initialize")
    .arg("name", mName)
    .flush();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_START, mName, mInstanceKey);
  try {
    boolean shouldInitialize = false;
    // Check to see if another thread is initializing the object, if not claim the responsibility
    synchronized (this) {
      if (mInitializable && !mIsInitializing) {
        shouldInitialize = true;
        mIsInitializing = true;
      }
    }
    if (shouldInitialize) {
      module.initialize();
      // Once finished, set flags accordingly, but we don't expect anyone to wait for this to finish
      // So no need to notify other threads
      synchronized (this) {
        mIsInitializing = false;
      }
    }
  } finally {
    ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_END, mInstanceKey);
    SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
  }
}
 
Example 14
Source Project: react-native-GPay   Source 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 15
Source Project: react-native-GPay   Source File: FabricReconciler.java    License: MIT License 5 votes vote down vote up
public void manageChildren(ReactShadowNode previousRootShadowNode, ReactShadowNode newRootShadowNode) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricReconciler.manageChildren")
    .flush();

  try {
    List<ReactShadowNode> prevList =
      previousRootShadowNode == null ? null :  previousRootShadowNode.getChildrenList();
    manageChildren(newRootShadowNode, prevList, newRootShadowNode.getChildrenList());
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 16
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 5 votes vote down vote up
@DoNotStrip
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.completeRoot")
    .flush();
  try {
    long startTime = SystemClock.uptimeMillis();
    childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
    if (DEBUG) {
      FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
    }
    ReactShadowNode currentRootShadowNode = getRootNode(rootTag);
    Assertions.assertNotNull(
        currentRootShadowNode,
        "Root view with tag " + rootTag + " must be added before completeRoot is called");

    currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList);

    if (DEBUG) {
      FLog.d(
        TAG,
        "ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo());
    }

    applyUpdatesRecursive(currentRootShadowNode);
    mUIViewOperationQueue.dispatchViewUpdates(
      mCurrentBatch++, startTime, mLastCalculateLayoutTime);

    mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
  } catch (Exception e) {
    handleException(getRootNode(rootTag), e);
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 17
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 5 votes vote down vote up
private ReactShadowNode calculateDiffingAndCreateNewRootNode(
    ReactShadowNode currentRootShadowNode, List<ReactShadowNode> newChildList) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.calculateDiffingAndCreateNewRootNode")
    .flush();
  try {
    ReactShadowNode newRootShadowNode = currentRootShadowNode.mutableCopyWithNewChildren(currentRootShadowNode.getInstanceHandle());
    for (ReactShadowNode child : newChildList) {
      appendChild(newRootShadowNode, child);
    }

    if (DEBUG) {
      FLog.d(
        TAG,
        "ReactShadowNodeHierarchy before calculateLayout: " + newRootShadowNode.getHierarchyInfo());
    }

    notifyOnBeforeLayoutRecursive(newRootShadowNode);

    calculateLayout(newRootShadowNode);

    if (DEBUG) {
      FLog.d(
        TAG,
        "ReactShadowNodeHierarchy after calculateLayout: " + newRootShadowNode.getHierarchyInfo());
    }

    mFabricReconciler.manageChildren(currentRootShadowNode, newRootShadowNode);
    return newRootShadowNode;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 18
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 5 votes vote down vote up
private void calculateLayout(ReactShadowNode newRootShadowNode) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.calculateLayout")
    .flush();
  long startTime = SystemClock.uptimeMillis();
  try {
    newRootShadowNode.calculateLayout();
  } finally{
    mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime;
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 19
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 5 votes vote down vote up
private void applyUpdatesRecursive(ReactShadowNode node) {
  SystraceMessage.beginSection(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager.applyUpdatesRecursive")
      .flush();
  try {
    applyUpdatesRecursive(node, 0, 0);
  } finally{
    SystraceMessage.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 20
Source Project: react-native-GPay   Source File: FabricUIManager.java    License: MIT License 5 votes vote down vote up
@Override
@DoNotStrip
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
    final T rootView) {

  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.addRootView")
    .flush();
  try {
    final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
    ThemedReactContext themedRootContext =
        new ThemedReactContext(mReactApplicationContext, rootView.getContext());

    ReactShadowNode rootShadowNode = createRootShadowNode(rootTag, themedRootContext);

    int widthMeasureSpec = rootView.getWidthMeasureSpec();
    int heightMeasureSpec = rootView.getHeightMeasureSpec();
    updateRootView(rootShadowNode, widthMeasureSpec, heightMeasureSpec);

    rootView.setOnSizeChangedListener(
      new SizeMonitoringFrameLayout.OnSizeChangedListener() {
        @Override
        public void onSizeChanged(final int width, final int height, int oldW, int oldH) {
          updateRootSize(rootTag, width, height);
        }
      });

    mRootShadowNodeRegistry.registerNode(rootShadowNode);
    mUIViewOperationQueue.addRootView(rootTag, rootView, themedRootContext);
    return rootTag;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 21
Source Project: react-native-GPay   Source File: NativeViewHierarchyManager.java    License: MIT License 5 votes vote down vote up
public synchronized void createView(
    ThemedReactContext themedContext,
    int tag,
    String className,
    @Nullable ReactStylesDiffMap initialProps) {
  UiThreadUtil.assertOnUiThread();
  SystraceMessage.beginSection(
      Systrace.TRACE_TAG_REACT_VIEW,
      "NativeViewHierarchyManager_createView")
      .arg("tag", tag)
      .arg("className", className)
      .flush();
  try {
    ViewManager viewManager = mViewManagers.get(className);

    View view = viewManager.createView(themedContext, mJSResponderHandler);
    mTagsToViews.put(tag, view);
    mTagsToViewManagers.put(tag, viewManager);

    // Use android View id field to store React tag. This is possible since we don't inflate
    // React views from layout xmls. Thus it is easier to just reuse that field instead of
    // creating another (potentially much more expensive) mapping from view to React tag
    view.setId(tag);
    if (initialProps != null) {
      viewManager.updateProperties(view, initialProps);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_VIEW);
  }
}
 
Example 22
Source Project: react-native-GPay   Source File: ReactShadowNodeImpl.java    License: MIT License 5 votes vote down vote up
@Override
public YogaNode cloneNode(YogaNode oldYogaNode,
    YogaNode parent,
    int childIndex) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricReconciler.YogaNodeCloneFunction")
    .flush();
  try {
    ReactShadowNodeImpl parentReactShadowNode = (ReactShadowNodeImpl) parent.getData();
    Assertions.assertNotNull(parentReactShadowNode);
    ReactShadowNodeImpl oldReactShadowNode = (ReactShadowNodeImpl) oldYogaNode.getData();
    Assertions.assertNotNull(oldReactShadowNode);

    if (DEBUG) {
      FLog.d(
        TAG,
        "YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: "
          + parentReactShadowNode + " index: " + childIndex);
    }

    ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy(oldReactShadowNode.getInstanceHandle());
    parentReactShadowNode.replaceChild(newNode, childIndex);
    return newNode.mYogaNode;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 23
Source Project: react-native-GPay   Source File: UIImplementation.java    License: MIT License 5 votes vote down vote up
protected void calculateRootLayout(ReactShadowNode cssRoot) {
  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "cssRoot.calculateLayout")
      .arg("rootTag", cssRoot.getReactTag())
      .flush();
  long startTime = SystemClock.uptimeMillis();
  try {
    cssRoot.calculateLayout();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime;
  }
}
 
Example 24
Source Project: react-native-GPay   Source File: JavaMethodWrapper.java    License: MIT License 4 votes vote down vote up
@Override
public void invoke(JSInstance jsInstance, ReadableNativeArray parameters) {
  String traceName = mModuleWrapper.getName() + "." + mMethod.getName();
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "callJavaModuleMethod")
    .arg("method", traceName)
    .flush();
  if (DEBUG) {
    PrinterHolder.getPrinter()
        .logMessage(
            ReactDebugOverlayTags.BRIDGE_CALLS,
            "JS->Java: %s.%s()",
            mModuleWrapper.getName(),
            mMethod.getName());
  }
  try {
    if (!mArgumentsProcessed) {
      processArguments();
    }
    if (mArguments == null || mArgumentExtractors == null) {
      throw new Error("processArguments failed");
    }
    if (mJSArgumentsNeeded != parameters.size()) {
      throw new NativeArgumentsParseException(
        traceName + " got " + parameters.size() + " arguments, expected " + mJSArgumentsNeeded);
    }

    int i = 0, jsArgumentsConsumed = 0;
    try {
      for (; i < mArgumentExtractors.length; i++) {
        mArguments[i] = mArgumentExtractors[i].extractArgument(
          jsInstance, parameters, jsArgumentsConsumed);
        jsArgumentsConsumed += mArgumentExtractors[i].getJSArgumentsNeeded();
      }
    } catch (UnexpectedNativeTypeException e) {
      throw new NativeArgumentsParseException(
        e.getMessage() + " (constructing arguments for " + traceName + " at argument index " +
          getAffectedRange(jsArgumentsConsumed, mArgumentExtractors[i].getJSArgumentsNeeded()) +
          ")",
        e);
    }

    try {
      mMethod.invoke(mModuleWrapper.getModule(), mArguments);
    } catch (IllegalArgumentException ie) {
      throw new RuntimeException("Could not invoke " + traceName, ie);
    } catch (IllegalAccessException iae) {
      throw new RuntimeException("Could not invoke " + traceName, iae);
    } catch (InvocationTargetException ite) {
      // Exceptions thrown from native module calls end up wrapped in InvocationTargetException
      // which just make traces harder to read and bump out useful information
      if (ite.getCause() instanceof RuntimeException) {
        throw (RuntimeException) ite.getCause();
      }
      throw new RuntimeException("Could not invoke " + traceName, ite);
    }
  } finally {
    SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
  }
}
 
Example 25
Source Project: react-native-GPay   Source File: UIManagerModuleConstantsHelper.java    License: MIT License 4 votes vote down vote up
/**
 * Generates map of constants that is then exposed by {@link UIManagerModule}.
 * Provided list of {@param viewManagers} is then used to populate content of
 * those predefined fields using
 * {@link ViewManager#getExportedCustomBubblingEventTypeConstants} and
 * {@link ViewManager#getExportedCustomDirectEventTypeConstants} respectively. Each view manager
 * is in addition allowed to expose viewmanager-specific constants that are placed under the key
 * that corresponds to the view manager's name (see {@link ViewManager#getName}). Constants are
 * merged into the map of {@link UIManagerModule} base constants that is stored in
 * {@link UIManagerModuleConstants}.
 * TODO(6845124): Create a test for this
 */
/* package */ static Map<String, Object> createConstants(
      List<ViewManager> viewManagers,
      @Nullable Map<String, Object> allBubblingEventTypes,
      @Nullable Map<String, Object> allDirectEventTypes) {
  Map<String, Object> constants = UIManagerModuleConstants.getConstants();

  // Generic/default event types:
  // All view managers are capable of dispatching these events.
  // They will be automatically registered with React Fiber.
  Map genericBubblingEventTypes = UIManagerModuleConstants.getBubblingEventTypeConstants();
  Map genericDirectEventTypes = UIManagerModuleConstants.getDirectEventTypeConstants();

  // Cumulative event types:
  // View manager specific event types are collected as views are loaded.
  // This information is used later when events are dispatched.
  if (allBubblingEventTypes != null) {
    allBubblingEventTypes.putAll(genericBubblingEventTypes);
  }
  if (allDirectEventTypes != null) {
    allDirectEventTypes.putAll(genericDirectEventTypes);
  }

  for (ViewManager viewManager : viewManagers) {
    final String viewManagerName = viewManager.getName();

    SystraceMessage.beginSection(
            TRACE_TAG_REACT_JAVA_BRIDGE, "UIManagerModuleConstantsHelper.createConstants")
        .arg("ViewManager", viewManagerName)
        .arg("Lazy", false)
        .flush();

    try {
      Map viewManagerConstants = createConstantsForViewManager(
          viewManager,
          null,
          null,
          allBubblingEventTypes,
          allDirectEventTypes);
      if (!viewManagerConstants.isEmpty()) {
        constants.put(viewManagerName, viewManagerConstants);
      }
    } finally {
      Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    }
  }

  constants.put("genericBubblingEventTypes", genericBubblingEventTypes);
  constants.put("genericDirectEventTypes", genericDirectEventTypes);
  return constants;
}
 
Example 26
Source Project: react-native-GPay   Source File: NativeViewHierarchyManager.java    License: MIT License 4 votes vote down vote up
public synchronized void updateLayout(
    int parentTag, int tag, int x, int y, int width, int height) {
  UiThreadUtil.assertOnUiThread();
  SystraceMessage.beginSection(
      Systrace.TRACE_TAG_REACT_VIEW,
      "NativeViewHierarchyManager_updateLayout")
      .arg("parentTag", parentTag)
      .arg("tag", tag)
      .flush();
  try {
    View viewToUpdate = resolveView(tag);

    // Even though we have exact dimensions, we still call measure because some platform views (e.g.
    // Switch) assume that method will always be called before onLayout and onDraw. They use it to
    // calculate and cache information used in the draw pass. For most views, onMeasure can be
    // stubbed out to only call setMeasuredDimensions. For ViewGroups, onLayout should be stubbed
    // out to not recursively call layout on its children: React Native already handles doing that.
    //
    // Also, note measure and layout need to be called *after* all View properties have been updated
    // because of caching and calculation that may occur in onMeasure and onLayout. Layout
    // operations should also follow the native view hierarchy and go top to bottom for consistency
    // with standard layout passes (some views may depend on this).

    viewToUpdate.measure(
        View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
        View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));

    // We update the layout of the ReactRootView when there is a change in the layout of its child.
    // This is required to re-measure the size of the native View container (usually a
    // FrameLayout) that is configured with layout_height = WRAP_CONTENT or layout_width =
    // WRAP_CONTENT
    //
    // This code is going to be executed ONLY when there is a change in the size of the Root
    // View defined in the js side. Changes in the layout of inner views will not trigger an update
    // on the layour of the Root View.
    ViewParent parent = viewToUpdate.getParent();
    if (parent instanceof RootView) {
      parent.requestLayout();
    }

    // Check if the parent of the view has to layout the view, or the child has to lay itself out.
    if (!mRootTags.get(parentTag)) {
      ViewManager parentViewManager = mTagsToViewManagers.get(parentTag);
      ViewGroupManager parentViewGroupManager;
      if (parentViewManager instanceof ViewGroupManager) {
        parentViewGroupManager = (ViewGroupManager) parentViewManager;
      } else {
        throw new IllegalViewOperationException(
            "Trying to use view with tag " + tag +
                " as a parent, but its Manager doesn't extends ViewGroupManager");
      }
      if (parentViewGroupManager != null
          && !parentViewGroupManager.needsCustomLayoutForChildren()) {
        updateLayout(viewToUpdate, x, y, width, height);
      }
    } else {
      updateLayout(viewToUpdate, x, y, width, height);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_VIEW);
  }
}
 
Example 27
Source Project: react-native-GPay   Source 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);
  }
}