Skip to content

Commit

Permalink
Only send layout update operation to nativehierarchymanager when layo…
Browse files Browse the repository at this point in the history
…ut actually changes.

Reviewed By: andreicoman11

Differential Revision: D2679408

fb-gh-sync-id: 7f0a972e9e12f70402e2d285edef458a61ca1c39
  • Loading branch information
kmagiera authored and facebook-github-bot-9 committed Nov 20, 2015
1 parent 06e5140 commit 0c8850f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReadableMap;
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
Expand Down Expand Up @@ -202,18 +203,37 @@ public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
float absoluteX,
float absoluteY,
UIViewOperationQueue uiViewOperationQueue,
NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer) {
NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer,
EventDispatcher eventDispatcher) {
if (mNodeUpdated) {
onCollectExtraUpdates(uiViewOperationQueue);
}

if (hasNewLayout()) {
mAbsoluteLeft = Math.round(absoluteX + getLayoutX());
mAbsoluteTop = Math.round(absoluteY + getLayoutY());
mAbsoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth());
mAbsoluteBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight());

nativeViewHierarchyOptimizer.handleUpdateLayout(this);
float absoluteLeft = Math.round(absoluteX + getLayoutX());
float absoluteTop = Math.round(absoluteY + getLayoutY());
float absoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth());
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);
if (mShouldNotifyOnLayout) {
eventDispatcher.dispatchEvent(
OnLayoutEvent.obtain(
getReactTag(),
getScreenX(),
getScreenY(),
getScreenWidth(),
getScreenHeight()));
}
}
}
}

Expand Down Expand Up @@ -264,10 +284,6 @@ public void setShouldNotifyOnLayout(boolean 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
* corresponding to this node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,18 +814,8 @@ private void applyUpdatesRecursive(ReactShadowNode cssNode, float absoluteX, flo
absoluteX,
absoluteY,
mOperationsQueue,
mNativeViewHierarchyOptimizer);

// notify JS about layout event if requested
if (cssNode.shouldNotifyOnLayout()) {
mEventDispatcher.dispatchEvent(
OnLayoutEvent.obtain(
tag,
cssNode.getScreenX(),
cssNode.getScreenY(),
cssNode.getScreenWidth(),
cssNode.getScreenHeight()));
}
mNativeViewHierarchyOptimizer,
mEventDispatcher);
}
cssNode.markUpdateSeen();
}
Expand Down

0 comments on commit 0c8850f

Please sign in to comment.