2017-11-08 00:10:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-11-08 00:10:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTSurfaceRootShadowView.h"
|
|
|
|
|
|
|
|
#import "RCTI18nUtil.h"
|
2018-01-08 02:21:43 +00:00
|
|
|
#import "RCTShadowView+Layout.h"
|
|
|
|
#import "RCTUIManagerUtils.h"
|
2017-11-08 00:10:55 +00:00
|
|
|
|
|
|
|
@implementation RCTSurfaceRootShadowView {
|
|
|
|
CGSize _intrinsicSize;
|
|
|
|
BOOL _isRendered;
|
|
|
|
BOOL _isLaidOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
self.viewName = @"RCTSurfaceRootView";
|
|
|
|
_baseDirection = [[RCTI18nUtil sharedInstance] isRTL] ? YGDirectionRTL : YGDirectionLTR;
|
|
|
|
_minimumSize = CGSizeZero;
|
2018-01-08 02:21:43 +00:00
|
|
|
_maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
|
2017-11-08 00:10:55 +00:00
|
|
|
|
|
|
|
self.alignSelf = YGAlignStretch;
|
|
|
|
self.flex = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
|
|
|
|
{
|
|
|
|
[super insertReactSubview:subview atIndex:atIndex];
|
|
|
|
if (!_isRendered) {
|
|
|
|
[_delegate rootShadowViewDidStartRendering:self];
|
|
|
|
_isRendered = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 08:04:16 +00:00
|
|
|
- (void)layoutWithAffectedShadowViews:(NSHashTable<RCTShadowView *> *)affectedShadowViews
|
2017-11-08 00:10:55 +00:00
|
|
|
{
|
2018-02-12 08:04:16 +00:00
|
|
|
NSHashTable<NSString *> *other = [NSHashTable new];
|
2017-11-08 00:10:55 +00:00
|
|
|
|
2018-02-12 08:04:16 +00:00
|
|
|
RCTLayoutContext layoutContext = {};
|
|
|
|
layoutContext.absolutePosition = CGPointZero;
|
|
|
|
layoutContext.affectedShadowViews = affectedShadowViews;
|
|
|
|
layoutContext.other = other;
|
2017-11-08 00:10:55 +00:00
|
|
|
|
2018-02-12 08:04:16 +00:00
|
|
|
[self layoutWithMinimumSize:_minimumSize
|
|
|
|
maximumSize:_maximumSize
|
|
|
|
layoutDirection:RCTUIKitLayoutDirectionFromYogaLayoutDirection(_baseDirection)
|
|
|
|
layoutContext:layoutContext];
|
2017-11-08 00:10:55 +00:00
|
|
|
|
2018-02-12 08:04:16 +00:00
|
|
|
self.intrinsicSize = self.layoutMetrics.frame.size;
|
2017-11-08 00:10:55 +00:00
|
|
|
|
|
|
|
if (_isRendered && !_isLaidOut) {
|
|
|
|
[_delegate rootShadowViewDidStartLayingOut:self];
|
|
|
|
_isLaidOut = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize
|
|
|
|
{
|
|
|
|
if (CGSizeEqualToSize(minimumSize, _minimumSize) &&
|
|
|
|
CGSizeEqualToSize(maximumSize, _maximumSize)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_maximumSize = maximumSize;
|
|
|
|
_minimumSize = minimumSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIntrinsicSize:(CGSize)intrinsicSize
|
|
|
|
{
|
|
|
|
if (CGSizeEqualToSize(_intrinsicSize, intrinsicSize)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_intrinsicSize = intrinsicSize;
|
|
|
|
|
|
|
|
[_delegate rootShadowView:self didChangeIntrinsicSize:intrinsicSize];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGSize)intrinsicSize
|
|
|
|
{
|
|
|
|
return _intrinsicSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|