RCTRootView's `intrinsicSize` property was deprecated in favour of `intrinsicContentSize`

Summary:
Nothing actually changed except the deprecation.
Existed `intrinsicSize` was already implemented as `intrinsicContentSize` and this change only removes redundancy.
Moreover, we do not need `rootViewDidChangeIntrinsicSize` delegate method anymore; this is now mentioned in its description.

Depends on D4577890

Reviewed By: mmmulani

Differential Revision: D4589344

fbshipit-source-id: 16ed62cbf6bf72678bd7f7c11d4812c5aa36c743
This commit is contained in:
Valentin Shergin 2017-02-27 10:47:30 -08:00 committed by Facebook Github Bot
parent 9dccff0eda
commit e7cc1bcbba
5 changed files with 49 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -12,13 +12,20 @@
@class RCTRootView;
@protocol RCTRootViewDelegate <NSObject>
/**
* 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;

View File

@ -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

View File

@ -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;
});
}
}