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
This commit is contained in:
Valentin Shergin 2018-05-08 22:56:27 -07:00 committed by Facebook Github Bot
parent 20e88e9ac4
commit 67dbcbd57e
5 changed files with 79 additions and 7 deletions

View File

@ -9,6 +9,8 @@
#import <memory> #import <memory>
#import <React/RCTPrimitives.h> #import <React/RCTPrimitives.h>
#import <fabric/core/LayoutConstraints.h>
#import <fabric/core/LayoutContext.h>
#import <fabric/uimanager/FabricUIManager.h> #import <fabric/uimanager/FabricUIManager.h>
#import <fabric/uimanager/TreeMutationInstruction.h> #import <fabric/uimanager/TreeMutationInstruction.h>
@ -38,6 +40,14 @@ NS_ASSUME_NONNULL_BEGIN
- (void)unregisterRootTag:(ReactTag)tag; - (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 @end
@interface RCTScheduler (Deprecated) @interface RCTScheduler (Deprecated)

View File

@ -10,6 +10,8 @@
#import <fabric/uimanager/Scheduler.h> #import <fabric/uimanager/Scheduler.h>
#import <fabric/uimanager/SchedulerDelegate.h> #import <fabric/uimanager/SchedulerDelegate.h>
#import "RCTConversions.h"
using namespace facebook::react; using namespace facebook::react;
class SchedulerDelegateProxy: public SchedulerDelegate { class SchedulerDelegateProxy: public SchedulerDelegate {
@ -61,6 +63,20 @@ private:
_scheduler->unregisterRootTag(tag); _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 @end
@implementation RCTScheduler (Deprecated) @implementation RCTScheduler (Deprecated)

View File

@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
@interface RCTSurfacePresenter (Internal) @interface RCTSurfacePresenter (Surface)
/** /**
* Surface uses those methods to register itself in the Presenter. * Surface uses those methods to register itself in the Presenter.
@ -38,6 +38,19 @@ NS_ASSUME_NONNULL_BEGIN
- (void)registerSurface:(RCTFabricSurface *)surface; - (void)registerSurface:(RCTFabricSurface *)surface;
- (void)unregisterSurface:(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 @end
@interface RCTSurfacePresenter (Deprecated) @interface RCTSurfacePresenter (Deprecated)

View File

@ -19,6 +19,11 @@
#import <React/RCTSurfaceView.h> #import <React/RCTSurfaceView.h>
#import <React/RCTSurfaceView+Internal.h> #import <React/RCTSurfaceView+Internal.h>
#import <fabric/core/LayoutContext.h>
#import <fabric/core/LayoutConstraints.h>
#import "RCTConversions.h"
using namespace facebook::react; using namespace facebook::react;
@interface RCTSurfacePresenter () <RCTSchedulerDelegate, RCTMountingManagerDelegate> @interface RCTSurfacePresenter () <RCTSchedulerDelegate, RCTMountingManagerDelegate>
@ -87,6 +92,34 @@ using namespace facebook::react;
[_surfaceRegistry unregisterSurface:surface]; [_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 - (void)runSurface:(RCTFabricSurface *)surface
{ {
NSDictionary *applicationParameters = @{ NSDictionary *applicationParameters = @{
@ -122,9 +155,6 @@ using namespace facebook::react;
UIView *rootComponentView = [_mountingManager.componentViewRegistry componentViewByTag:rootTag]; UIView *rootComponentView = [_mountingManager.componentViewRegistry componentViewByTag:rootTag];
// FIXME: Remove this.
rootComponentView.frame = CGRectMake(0, 0, 400, 400);
surface.view.rootView = (RCTSurfaceRootView *)rootComponentView; surface.view.rootView = (RCTSurfaceRootView *)rootComponentView;
} }

View File

@ -188,8 +188,9 @@
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize - (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize
maximumSize:(CGSize)maximumSize maximumSize:(CGSize)maximumSize
{ {
// TODO: Not supported yet. return [_surfacePresenter sizeThatFitsMinimumSize:minimumSize
return CGSizeZero; maximumSize:maximumSize
surface:self];
} }
#pragma mark - Size Constraints #pragma mark - Size Constraints
@ -213,7 +214,9 @@
_minimumSize = minimumSize; _minimumSize = minimumSize;
} }
// TODO: Not supported yet. return [_surfacePresenter setMinimumSize:minimumSize
maximumSize:maximumSize
surface:self];
} }
- (CGSize)minimumSize - (CGSize)minimumSize