diff --git a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm index ecd24d7e226..50a3346d14a 100644 --- a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm +++ b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm @@ -33,11 +33,10 @@ RCTSurfaceBackedComponentState *state = scope.state(); if (state.surface == nil || ![state.surface.moduleName isEqualToString:moduleName]) { - RCTSurface *surface = - [[RCTSurface alloc] initWithBridge:bridge - moduleName:moduleName - initialProperties:properties]; - + id surface = [[RCTSurface alloc] initWithBridge:bridge + moduleName:moduleName + initialProperties:properties]; + [surface start]; state = [RCTSurfaceBackedComponentState newWithSurface:surface]; diff --git a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.h b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.h index d68a6b450d2..b595e41872d 100644 --- a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.h +++ b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.h @@ -7,12 +7,12 @@ #import -@class RCTSurface; +@protocol RCTSurfaceProtocol; @interface RCTSurfaceBackedComponentState: NSObject -@property (atomic, readonly, strong) RCTSurface *surface; +@property (atomic, readonly, strong) id surface; -+ (instancetype)newWithSurface:(RCTSurface *)surface; ++ (instancetype)newWithSurface:(id)surface; @end diff --git a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.mm b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.mm index 649cea4af31..224017da62b 100644 --- a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.mm +++ b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.mm @@ -7,16 +7,14 @@ #import "RCTSurfaceBackedComponentState.h" -#import - @implementation RCTSurfaceBackedComponentState -+ (instancetype)newWithSurface:(RCTSurface *)surface ++ (instancetype)newWithSurface:(id)surface { return [[self alloc] initWithSurface:surface]; } -- (instancetype)initWithSurface:(RCTSurface *)surface +- (instancetype)initWithSurface:(id)surface { if (self = [super init]) { _surface = surface; diff --git a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent+Internal.h b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent+Internal.h index 41af830ec75..b3d3d4616ae 100644 --- a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent+Internal.h +++ b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent+Internal.h @@ -8,12 +8,11 @@ #import #import -@class RCTSurface; @class RCTSurfaceHostingComponentState; @interface RCTSurfaceHostingComponent () -@property (nonatomic, strong, readonly) RCTSurface *surface; +@property (nonatomic, strong, readonly) id surface; @property (nonatomic, retain, readonly) RCTSurfaceHostingComponentState *state; @property (nonatomic, assign, readonly) RCTSurfaceHostingComponentOptions options; diff --git a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.h b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.h index f2859cf0313..1bd6f4667d3 100644 --- a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.h +++ b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.h @@ -7,14 +7,13 @@ #import #import - -@class RCTSurface; +#import /** * ComponentKit component represents given Surface instance. */ @interface RCTSurfaceHostingComponent : CKComponent -+ (instancetype)newWithSurface:(RCTSurface *)surface options:(RCTSurfaceHostingComponentOptions)options; ++ (instancetype)newWithSurface:(id)surface options:(RCTSurfaceHostingComponentOptions)options; @end diff --git a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.mm b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.mm index 80035fc0eac..41db84fe67d 100644 --- a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.mm +++ b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponent.mm @@ -29,7 +29,7 @@ return [RCTSurfaceHostingComponentState new]; } -+ (instancetype)newWithSurface:(RCTSurface *)surface options:(RCTSurfaceHostingComponentOptions)options ++ (instancetype)newWithSurface:(id)surface options:(RCTSurfaceHostingComponentOptions)options { CKComponentScope scope(self, surface); @@ -76,9 +76,11 @@ // Just in case of the very first building pass, we give React Native a chance // to prepare its internals for coming synchronous measuring. - [_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialLayout + if ([_surface isKindOfClass:[RCTSurface class]]) { + [(RCTSurface *)_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialLayout timeout:_options.synchronousLayoutingTimeout]; - + } + CGSize fittingSize = CGSizeZero; if (_surface.stage & RCTSurfaceStageSurfaceDidInitialLayout) { fittingSize = [_surface sizeThatFitsMinimumSize:constrainedSize.min diff --git a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm index 24d83b48d22..58100978465 100644 --- a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm +++ b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm @@ -21,7 +21,7 @@ @end @implementation RCTSurfaceHostingComponentController { - RCTSurface *_surface; + id _surface; } - (instancetype)initWithComponent:(RCTSurfaceHostingComponent *)component @@ -64,7 +64,7 @@ - (void)updateSurfaceWithComponent:(RCTSurfaceHostingComponent *)component { // Updating `surface` - RCTSurface *const surface = component.surface; + id const surface = component.surface; if (surface != _surface) { if (_surface.delegate == self) { _surface.delegate = nil;