From 67dbcbd57e8e69a397faaab8daffd61f27b90db4 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 8 May 2018 22:56:27 -0700 Subject: [PATCH] Fabric: Wiring layout pipeline between Surface and ShadowTree Summary: The layout pipeline is quite long: UIKit <-> Surface <-> SurfacePresenter <-> [RCTScheduler <|-|> Scheduler] <-> ShadowTree <-> RootShadowNode <-> YogaNode. Reviewed By: mdvacca Differential Revision: D7857048 fbshipit-source-id: 06c92ef1639465d17e2489667f99d0114b80dcff --- React/Fabric/RCTScheduler.h | 10 +++++++ React/Fabric/RCTScheduler.mm | 16 +++++++++++ React/Fabric/RCTSurfacePresenter.h | 15 +++++++++- React/Fabric/RCTSurfacePresenter.mm | 36 ++++++++++++++++++++++-- React/Fabric/Surface/RCTFabricSurface.mm | 9 ++++-- 5 files changed, 79 insertions(+), 7 deletions(-) diff --git a/React/Fabric/RCTScheduler.h b/React/Fabric/RCTScheduler.h index 1f1e36706..e6a730b78 100644 --- a/React/Fabric/RCTScheduler.h +++ b/React/Fabric/RCTScheduler.h @@ -9,6 +9,8 @@ #import #import +#import +#import #import #import @@ -38,6 +40,14 @@ NS_ASSUME_NONNULL_BEGIN - (void)unregisterRootTag:(ReactTag)tag; +- (CGSize)measureWithLayoutConstraints:(facebook::react::LayoutConstraints)layoutConstraints + layoutContext:(facebook::react::LayoutContext)layoutContext + rootTag:(ReactTag)rootTag; + +- (void)constraintLayoutWithLayoutConstraints:(facebook::react::LayoutConstraints)layoutConstraints + layoutContext:(facebook::react::LayoutContext)layoutContext + rootTag:(ReactTag)rootTag; + @end @interface RCTScheduler (Deprecated) diff --git a/React/Fabric/RCTScheduler.mm b/React/Fabric/RCTScheduler.mm index 0fe06175e..fcd1a9d8b 100644 --- a/React/Fabric/RCTScheduler.mm +++ b/React/Fabric/RCTScheduler.mm @@ -10,6 +10,8 @@ #import #import +#import "RCTConversions.h" + using namespace facebook::react; class SchedulerDelegateProxy: public SchedulerDelegate { @@ -61,6 +63,20 @@ private: _scheduler->unregisterRootTag(tag); } +- (CGSize)measureWithLayoutConstraints:(LayoutConstraints)layoutConstraints + layoutContext:(LayoutContext)layoutContext + rootTag:(ReactTag)rootTag +{ + return RCTCGSizeFromSize(_scheduler->measure(rootTag, layoutConstraints, layoutContext)); +} + +- (void)constraintLayoutWithLayoutConstraints:(LayoutConstraints)layoutConstraints + layoutContext:(LayoutContext)layoutContext + rootTag:(ReactTag)rootTag +{ + _scheduler->constraintLayout(rootTag, layoutConstraints, layoutContext); +} + @end @implementation RCTScheduler (Deprecated) diff --git a/React/Fabric/RCTSurfacePresenter.h b/React/Fabric/RCTSurfacePresenter.h index d99133d59..65456cbf5 100644 --- a/React/Fabric/RCTSurfacePresenter.h +++ b/React/Fabric/RCTSurfacePresenter.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN @end -@interface RCTSurfacePresenter (Internal) +@interface RCTSurfacePresenter (Surface) /** * Surface uses those methods to register itself in the Presenter. @@ -38,6 +38,19 @@ NS_ASSUME_NONNULL_BEGIN - (void)registerSurface:(RCTFabricSurface *)surface; - (void)unregisterSurface:(RCTFabricSurface *)surface; +/** + * Measures the Surface with given constraints. + */ +- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize + maximumSize:(CGSize)maximumSize + surface:(RCTFabricSurface *)surface; + +/** + * Sets `minimumSize` and `maximumSize` layout constraints for the Surface. + */ +- (void)setMinimumSize:(CGSize)minimumSize + maximumSize:(CGSize)maximumSize + surface:(RCTFabricSurface *)surface; @end @interface RCTSurfacePresenter (Deprecated) diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 8e88548c8..1e0164f2b 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -19,6 +19,11 @@ #import #import +#import +#import + +#import "RCTConversions.h" + using namespace facebook::react; @interface RCTSurfacePresenter () @@ -87,6 +92,34 @@ using namespace facebook::react; [_surfaceRegistry unregisterSurface:surface]; } +- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize + maximumSize:(CGSize)maximumSize + surface:(RCTFabricSurface *)surface +{ + LayoutContext layoutContext; + LayoutConstraints layoutConstraints = {}; + layoutConstraints.minimumSize = RCTSizeFromCGSize(minimumSize); + layoutConstraints.maximumSize = RCTSizeFromCGSize(maximumSize); + + return [_scheduler measureWithLayoutConstraints:layoutConstraints + layoutContext:layoutContext + rootTag:surface.rootTag]; +} + +- (void)setMinimumSize:(CGSize)minimumSize + maximumSize:(CGSize)maximumSize + surface:(RCTFabricSurface *)surface +{ + LayoutContext layoutContext; + LayoutConstraints layoutConstraints = {}; + layoutConstraints.minimumSize = RCTSizeFromCGSize(minimumSize); + layoutConstraints.maximumSize = RCTSizeFromCGSize(maximumSize); + + [_scheduler constraintLayoutWithLayoutConstraints:layoutConstraints + layoutContext:layoutContext + rootTag:surface.rootTag]; +} + - (void)runSurface:(RCTFabricSurface *)surface { NSDictionary *applicationParameters = @{ @@ -122,9 +155,6 @@ using namespace facebook::react; UIView *rootComponentView = [_mountingManager.componentViewRegistry componentViewByTag:rootTag]; - // FIXME: Remove this. - rootComponentView.frame = CGRectMake(0, 0, 400, 400); - surface.view.rootView = (RCTSurfaceRootView *)rootComponentView; } diff --git a/React/Fabric/Surface/RCTFabricSurface.mm b/React/Fabric/Surface/RCTFabricSurface.mm index 060d05675..3028a204e 100644 --- a/React/Fabric/Surface/RCTFabricSurface.mm +++ b/React/Fabric/Surface/RCTFabricSurface.mm @@ -188,8 +188,9 @@ - (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize { - // TODO: Not supported yet. - return CGSizeZero; + return [_surfacePresenter sizeThatFitsMinimumSize:minimumSize + maximumSize:maximumSize + surface:self]; } #pragma mark - Size Constraints @@ -213,7 +214,9 @@ _minimumSize = minimumSize; } - // TODO: Not supported yet. + return [_surfacePresenter setMinimumSize:minimumSize + maximumSize:maximumSize + surface:self]; } - (CGSize)minimumSize