mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-21 10:34:31 +08:00
pass EventDispatcher to UIImplementation constructor
Summary: This way `UIImplementation` can hold on to it and use it outside of calls from the `UIManagerModule`. Reviewed By: lexs Differential Revision: D3899774 fbshipit-source-id: 01e4956c4540bcdf30774a3f40a625e934714ee9
This commit is contained in:
committed by
Facebook Github Bot
parent
5eb28dc4f0
commit
f7cbd56d8e
@@ -202,9 +202,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M
|
||||
return new UIManagerModule(
|
||||
reactContext,
|
||||
viewManagersList,
|
||||
mUIImplementationProvider.createUIImplementation(
|
||||
reactContext,
|
||||
viewManagersList));
|
||||
mUIImplementationProvider);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
|
||||
|
||||
@@ -45,31 +45,41 @@ public class UIImplementation {
|
||||
private final NativeViewHierarchyOptimizer mNativeViewHierarchyOptimizer;
|
||||
private final int[] mMeasureBuffer = new int[4];
|
||||
private final ReactApplicationContext mReactContext;
|
||||
protected final EventDispatcher mEventDispatcher;
|
||||
|
||||
private double mLayoutCount = 0.0;
|
||||
private double mLayoutTimer = 0.0;
|
||||
|
||||
public UIImplementation(ReactApplicationContext reactContext, List<ViewManager> viewManagers) {
|
||||
this(reactContext, new ViewManagerRegistry(viewManagers));
|
||||
public UIImplementation(
|
||||
ReactApplicationContext reactContext,
|
||||
List<ViewManager> viewManagers,
|
||||
EventDispatcher eventDispatcher) {
|
||||
this(reactContext, new ViewManagerRegistry(viewManagers), eventDispatcher);
|
||||
}
|
||||
|
||||
private UIImplementation(ReactApplicationContext reactContext, ViewManagerRegistry viewManagers) {
|
||||
private UIImplementation(
|
||||
ReactApplicationContext reactContext,
|
||||
ViewManagerRegistry viewManagers,
|
||||
EventDispatcher eventDispatcher) {
|
||||
this(
|
||||
reactContext,
|
||||
viewManagers,
|
||||
new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagers)));
|
||||
new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagers)),
|
||||
eventDispatcher);
|
||||
}
|
||||
|
||||
protected UIImplementation(
|
||||
ReactApplicationContext reactContext,
|
||||
ViewManagerRegistry viewManagers,
|
||||
UIViewOperationQueue operationsQueue) {
|
||||
UIViewOperationQueue operationsQueue,
|
||||
EventDispatcher eventDispatcher) {
|
||||
mReactContext = reactContext;
|
||||
mViewManagers = viewManagers;
|
||||
mOperationsQueue = operationsQueue;
|
||||
mNativeViewHierarchyOptimizer = new NativeViewHierarchyOptimizer(
|
||||
mOperationsQueue,
|
||||
mShadowNodeRegistry);
|
||||
mEventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
protected ReactShadowNode createRootShadowNode() {
|
||||
@@ -136,8 +146,7 @@ public class UIImplementation {
|
||||
public void updateNodeSize(
|
||||
int nodeViewTag,
|
||||
int newWidth,
|
||||
int newHeight,
|
||||
EventDispatcher eventDispatcher) {
|
||||
int newHeight) {
|
||||
ReactShadowNode cssNode = mShadowNodeRegistry.getNode(nodeViewTag);
|
||||
cssNode.setStyleWidth(newWidth);
|
||||
cssNode.setStyleHeight(newHeight);
|
||||
@@ -146,7 +155,7 @@ public class UIImplementation {
|
||||
// the batch. As all batches are executed as a single runnable on the event queue this should
|
||||
// always be empty, but that calling architecture is an implementation detail.
|
||||
if (mOperationsQueue.isEmpty()) {
|
||||
dispatchViewUpdates(eventDispatcher, -1); // -1 = no associated batch id
|
||||
dispatchViewUpdates(-1); // -1 = no associated batch id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,20 +524,20 @@ public class UIImplementation {
|
||||
/**
|
||||
* Invoked at the end of the transaction to commit any updates to the node hierarchy.
|
||||
*/
|
||||
public void dispatchViewUpdates(EventDispatcher eventDispatcher, int batchId) {
|
||||
updateViewHierarchy(eventDispatcher);
|
||||
public void dispatchViewUpdates(int batchId) {
|
||||
updateViewHierarchy();
|
||||
mNativeViewHierarchyOptimizer.onBatchComplete();
|
||||
mOperationsQueue.dispatchViewUpdates(batchId);
|
||||
}
|
||||
|
||||
protected void updateViewHierarchy(EventDispatcher eventDispatcher) {
|
||||
protected void updateViewHierarchy() {
|
||||
for (int i = 0; i < mShadowNodeRegistry.getRootNodeCount(); i++) {
|
||||
int tag = mShadowNodeRegistry.getRootTag(i);
|
||||
ReactShadowNode cssRoot = mShadowNodeRegistry.getNode(tag);
|
||||
notifyOnBeforeLayoutRecursive(cssRoot);
|
||||
|
||||
calculateRootLayout(cssRoot);
|
||||
applyUpdatesRecursive(cssRoot, 0f, 0f, eventDispatcher);
|
||||
applyUpdatesRecursive(cssRoot, 0f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,8 +773,7 @@ public class UIImplementation {
|
||||
protected void applyUpdatesRecursive(
|
||||
ReactShadowNode cssNode,
|
||||
float absoluteX,
|
||||
float absoluteY,
|
||||
EventDispatcher eventDispatcher) {
|
||||
float absoluteY) {
|
||||
if (!cssNode.hasUpdates()) {
|
||||
return;
|
||||
}
|
||||
@@ -775,8 +783,7 @@ public class UIImplementation {
|
||||
applyUpdatesRecursive(
|
||||
cssNode.getChildAt(i),
|
||||
absoluteX + cssNode.getLayoutX(),
|
||||
absoluteY + cssNode.getLayoutY(),
|
||||
eventDispatcher);
|
||||
absoluteY + cssNode.getLayoutY());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,7 +797,7 @@ public class UIImplementation {
|
||||
|
||||
// notify JS about layout event if requested
|
||||
if (cssNode.shouldNotifyOnLayout()) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
mEventDispatcher.dispatchEvent(
|
||||
OnLayoutEvent.obtain(
|
||||
tag,
|
||||
cssNode.getScreenX(),
|
||||
|
||||
@@ -11,6 +11,7 @@ package com.facebook.react.uimanager;
|
||||
import java.util.List;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
|
||||
/**
|
||||
* Provides UIImplementation to use in {@link UIManagerModule}.
|
||||
@@ -18,7 +19,8 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||
public class UIImplementationProvider {
|
||||
public UIImplementation createUIImplementation(
|
||||
ReactApplicationContext reactContext,
|
||||
List<ViewManager> viewManagers) {
|
||||
return new UIImplementation(reactContext, viewManagers);
|
||||
List<ViewManager> viewManagers,
|
||||
EventDispatcher eventDispatcher) {
|
||||
return new UIImplementation(reactContext, viewManagers, eventDispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +85,13 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||
public UIManagerModule(
|
||||
ReactApplicationContext reactContext,
|
||||
List<ViewManager> viewManagerList,
|
||||
UIImplementation uiImplementation) {
|
||||
UIImplementationProvider uiImplementationProvider) {
|
||||
super(reactContext);
|
||||
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
|
||||
mEventDispatcher = new EventDispatcher(reactContext);
|
||||
mModuleConstants = createConstants(viewManagerList);
|
||||
mUIImplementation = uiImplementation;
|
||||
mUIImplementation = uiImplementationProvider
|
||||
.createUIImplementation(reactContext, viewManagerList, mEventDispatcher);
|
||||
|
||||
reactContext.addLifecycleEventListener(this);
|
||||
}
|
||||
@@ -209,7 +210,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||
public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) {
|
||||
getReactApplicationContext().assertOnNativeModulesQueueThread();
|
||||
|
||||
mUIImplementation.updateNodeSize(nodeViewTag, newWidth, newHeight, mEventDispatcher);
|
||||
mUIImplementation.updateNodeSize(nodeViewTag, newWidth, newHeight);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
@@ -496,7 +497,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||
.arg("BatchId", batchId)
|
||||
.flush();
|
||||
try {
|
||||
mUIImplementation.dispatchViewUpdates(mEventDispatcher, batchId);
|
||||
mUIImplementation.dispatchViewUpdates(batchId);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user