Skip to content

Commit 432868b

Browse files
Peter Arganyfacebook-github-bot
Peter Argany
authored andcommittedApr 8, 2020
Add minimumSize to RCTRootView & RCTRootShadowView
Summary: This adds a `minimumSize` property to RCTRootView, and forwards any changes to it's shadow view. This **does not** change any default behaviour, as the default minimum size is `CGSizeZero` before & after this diff. Changelog: [iOS][Internal] Add minimumSize to RCTRootView & RCTRootShadowView Reviewed By: RSNara Differential Revision: D20905456 fbshipit-source-id: a03f880e782891f60ef86b9c898965e05a5e796e
1 parent fd5de50 commit 432868b

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed
 

‎React/Base/RCTRootView.h

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ extern
9494
*/
9595
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
9696

97+
/*
98+
* The minimum size of the root view, defaults to CGSizeZero.
99+
*/
100+
@property (nonatomic, assign) CGSize minimumSize;
101+
97102
/**
98103
* The delegate that handles intrinsic size updates.
99104
*/

‎React/Base/RCTRootView.m

+19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "RCTPerformanceLogger.h"
2222
#import "RCTProfile.h"
2323
#import "RCTRootContentView.h"
24+
#import "RCTRootShadowView.h"
2425
#import "RCTTouchHandler.h"
2526
#import "RCTUIManager.h"
2627
#import "RCTUIManagerUtils.h"
@@ -71,6 +72,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
7172
_loadingViewFadeDelay = 0.25;
7273
_loadingViewFadeDuration = 0.25;
7374
_sizeFlexibility = RCTRootViewSizeFlexibilityNone;
75+
_minimumSize = CGSizeZero;
7476

7577
[[NSNotificationCenter defaultCenter] addObserver:self
7678
selector:@selector(bridgeDidReload)
@@ -167,6 +169,23 @@ - (void)layoutSubviews
167169
_loadingView.center = (CGPoint){CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)};
168170
}
169171

172+
- (void)setMinimumSize:(CGSize)minimumSize
173+
{
174+
if (CGSizeEqualToSize(_minimumSize, minimumSize)) {
175+
return;
176+
}
177+
_minimumSize = minimumSize;
178+
__block NSNumber *tag = self.reactTag;
179+
__weak typeof(self) weakSelf = self;
180+
RCTExecuteOnUIManagerQueue(^{
181+
__strong typeof(self) strongSelf = weakSelf;
182+
if (strongSelf && strongSelf->_bridge.isValid) {
183+
RCTRootShadowView *shadowView = (RCTRootShadowView *)[strongSelf->_bridge.uiManager shadowViewForReactTag:tag];
184+
shadowView.minimumSize = minimumSize;
185+
}
186+
});
187+
}
188+
170189
- (UIViewController *)reactViewController
171190
{
172191
return _reactViewController ?: [super reactViewController];

‎React/Views/RCTRootShadowView.h

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
@interface RCTRootShadowView : RCTShadowView
1212

13+
/**
14+
* Minimum size to layout all views.
15+
* Defaults to CGSizeZero
16+
*/
17+
@property (nonatomic, assign) CGSize minimumSize;
18+
1319
/**
1420
* Available size to layout all views.
1521
* Defaults to {INFINITY, INFINITY}

‎React/Views/RCTRootShadowView.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ - (instancetype)init
1616
{
1717
if (self = [super init]) {
1818
_baseDirection = [[RCTI18nUtil sharedInstance] isRTL] ? YGDirectionRTL : YGDirectionLTR;
19+
_minimumSize = CGSizeZero;
1920
_availableSize = CGSizeMake(INFINITY, INFINITY);
2021
}
2122

@@ -31,7 +32,7 @@ - (void)layoutWithAffectedShadowViews:(NSHashTable<RCTShadowView *> *)affectedSh
3132
layoutContext.affectedShadowViews = affectedShadowViews;
3233
layoutContext.other = other;
3334

34-
[self layoutWithMinimumSize:CGSizeZero
35+
[self layoutWithMinimumSize:_minimumSize
3536
maximumSize:_availableSize
3637
layoutDirection:RCTUIKitLayoutDirectionFromYogaLayoutDirection(_baseDirection)
3738
layoutContext:layoutContext];

0 commit comments

Comments
 (0)
Please sign in to comment.