mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 12:45:37 +08:00
Only send layout update operation to nativehierarchymanager when layout actually changes.
Reviewed By: andreicoman11 Differential Revision: D2679408 fb-gh-sync-id: 7f0a972e9e12f70402e2d285edef458a61ca1c39
This commit is contained in:
committed by
facebook-github-bot-9
parent
06e514076b
commit
0c8850f3a7
@@ -18,6 +18,7 @@ import com.facebook.csslayout.CSSNode;
|
|||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
||||||
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily
|
* Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily
|
||||||
@@ -202,18 +203,37 @@ public class ReactShadowNode extends CSSNode {
|
|||||||
float absoluteX,
|
float absoluteX,
|
||||||
float absoluteY,
|
float absoluteY,
|
||||||
UIViewOperationQueue uiViewOperationQueue,
|
UIViewOperationQueue uiViewOperationQueue,
|
||||||
NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer) {
|
NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer,
|
||||||
|
EventDispatcher eventDispatcher) {
|
||||||
if (mNodeUpdated) {
|
if (mNodeUpdated) {
|
||||||
onCollectExtraUpdates(uiViewOperationQueue);
|
onCollectExtraUpdates(uiViewOperationQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNewLayout()) {
|
if (hasNewLayout()) {
|
||||||
mAbsoluteLeft = Math.round(absoluteX + getLayoutX());
|
float absoluteLeft = Math.round(absoluteX + getLayoutX());
|
||||||
mAbsoluteTop = Math.round(absoluteY + getLayoutY());
|
float absoluteTop = Math.round(absoluteY + getLayoutY());
|
||||||
mAbsoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth());
|
float absoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth());
|
||||||
mAbsoluteBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight());
|
float absoluteBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight());
|
||||||
|
// If the layout didn't change this should calculate exactly same values, it's fine to compare
|
||||||
|
// floats with "==" in this case
|
||||||
|
if (absoluteLeft != mAbsoluteLeft || absoluteTop != mAbsoluteTop ||
|
||||||
|
absoluteRight != mAbsoluteRight || absoluteBottom != mAbsoluteBottom) {
|
||||||
|
mAbsoluteLeft = absoluteLeft;
|
||||||
|
mAbsoluteTop = absoluteTop;
|
||||||
|
mAbsoluteRight = absoluteRight;
|
||||||
|
mAbsoluteBottom = absoluteBottom;
|
||||||
|
|
||||||
nativeViewHierarchyOptimizer.handleUpdateLayout(this);
|
nativeViewHierarchyOptimizer.handleUpdateLayout(this);
|
||||||
|
if (mShouldNotifyOnLayout) {
|
||||||
|
eventDispatcher.dispatchEvent(
|
||||||
|
OnLayoutEvent.obtain(
|
||||||
|
getReactTag(),
|
||||||
|
getScreenX(),
|
||||||
|
getScreenY(),
|
||||||
|
getScreenWidth(),
|
||||||
|
getScreenHeight()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,10 +284,6 @@ public class ReactShadowNode extends CSSNode {
|
|||||||
mShouldNotifyOnLayout = shouldNotifyOnLayout;
|
mShouldNotifyOnLayout = shouldNotifyOnLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ boolean shouldNotifyOnLayout() {
|
|
||||||
return mShouldNotifyOnLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a child that the native view hierarchy will have at this index in the native view
|
* Adds a child that the native view hierarchy will have at this index in the native view
|
||||||
* corresponding to this node.
|
* corresponding to this node.
|
||||||
|
|||||||
@@ -814,18 +814,8 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||||||
absoluteX,
|
absoluteX,
|
||||||
absoluteY,
|
absoluteY,
|
||||||
mOperationsQueue,
|
mOperationsQueue,
|
||||||
mNativeViewHierarchyOptimizer);
|
mNativeViewHierarchyOptimizer,
|
||||||
|
mEventDispatcher);
|
||||||
// notify JS about layout event if requested
|
|
||||||
if (cssNode.shouldNotifyOnLayout()) {
|
|
||||||
mEventDispatcher.dispatchEvent(
|
|
||||||
OnLayoutEvent.obtain(
|
|
||||||
tag,
|
|
||||||
cssNode.getScreenX(),
|
|
||||||
cssNode.getScreenY(),
|
|
||||||
cssNode.getScreenWidth(),
|
|
||||||
cssNode.getScreenHeight()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cssNode.markUpdateSeen();
|
cssNode.markUpdateSeen();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user