From ac0134322ff25b0c527f75fd3da1b743caaaf148 Mon Sep 17 00:00:00 2001 From: Denis Koroskin Date: Mon, 23 Nov 2015 13:21:29 -0800 Subject: [PATCH] Remove UIManagerModule dependency in UIViewOperationQueue Reviewed By: astreet Differential Revision: D2463226 fb-gh-sync-id: eafc876ca750a08406917d8bbbfe87c27a4649fd --- .../DidJSUpdateUiDuringFrameDetector.java | 4 +-- .../modules/debug/FpsDebugFrameCallback.java | 4 +-- .../react/uimanager/UIManagerModule.java | 34 +++---------------- .../react/uimanager/UIViewOperationQueue.java | 28 +++++++++------ ...SafeViewHierarchyUpdateDebugListener.java} | 4 +-- 5 files changed, 28 insertions(+), 46 deletions(-) rename ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/{NotThreadSafeUiManagerDebugListener.java => NotThreadSafeViewHierarchyUpdateDebugListener.java} (85%) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java index 28144b9af..f15a143df 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java @@ -15,7 +15,7 @@ import com.facebook.react.bridge.ReactBridge; import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener; import com.facebook.react.common.LongArray; import com.facebook.react.uimanager.UIManagerModule; -import com.facebook.react.uimanager.debug.NotThreadSafeUiManagerDebugListener; +import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener; /** * Debug object that listens to bridge busy/idle events and UiManagerModule dispatches and uses it @@ -25,7 +25,7 @@ import com.facebook.react.uimanager.debug.NotThreadSafeUiManagerDebugListener; * {@link Choreographer.FrameCallback}. */ public class DidJSUpdateUiDuringFrameDetector implements NotThreadSafeBridgeIdleDebugListener, - NotThreadSafeUiManagerDebugListener { + NotThreadSafeViewHierarchyUpdateDebugListener { private final LongArray mTransitionToIdleEvents = LongArray.createWithInitialCapacity(20); private final LongArray mTransitionToBusyEvents = LongArray.createWithInitialCapacity(20); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java index 71400867e..1eac40fae 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java @@ -135,7 +135,7 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback { mShouldStop = false; mReactContext.getCatalystInstance().addBridgeIdleDebugListener( mDidJSUpdateUiDuringFrameDetector); - mUIManagerModule.setUiManagerDebugListener(mDidJSUpdateUiDuringFrameDetector); + mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector); mChoreographer.postFrameCallback(this); } @@ -149,7 +149,7 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback { mShouldStop = true; mReactContext.getCatalystInstance().removeBridgeIdleDebugListener( mDidJSUpdateUiDuringFrameDetector); - mUIManagerModule.setUiManagerDebugListener(null); + mUIManagerModule.setViewHierarchyUpdateDebugListener(null); } public double getFPS() { diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 6482a209b..67b171ee9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -35,7 +35,7 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.SoftAssertions; import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.WritableArray; -import com.facebook.react.uimanager.debug.NotThreadSafeUiManagerDebugListener; +import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.systrace.Systrace; import com.facebook.systrace.SystraceMessage; @@ -87,7 +87,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements private final NativeViewHierarchyOptimizer mNativeViewHierarchyOptimizer; private final int[] mMeasureBuffer = new int[4]; - private @Nullable NotThreadSafeUiManagerDebugListener mUiManagerDebugListener; private int mNextRootViewTag = 1; private int mBatchId = 0; @@ -100,7 +99,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements mViewManagers); mOperationsQueue = new UIViewOperationQueue( reactContext, - this, mNativeViewHierarchyManager, mAnimationRegistry); mNativeViewHierarchyOptimizer = new NativeViewHierarchyOptimizer( @@ -771,8 +769,9 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements } } - public void setUiManagerDebugListener(@Nullable NotThreadSafeUiManagerDebugListener listener) { - mUiManagerDebugListener = listener; + public void setViewHierarchyUpdateDebugListener( + @Nullable NotThreadSafeViewHierarchyUpdateDebugListener listener) { + mOperationsQueue.setViewHierarchyUpdateDebugListener(listener); } public EventDispatcher getEventDispatcher() { @@ -836,34 +835,9 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements cssNode.markUpdateSeen(); } - /* package */ void notifyOnViewHierarchyUpdateEnqueued() { - if (mUiManagerDebugListener != null) { - mUiManagerDebugListener.onViewHierarchyUpdateEnqueued(); - } - } - - /* package */ void notifyOnViewHierarchyUpdateFinished() { - if (mUiManagerDebugListener != null) { - mUiManagerDebugListener.onViewHierarchyUpdateFinished(); - } - } - @ReactMethod public void sendAccessibilityEvent(int tag, int eventType) { mOperationsQueue.enqueueSendAccessibilityEvent(tag, eventType); } - /** - * Get the first non-virtual (i.e. native) parent view tag of the react view with the passed tag. - * If the passed tag represents a non-virtual view, the same tag is returned. If the passed tag - * doesn't map to a react view, or a non-virtual parent cannot be found, -1 is returned. - */ - /* package */ int getNonVirtualParent(int reactTag) { - ReactShadowNode node = mShadowNodeRegistry.getNode(reactTag); - while (node != null && node.isVirtual()) { - node = node.getParent(); - } - return node == null ? -1 : node.getReactTag(); - } - } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java index bb9cea705..a931b5e0f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java @@ -20,6 +20,7 @@ import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener; import com.facebook.systrace.Systrace; import com.facebook.systrace.SystraceMessage; @@ -405,11 +406,10 @@ public class UIViewOperationQueue { final float containerX = (float) mMeasureBuffer[0]; final float containerY = (float) mMeasureBuffer[1]; - final int touchTargetReactTag = mUIManagerModule.getNonVirtualParent( - mNativeViewHierarchyManager.findTargetTagForTouch( - mReactTag, - mTargetX, - mTargetY)); + final int touchTargetReactTag = mNativeViewHierarchyManager.findTargetTagForTouch( + mReactTag, + mTargetX, + mTargetY); try { mNativeViewHierarchyManager.measure( @@ -443,7 +443,6 @@ public class UIViewOperationQueue { } } - private final UIManagerModule mUIManagerModule; private final NativeViewHierarchyManager mNativeViewHierarchyManager; private final AnimationRegistry mAnimationRegistry; @@ -453,17 +452,22 @@ public class UIViewOperationQueue { @GuardedBy("mDispatchRunnablesLock") private final ArrayList mDispatchUIRunnables = new ArrayList<>(); + private @Nullable NotThreadSafeViewHierarchyUpdateDebugListener mViewHierarchyUpdateDebugListener; + /* package */ UIViewOperationQueue( ReactApplicationContext reactContext, - UIManagerModule uiManagerModule, NativeViewHierarchyManager nativeViewHierarchyManager, AnimationRegistry animationRegistry) { - mUIManagerModule = uiManagerModule; mNativeViewHierarchyManager = nativeViewHierarchyManager; mAnimationRegistry = animationRegistry; mDispatchUIFrameCallback = new DispatchUIFrameCallback(reactContext); } + public void setViewHierarchyUpdateDebugListener( + @Nullable NotThreadSafeViewHierarchyUpdateDebugListener listener) { + mViewHierarchyUpdateDebugListener = listener; + } + public boolean isEmpty() { return mOperations.isEmpty(); } @@ -592,7 +596,9 @@ public class UIViewOperationQueue { mOperations = new ArrayList<>(); } - mUIManagerModule.notifyOnViewHierarchyUpdateEnqueued(); + if (mViewHierarchyUpdateDebugListener != null) { + mViewHierarchyUpdateDebugListener.onViewHierarchyUpdateEnqueued(); + } synchronized (mDispatchRunnablesLock) { mDispatchUIRunnables.add( @@ -608,7 +614,9 @@ public class UIViewOperationQueue { operations.get(i).execute(); } } - mUIManagerModule.notifyOnViewHierarchyUpdateFinished(); + if (mViewHierarchyUpdateDebugListener != null) { + mViewHierarchyUpdateDebugListener.onViewHierarchyUpdateFinished(); + } } finally { Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/NotThreadSafeUiManagerDebugListener.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/NotThreadSafeViewHierarchyUpdateDebugListener.java similarity index 85% rename from ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/NotThreadSafeUiManagerDebugListener.java rename to ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/NotThreadSafeViewHierarchyUpdateDebugListener.java index 1f4a5690b..6f35ca065 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/NotThreadSafeUiManagerDebugListener.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/debug/NotThreadSafeViewHierarchyUpdateDebugListener.java @@ -12,13 +12,13 @@ package com.facebook.react.uimanager.debug; import com.facebook.react.uimanager.UIManagerModule; /** - * A listener that is notified about {@link UIManagerModule} events. This listener should only be + * A listener that is notified about view hierarchy update events. This listener should only be * used for debug purposes and should not affect application state. * * NB: while onViewHierarchyUpdateFinished will always be called from the UI thread, there are no * guarantees what thread onViewHierarchyUpdateEnqueued is called on. */ -public interface NotThreadSafeUiManagerDebugListener { +public interface NotThreadSafeViewHierarchyUpdateDebugListener { /** * Called when {@link UIManagerModule} enqueues a UI batch to be dispatched to the main thread.