Setting availableSize for RCTRootShadowView on earlier stage

Summary:
Moving setting `availableSize` for `RCTRootShadowView` on earlier stage allows to prevent situations where `availableSize` is not specified yet, but Yoga layout is already happening.
Because `availableSize` equals {infinity, infinity} by default (in this case), Yoga returns a lot of nodes with infinit metrics, which confises UIKit.

Reviewed By: mmmulani

Differential Revision: D4672170

fbshipit-source-id: f9d8c84799dcbdb6b9230ddef6284d84df268833
This commit is contained in:
Valentin Shergin 2017-03-08 18:45:28 -08:00 committed by Facebook Github Bot
parent 1269f1ef4e
commit 264d60b979
4 changed files with 16 additions and 13 deletions

View File

@ -22,6 +22,7 @@
@property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler; @property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler;
@property (nonatomic, assign) BOOL passThroughTouches; @property (nonatomic, assign) BOOL passThroughTouches;
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility; @property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
@property (nonatomic, readonly) CGSize availableSize;
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge bridge:(RCTBridge *)bridge

View File

@ -72,20 +72,22 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
[self setNeedsLayout]; [self setNeedsLayout];
} }
- (CGSize)availableSize
{
CGSize size = self.bounds.size;
return CGSizeMake(
_sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? INFINITY : size.width,
_sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? INFINITY : size.height
);
}
- (void)updateAvailableSize - (void)updateAvailableSize
{ {
if (!self.reactTag || !_bridge.isValid) { if (!self.reactTag || !_bridge.isValid) {
return; return;
} }
CGSize size = self.bounds.size; [_bridge.uiManager setAvailableSize:self.availableSize forRootView:self];
CGSize availableSize =
CGSizeMake(
_sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? INFINITY : size.width,
_sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? INFINITY : size.height
);
[_bridge.uiManager setAvailableSize:availableSize forRootView:self];
} }
- (void)setBackgroundColor:(UIColor *)backgroundColor - (void)setBackgroundColor:(UIColor *)backgroundColor

View File

@ -27,6 +27,7 @@
#import "RCTModuleData.h" #import "RCTModuleData.h"
#import "RCTModuleMethod.h" #import "RCTModuleMethod.h"
#import "RCTProfile.h" #import "RCTProfile.h"
#import "RCTRootContentView.h"
#import "RCTRootShadowView.h" #import "RCTRootShadowView.h"
#import "RCTRootViewInternal.h" #import "RCTRootViewInternal.h"
#import "RCTScrollableProtocol.h" #import "RCTScrollableProtocol.h"
@ -381,7 +382,7 @@ dispatch_queue_t RCTGetUIManagerQueue(void)
return RCTGetUIManagerQueue(); return RCTGetUIManagerQueue();
} }
- (void)registerRootView:(UIView *)rootView - (void)registerRootView:(RCTRootContentView *)rootView
{ {
RCTAssertMainQueue(); RCTAssertMainQueue();
@ -393,6 +394,8 @@ dispatch_queue_t RCTGetUIManagerQueue(void)
RCTAssert(existingView == nil || existingView == rootView, RCTAssert(existingView == nil || existingView == rootView,
@"Expect all root views to have unique tag. Added %@ twice", reactTag); @"Expect all root views to have unique tag. Added %@ twice", reactTag);
CGSize availableSize = rootView.availableSize;
// Register view // Register view
_viewRegistry[reactTag] = rootView; _viewRegistry[reactTag] = rootView;
@ -403,6 +406,7 @@ dispatch_queue_t RCTGetUIManagerQueue(void)
} }
RCTRootShadowView *shadowView = [RCTRootShadowView new]; RCTRootShadowView *shadowView = [RCTRootShadowView new];
shadowView.availableSize = availableSize;
shadowView.reactTag = reactTag; shadowView.reactTag = reactTag;
shadowView.backgroundColor = rootView.backgroundColor; shadowView.backgroundColor = rootView.backgroundColor;
shadowView.viewName = NSStringFromClass([rootView class]); shadowView.viewName = NSStringFromClass([rootView class]);

View File

@ -13,10 +13,6 @@
@implementation RCTRootShadowView @implementation RCTRootShadowView
/**
* Init the RCTRootShadowView with RTL status.
* Returns a RTL CSS layout if isRTL is true (Default is LTR CSS layout).
*/
- (instancetype)init - (instancetype)init
{ {
self = [super init]; self = [super init];