From 760a2fc79aae8360443fff5f7b6d720ea6b0c0b5 Mon Sep 17 00:00:00 2001 From: Pawel Sienkowski Date: Fri, 13 Nov 2015 08:25:16 -0800 Subject: [PATCH] Prevent RCTRootView delegate call Reviewed By: javache Differential Revision: D2631582 fb-gh-sync-id: 409d439eb1dc8c7723892477dfaf58aa85c664b5 --- React/Base/RCTRootView.m | 16 +++++++++++++--- React/Base/RCTRootViewDelegate.h | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index e668e5208..fb9116d62 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -237,10 +237,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (void)setIntrinsicSize:(CGSize)intrinsicSize { - if (!CGSizeEqualToSize(_intrinsicSize, intrinsicSize)) { - _intrinsicSize = intrinsicSize; - [_delegate rootViewDidChangeIntrinsicSize:self]; + BOOL oldSizeHasAZeroDimension = _intrinsicSize.height == 0 || _intrinsicSize.width == 0; + BOOL newSizeHasAZeroDimension = intrinsicSize.height == 0 || intrinsicSize.width == 0; + BOOL bothSizesHaveAZeroDimension = oldSizeHasAZeroDimension && newSizeHasAZeroDimension; + + BOOL sizesAreEqual = CGSizeEqualToSize(_intrinsicSize, intrinsicSize); + + _intrinsicSize = intrinsicSize; + + // Don't notify the delegate if the content remains invisible or its size has not changed + if (bothSizesHaveAZeroDimension || sizesAreEqual) { + return; } + + [_delegate rootViewDidChangeIntrinsicSize:self]; } - (NSNumber *)reactTag diff --git a/React/Base/RCTRootViewDelegate.h b/React/Base/RCTRootViewDelegate.h index 61cab6fbf..92d71b7d0 100644 --- a/React/Base/RCTRootViewDelegate.h +++ b/React/Base/RCTRootViewDelegate.h @@ -13,7 +13,8 @@ @protocol RCTRootViewDelegate /** - * Called after the root view's content is updated to a new size. + * Called after the root view's content is updated to a new size. The method is not called + * when both old size and new size have a dimension that equals to zero. * * The delegate can use this callback to appropriately resize the root view frame to fit the new * content view size. The view will not resize itself. The new content size is available via the