Skip to content

Commit

Permalink
Add debugging mode to non-Fabric NativeViewHierarchyManager
Browse files Browse the repository at this point in the history
Summary:
Just helpful for debugging sessions.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D24207622

fbshipit-source-id: 904cbaa4512c03581d6a5c3efd69ebfca7972d42
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Oct 9, 2020
1 parent 0c438be commit 3aa4de7
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.facebook.react.bridge.RetryableMountingLayerException;
import com.facebook.react.bridge.SoftAssertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.uimanager.layoutanimation.LayoutAnimationController;
Expand Down Expand Up @@ -69,6 +70,7 @@
public class NativeViewHierarchyManager {

private static final String TAG = NativeViewHierarchyManager.class.getSimpleName();
private final boolean DEBUG_MODE = ReactBuildConfig.DEBUG && false;

private final SparseArray<View> mTagsToViews;
private final SparseArray<ViewManager> mTagsToViewManagers;
Expand Down Expand Up @@ -128,6 +130,9 @@ public synchronized void updateInstanceHandle(int tag, long instanceHandle) {
}

public synchronized void updateProperties(int tag, ReactStylesDiffMap props) {
if (DEBUG_MODE) {
FLog.d(TAG, "updateProperties[%d]: %s", tag, props.toString());
}
UiThreadUtil.assertOnUiThread();

try {
Expand All @@ -143,6 +148,9 @@ public synchronized void updateProperties(int tag, ReactStylesDiffMap props) {
}

public synchronized void updateViewExtraData(int tag, Object extraData) {
if (DEBUG_MODE) {
FLog.d(TAG, "updateViewExtraData[%d]: %s", tag, extraData.toString());
}
UiThreadUtil.assertOnUiThread();

ViewManager viewManager = resolveViewManager(tag);
Expand All @@ -152,6 +160,9 @@ public synchronized void updateViewExtraData(int tag, Object extraData) {

public synchronized void updateLayout(
int parentTag, int tag, int x, int y, int width, int height) {
if (DEBUG_MODE) {
FLog.d(TAG, "updateLayout[%d]->[%d]: %d %d %d %d", tag, parentTag, x, y, width, height);
}
UiThreadUtil.assertOnUiThread();
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_VIEW, "NativeViewHierarchyManager_updateLayout")
Expand Down Expand Up @@ -250,6 +261,9 @@ public synchronized void createView(
int tag,
String className,
@Nullable ReactStylesDiffMap initialProps) {
if (DEBUG_MODE) {
FLog.d(TAG, "createView[%d]: %s %s", tag, className, initialProps.toString());
}
UiThreadUtil.assertOnUiThread();
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_VIEW, "NativeViewHierarchyManager_createView")
Expand Down Expand Up @@ -372,6 +386,15 @@ public synchronized void manageChildren(
@Nullable int[] indicesToRemove,
@Nullable ViewAtIndex[] viewsToAdd,
@Nullable int[] tagsToDelete) {
if (DEBUG_MODE) {
FLog.d(
TAG,
"createView[%d]: %s %s %s",
tag,
(indicesToRemove != null ? indicesToRemove.toString() : "<null>"),
(viewsToAdd != null ? viewsToAdd.toString() : "<null>"),
(tagsToDelete != null ? tagsToDelete.toString() : "<null>"));
}
UiThreadUtil.assertOnUiThread();

final Set<Integer> pendingDeletionTags = getPendingDeletionsForTag(tag);
Expand Down Expand Up @@ -545,6 +568,13 @@ private static String constructSetChildrenErrorMessage(

/** Simplified version of manageChildren that only deals with adding children views */
public synchronized void setChildren(int tag, ReadableArray childrenTags) {
if (DEBUG_MODE) {
FLog.d(
TAG,
"setChildren[%d]: %s",
tag,
(childrenTags != null ? childrenTags.toString() : "<null>"));
}
UiThreadUtil.assertOnUiThread();
ViewGroup viewToManage = (ViewGroup) mTagsToViews.get(tag);
ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(tag);
Expand All @@ -568,6 +598,9 @@ public synchronized void addRootView(int tag, View view) {
}

protected final synchronized void addRootViewGroup(int tag, View view) {
if (DEBUG_MODE) {
FLog.d(TAG, "addRootViewGroup[%d]: %s", tag, (view != null ? view.toString() : "<null>"));
}
if (view.getId() != View.NO_ID) {
FLog.e(
TAG,
Expand All @@ -587,6 +620,9 @@ protected final synchronized void addRootViewGroup(int tag, View view) {

/** Releases all references to given native View. */
protected synchronized void dropView(View view) {
if (DEBUG_MODE) {
FLog.d(TAG, "dropView[%d]", (view != null ? view.getId() : -1));
}
UiThreadUtil.assertOnUiThread();
if (view == null) {
// Ignore this drop operation when view is null.
Expand Down Expand Up @@ -620,6 +656,9 @@ protected synchronized void dropView(View view) {
}

public synchronized void removeRootView(int rootViewTag) {
if (DEBUG_MODE) {
FLog.d(TAG, "removeRootView[%d]", rootViewTag);
}
UiThreadUtil.assertOnUiThread();
if (!mRootTags.get(rootViewTag)) {
SoftAssertions.assertUnreachable(
Expand All @@ -635,6 +674,9 @@ public synchronized void removeRootView(int rootViewTag) {
* {x, y, width, height}.
*/
public synchronized void measure(int tag, int[] outputBuffer) {
if (DEBUG_MODE) {
FLog.d(TAG, "measure[%d]", tag);
}
UiThreadUtil.assertOnUiThread();
View v = mTagsToViews.get(tag);
if (v == null) {
Expand Down Expand Up @@ -699,6 +741,9 @@ private void mapRectFromViewToWindowCoords(View view, RectF rect) {
* relative to the device window
*/
public synchronized void measureInWindow(int tag, int[] outputBuffer) {
if (DEBUG_MODE) {
FLog.d(TAG, "measureInWindow[%d]", tag);
}
UiThreadUtil.assertOnUiThread();
View v = mTagsToViews.get(tag);
if (v == null) {
Expand All @@ -720,6 +765,9 @@ public synchronized void measureInWindow(int tag, int[] outputBuffer) {
}

public synchronized int findTargetTagForTouch(int reactTag, float touchX, float touchY) {
if (DEBUG_MODE) {
FLog.d(TAG, "findTargetTagForTouch[%d]: %f %f", reactTag, touchX, touchY);
}
UiThreadUtil.assertOnUiThread();
View view = mTagsToViews.get(reactTag);
if (view == null) {
Expand Down Expand Up @@ -765,6 +813,14 @@ void clearLayoutAnimation() {
@Deprecated
public synchronized void dispatchCommand(
int reactTag, int commandId, @Nullable ReadableArray args) {
if (DEBUG_MODE) {
FLog.d(
TAG,
"dispatchCommand[%d]: %d %s",
reactTag,
commandId,
(args != null ? args.toString() : "<null>"));
}
UiThreadUtil.assertOnUiThread();
View view = mTagsToViews.get(reactTag);
if (view == null) {
Expand All @@ -780,6 +836,14 @@ public synchronized void dispatchCommand(

public synchronized void dispatchCommand(
int reactTag, String commandId, @Nullable ReadableArray args) {
if (DEBUG_MODE) {
FLog.d(
TAG,
"dispatchCommand[%d]: %s %s",
reactTag,
commandId,
(args != null ? args.toString() : "<null>"));
}
UiThreadUtil.assertOnUiThread();
View view = mTagsToViews.get(reactTag);
if (view == null) {
Expand Down

0 comments on commit 3aa4de7

Please sign in to comment.