Skip to content

Commit

Permalink
More accurate implementation of RCTRootView's sizeThatFits:
Browse files Browse the repository at this point in the history
Reviewed By: mmmulani

Differential Revision: D4672788

fbshipit-source-id: 780487f2264916349e32785808a93ed6f957e471
  • Loading branch information
shergin authored and facebook-github-bot committed Mar 13, 2017
1 parent 2976aa1 commit 98798a0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,22 @@ - (void)setPassThroughTouches:(BOOL)passThroughTouches

- (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
Expand Down

0 comments on commit 98798a0

Please sign in to comment.