diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java index b72561caf..e14be37f2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java @@ -12,10 +12,11 @@ package com.facebook.react.flat; import javax.annotation.Nullable; import com.facebook.infer.annotation.Assertions; -import com.facebook.react.uimanager.ReactStylesDiffMap; import com.facebook.react.uimanager.LayoutShadowNode; -import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.OnLayoutEvent; +import com.facebook.react.uimanager.ReactStylesDiffMap; import com.facebook.react.uimanager.ViewProps; +import com.facebook.react.uimanager.annotations.ReactProp; /** * FlatShadowNode is a base class for all shadow node used in FlatUIImplementation. It extends @@ -50,6 +51,12 @@ import com.facebook.react.uimanager.ViewProps; private int mMoveToIndexInParent; private boolean mClipToBounds = false; + // last OnLayoutEvent info, only used when shouldNotifyOnLayout() is true. + private int mLayoutX; + private int mLayoutY; + private int mLayoutWidth; + private int mLayoutHeight; + /* package */ void handleUpdateProperties(ReactStylesDiffMap styles) { if (!mountsToView()) { // Make sure we mount this FlatShadowNode to a View if any of these properties are present. @@ -277,6 +284,19 @@ import com.facebook.react.uimanager.ViewProps; return mDrawView; } + /* package */ final OnLayoutEvent obtainLayoutEvent(int x, int y, int width, int height) { + if (mLayoutX == x && mLayoutY == y && mLayoutWidth == width && mLayoutHeight == height) { + return null; + } + + mLayoutX = x; + mLayoutY = y; + mLayoutWidth = width; + mLayoutHeight = height; + + return OnLayoutEvent.obtain(getReactTag(), x, y, width, height); + } + /* package */ final boolean mountsToView() { return mDrawView != null; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java index e1482a667..f92c4a704 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java @@ -401,13 +401,14 @@ import com.facebook.react.uimanager.events.EventDispatcher; // notify JS about layout event if requested if (node.shouldNotifyOnLayout()) { - mOnLayoutEvents.add( - OnLayoutEvent.obtain( - node.getReactTag(), - (int) roundedLeft, - (int) roundedTop, - (int) (roundedRight - roundedLeft), - (int) (roundedBottom - roundedTop))); + OnLayoutEvent layoutEvent = node.obtainLayoutEvent( + Math.round(node.getLayoutX()), + Math.round(node.getLayoutY()), + (int) (roundedRight - roundedLeft), + (int) (roundedBottom - roundedTop)); + if (layoutEvent != null) { + mOnLayoutEvents.add(layoutEvent); + } } if (node.clipToBounds()) {