mirror of
https://github.com/status-im/react-native.git
synced 2025-02-05 22:23:37 +00:00
Android shouldn't dispatch onLayout if frame didn't change
Summary: Fixes [#7202 Android Redundant onLayout event](https://github.com/facebook/react-native/issues/7202) Closes https://github.com/facebook/react-native/pull/7250 Differential Revision: D4104066 Pulled By: mkonicek fbshipit-source-id: 383efdb4b4881aa7d7e508d61c9c01165bcf7bb6
This commit is contained in:
parent
9833e1bd34
commit
d4b8ae7a8a
@ -237,7 +237,10 @@ public class ReactShadowNode extends CSSNodeDEPRECATED {
|
|||||||
public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
|
public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void dispatchUpdates(
|
/**
|
||||||
|
* @return true if layout (position or dimensions) changed, false otherwise.
|
||||||
|
*/
|
||||||
|
/* package */ boolean dispatchUpdates(
|
||||||
float absoluteX,
|
float absoluteX,
|
||||||
float absoluteY,
|
float absoluteY,
|
||||||
UIViewOperationQueue uiViewOperationQueue,
|
UIViewOperationQueue uiViewOperationQueue,
|
||||||
@ -247,12 +250,27 @@ public class ReactShadowNode extends CSSNodeDEPRECATED {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasNewLayout()) {
|
if (hasNewLayout()) {
|
||||||
mAbsoluteLeft = Math.round(absoluteX + getLayoutX());
|
float newLeft = Math.round(absoluteX + getLayoutX());
|
||||||
mAbsoluteTop = Math.round(absoluteY + getLayoutY());
|
float newTop = Math.round(absoluteY + getLayoutY());
|
||||||
mAbsoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth());
|
float newRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth());
|
||||||
mAbsoluteBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight());
|
float newBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight());
|
||||||
|
|
||||||
|
if (newLeft == mAbsoluteLeft &&
|
||||||
|
newRight == mAbsoluteRight &&
|
||||||
|
newTop == mAbsoluteTop &&
|
||||||
|
newBottom == mAbsoluteBottom) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mAbsoluteLeft = newLeft;
|
||||||
|
mAbsoluteTop = newTop;
|
||||||
|
mAbsoluteRight = newRight;
|
||||||
|
mAbsoluteBottom = newBottom;
|
||||||
|
|
||||||
nativeViewHierarchyOptimizer.handleUpdateLayout(this);
|
nativeViewHierarchyOptimizer.handleUpdateLayout(this);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,14 +789,16 @@ public class UIImplementation {
|
|||||||
|
|
||||||
int tag = cssNode.getReactTag();
|
int tag = cssNode.getReactTag();
|
||||||
if (!mShadowNodeRegistry.isRootNode(tag)) {
|
if (!mShadowNodeRegistry.isRootNode(tag)) {
|
||||||
cssNode.dispatchUpdates(
|
boolean frameDidChange = cssNode.dispatchUpdates(
|
||||||
absoluteX,
|
absoluteX,
|
||||||
absoluteY,
|
absoluteY,
|
||||||
mOperationsQueue,
|
mOperationsQueue,
|
||||||
mNativeViewHierarchyOptimizer);
|
mNativeViewHierarchyOptimizer);
|
||||||
|
|
||||||
// notify JS about layout event if requested
|
// Notify JS about layout event if requested
|
||||||
if (cssNode.shouldNotifyOnLayout()) {
|
// and if the position or dimensions actually changed
|
||||||
|
// (consistent with iOS).
|
||||||
|
if (frameDidChange && cssNode.shouldNotifyOnLayout()) {
|
||||||
mEventDispatcher.dispatchEvent(
|
mEventDispatcher.dispatchEvent(
|
||||||
OnLayoutEvent.obtain(
|
OnLayoutEvent.obtain(
|
||||||
tag,
|
tag,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user