From 98798a06aebe87fdde7643143a9e5acd7f8c99ae Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 13 Mar 2017 13:19:55 -0700 Subject: [PATCH] More accurate implementation of `RCTRootView`'s `sizeThatFits:` Reviewed By: mmmulani Differential Revision: D4672788 fbshipit-source-id: 780487f2264916349e32785808a93ed6f957e471 --- React/Base/RCTRootView.m | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 839640a8f..db1ed0234 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -153,10 +153,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (CGSize)sizeThatFits:(CGSize)size { - return CGSizeMake( - _sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? MIN(_intrinsicContentSize.width, size.width) : size.width, - _sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? MIN(_intrinsicContentSize.height, size.height) : size.height - ); + CGSize fitSize = _intrinsicContentSize; + CGSize currentSize = self.bounds.size; + + // Following the current `size` and current `sizeFlexibility` policy. + fitSize = CGSizeMake( + _sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? fitSize.width : currentSize.width, + _sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? fitSize.height : currentSize.height + ); + + // Following the given size constraints. + fitSize = CGSizeMake( + MIN(size.width, fitSize.width), + MIN(size.height, fitSize.height) + ); + + return fitSize; } - (void)layoutSubviews