RCTSurfaceRootShadowView.m
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "RCTSurfaceRootShadowView.h"
#import "RCTI18nUtil.h"
#import "RCTShadowView+Layout.h"
#import "RCTUIManagerUtils.h"
@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;
_maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
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;
}
}
- (void)calculateLayoutWithMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize
{
YGNodeRef yogaNode = self.yogaNode;
YGNodeStyleSetMinWidth(yogaNode, RCTYogaFloatFromCoreGraphicsFloat(minimumSize.width));
YGNodeStyleSetMinHeight(yogaNode, RCTYogaFloatFromCoreGraphicsFloat(minimumSize.height));
YGNodeCalculateLayout(
self.yogaNode,
RCTYogaFloatFromCoreGraphicsFloat(maximumSize.width),
RCTYogaFloatFromCoreGraphicsFloat(maximumSize.height),
_baseDirection
);
}
- (NSSet<RCTShadowView *> *)collectViewsWithUpdatedFrames
{
[self calculateLayoutWithMinimumSize:_minimumSize
maximumSize:_maximumSize];
NSMutableSet<RCTShadowView *> *viewsWithNewFrame = [NSMutableSet set];
[self applyLayoutNode:self.yogaNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:CGPointZero];
self.intrinsicSize = self.frame.size;
if (_isRendered && !_isLaidOut) {
[_delegate rootShadowViewDidStartLayingOut:self];
_isLaidOut = YES;
}
return viewsWithNewFrame;
}
- (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