mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-09 09:12:06 +08:00
Remove UIManagerModule dependency in UIViewOperationQueue
Reviewed By: astreet Differential Revision: D2463226 fb-gh-sync-id: eafc876ca750a08406917d8bbbfe87c27a4649fd
This commit is contained in:
committed by
facebook-github-bot-0
parent
f624d01cac
commit
ac0134322f
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Runnable> 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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user