diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java index bbf33b7b2..73134194f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java @@ -18,7 +18,6 @@ import com.facebook.csslayout.CSSNode; 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 @@ -203,37 +202,18 @@ public class ReactShadowNode extends CSSNode { float absoluteX, float absoluteY, UIViewOperationQueue uiViewOperationQueue, - NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer, - EventDispatcher eventDispatcher) { + NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer) { if (mNodeUpdated) { onCollectExtraUpdates(uiViewOperationQueue); } if (hasNewLayout()) { - 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; + 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); - if (mShouldNotifyOnLayout) { - eventDispatcher.dispatchEvent( - OnLayoutEvent.obtain( - getReactTag(), - getScreenX(), - getScreenY(), - getScreenWidth(), - getScreenHeight())); - } - } + nativeViewHierarchyOptimizer.handleUpdateLayout(this); } } @@ -284,6 +264,10 @@ public class ReactShadowNode extends CSSNode { 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. diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java index aef2ebc29..633c8dd43 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java @@ -698,8 +698,18 @@ public class UIImplementation { absoluteX, absoluteY, mOperationsQueue, - mNativeViewHierarchyOptimizer, - eventDispatcher); + mNativeViewHierarchyOptimizer); + + // notify JS about layout event if requested + if (cssNode.shouldNotifyOnLayout()) { + eventDispatcher.dispatchEvent( + OnLayoutEvent.obtain( + tag, + cssNode.getScreenX(), + cssNode.getScreenY(), + cssNode.getScreenWidth(), + cssNode.getScreenHeight())); + } } cssNode.markUpdateSeen(); }