diff --git a/React/Base/RCTRootView.h b/React/Base/RCTRootView.h index 7f63baa9fd2..fba78ab6ad3 100644 --- a/React/Base/RCTRootView.h +++ b/React/Base/RCTRootView.h @@ -88,12 +88,6 @@ extern NSString *const RCTContentDidAppearNotification; */ @property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility; -/** - * The size of the root view's content. This is set right before the - * rootViewDidChangeIntrinsicSize method of RCTRootViewDelegate is called. - */ -@property (readonly, nonatomic, assign) CGSize intrinsicSize; - /** * The delegate that handles intrinsic size updates. */ @@ -155,3 +149,16 @@ extern NSString *const RCTContentDidAppearNotification; @property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration; @end + +@interface RCTRootView (Deprecated) + +/** + * The intrinsic size of the root view's content. This is set right before the + * `rootViewDidChangeIntrinsicSize` method of `RCTRootViewDelegate` is called. + * This property is deprecated and will be removed in next releases. + * Use UIKit `intrinsicContentSize` propery instead. + */ +@property (readonly, nonatomic, assign) CGSize intrinsicSize +__deprecated_msg("Use `intrinsicContentSize` instead."); + +@end diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 0b5e5dbb6b0..839640a8fbe 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -47,6 +47,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat NSDictionary *_launchOptions; RCTRootContentView *_contentView; BOOL _passThroughTouches; + CGSize _intrinsicContentSize; } - (instancetype)initWithBridge:(RCTBridge *)bridge @@ -153,8 +154,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (CGSize)sizeThatFits:(CGSize)size { return CGSizeMake( - _sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? MIN(_intrinsicSize.width, size.width) : size.width, - _sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? MIN(_intrinsicSize.height, size.height) : size.height + _sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? MIN(_intrinsicContentSize.width, size.width) : size.width, + _sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? MIN(_intrinsicContentSize.height, size.height) : size.height ); } @@ -268,7 +269,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [self insertSubview:_contentView atIndex:0]; if (_sizeFlexibility == RCTRootViewSizeFlexibilityNone) { - self.intrinsicSize = self.bounds.size; + self.intrinsicContentSize = self.bounds.size; } } @@ -323,15 +324,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) } } -- (void)setIntrinsicSize:(CGSize)intrinsicSize +- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize { - BOOL oldSizeHasAZeroDimension = _intrinsicSize.height == 0 || _intrinsicSize.width == 0; - BOOL newSizeHasAZeroDimension = intrinsicSize.height == 0 || intrinsicSize.width == 0; + BOOL oldSizeHasAZeroDimension = _intrinsicContentSize.height == 0 || _intrinsicContentSize.width == 0; + BOOL newSizeHasAZeroDimension = intrinsicContentSize.height == 0 || intrinsicContentSize.width == 0; BOOL bothSizesHaveAZeroDimension = oldSizeHasAZeroDimension && newSizeHasAZeroDimension; - BOOL sizesAreEqual = CGSizeEqualToSize(_intrinsicSize, intrinsicSize); + BOOL sizesAreEqual = CGSizeEqualToSize(_intrinsicContentSize, intrinsicContentSize); - _intrinsicSize = intrinsicSize; + _intrinsicContentSize = intrinsicContentSize; [self invalidateIntrinsicContentSize]; [self.superview setNeedsLayout]; @@ -346,7 +347,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (CGSize)intrinsicContentSize { - return _intrinsicSize; + return _intrinsicContentSize; } - (void)contentViewInvalidated @@ -369,6 +370,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) @end +@implementation RCTRootView (Deprecated) + +- (CGSize)intrinsicSize +{ + RCTLogWarn(@"Calling deprecated `[-RCTRootView intrinsicSize]`."); + return self.intrinsicContentSize; +} + +@end + @implementation RCTUIManager (RCTRootView) - (NSNumber *)allocateRootTag diff --git a/React/Base/RCTRootViewDelegate.h b/React/Base/RCTRootViewDelegate.h index 92d71b7d0e4..d5f6e4885e5 100644 --- a/React/Base/RCTRootViewDelegate.h +++ b/React/Base/RCTRootViewDelegate.h @@ -12,13 +12,20 @@ @class RCTRootView; @protocol RCTRootViewDelegate + /** - * 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. + * Called after the root view's intrinsic content size is changed. * - * 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 - * intrinsicSize propery of the root view. + * 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's frame to fit the new intrinsic content view size, + * but usually it is not necessary because the root view will also call + * `setNeedsLayout` for its superview which in its turn will trigger relayout. + * + * The new intrinsic content size is available via the `intrinsicContentSize` + * propery of the root view. The view will not resize itself. */ - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView; diff --git a/React/Base/RCTRootViewInternal.h b/React/Base/RCTRootViewInternal.h index e9a114a4755..1b3ff7bb7e8 100644 --- a/React/Base/RCTRootViewInternal.h +++ b/React/Base/RCTRootViewInternal.h @@ -18,9 +18,10 @@ @interface RCTRootView () /** - * This setter should be used only by RCTUIManager on react root view size update. + * This setter should be used only by RCTUIManager on react root view + * intrinsic content size update. */ -@property (readwrite, nonatomic, assign) CGSize intrinsicSize; +@property (readwrite, nonatomic, assign) CGSize intrinsicContentSize; /** * TV remote gesture recognizers diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index f582cb6aea2..288f3d61e1b 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -607,7 +607,7 @@ dispatch_queue_t RCTGetUIManagerQueue(void) RCTAssert(view != nil, @"view (for ID %@) not found", reactTag); RCTRootView *rootView = (RCTRootView *)[view superview]; - rootView.intrinsicSize = contentSize; + rootView.intrinsicContentSize = contentSize; }); } }