mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
3/n (Easy) Make ComponentKit hosting RN use RCTSurfaceProtocol instead of Paper's RCTSurface
Summary: Changelog: [iOS][Internal] Refactor: Make ComponentKit hosting ReactNative use RCTSurfaceProtocol instead of Paper's RCTSurface Replace RCTSurface with id<RCTSurfaceProtocol>, because both RCTFabricSurface and RCTSurface conforms to RCTSurfaceProtocol. Reviewed By: RSNara Differential Revision: D35163498 fbshipit-source-id: ba54c9bf5949313cd501bd185975fe96d4770961
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1874c81003
commit
32fa5d6025
@@ -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<RCTSurfaceProtocol> surface = [[RCTSurface alloc] initWithBridge:bridge
|
||||
moduleName:moduleName
|
||||
initialProperties:properties];
|
||||
|
||||
[surface start];
|
||||
|
||||
state = [RCTSurfaceBackedComponentState newWithSurface:surface];
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class RCTSurface;
|
||||
@protocol RCTSurfaceProtocol;
|
||||
|
||||
@interface RCTSurfaceBackedComponentState: NSObject
|
||||
|
||||
@property (atomic, readonly, strong) RCTSurface *surface;
|
||||
@property (atomic, readonly, strong) id<RCTSurfaceProtocol> surface;
|
||||
|
||||
+ (instancetype)newWithSurface:(RCTSurface *)surface;
|
||||
+ (instancetype)newWithSurface:(id<RCTSurfaceProtocol>)surface;
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,16 +7,14 @@
|
||||
|
||||
#import "RCTSurfaceBackedComponentState.h"
|
||||
|
||||
#import <React/RCTSurface.h>
|
||||
|
||||
@implementation RCTSurfaceBackedComponentState
|
||||
|
||||
+ (instancetype)newWithSurface:(RCTSurface *)surface
|
||||
+ (instancetype)newWithSurface:(id<RCTSurfaceProtocol>)surface
|
||||
{
|
||||
return [[self alloc] initWithSurface:surface];
|
||||
}
|
||||
|
||||
- (instancetype)initWithSurface:(RCTSurface *)surface
|
||||
- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_surface = surface;
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
#import <RCTSurfaceHostingComponent/RCTSurfaceHostingComponent.h>
|
||||
#import <RCTSurfaceHostingComponent/RCTSurfaceHostingComponentOptions.h>
|
||||
|
||||
@class RCTSurface;
|
||||
@class RCTSurfaceHostingComponentState;
|
||||
|
||||
@interface RCTSurfaceHostingComponent ()
|
||||
|
||||
@property (nonatomic, strong, readonly) RCTSurface *surface;
|
||||
@property (nonatomic, strong, readonly) id<RCTSurfaceProtocol> surface;
|
||||
@property (nonatomic, retain, readonly) RCTSurfaceHostingComponentState *state;
|
||||
@property (nonatomic, assign, readonly) RCTSurfaceHostingComponentOptions options;
|
||||
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
|
||||
#import <ComponentKit/CKComponent.h>
|
||||
#import <RCTSurfaceHostingComponent/RCTSurfaceHostingComponentOptions.h>
|
||||
|
||||
@class RCTSurface;
|
||||
#import <React/RCTSurfaceProtocol.h>
|
||||
|
||||
/**
|
||||
* ComponentKit component represents given Surface instance.
|
||||
*/
|
||||
@interface RCTSurfaceHostingComponent : CKComponent
|
||||
|
||||
+ (instancetype)newWithSurface:(RCTSurface *)surface options:(RCTSurfaceHostingComponentOptions)options;
|
||||
+ (instancetype)newWithSurface:(id<RCTSurfaceProtocol>)surface options:(RCTSurfaceHostingComponentOptions)options;
|
||||
|
||||
@end
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
return [RCTSurfaceHostingComponentState new];
|
||||
}
|
||||
|
||||
+ (instancetype)newWithSurface:(RCTSurface *)surface options:(RCTSurfaceHostingComponentOptions)options
|
||||
+ (instancetype)newWithSurface:(id<RCTSurfaceProtocol>)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
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
@end
|
||||
|
||||
@implementation RCTSurfaceHostingComponentController {
|
||||
RCTSurface *_surface;
|
||||
id<RCTSurfaceProtocol> _surface;
|
||||
}
|
||||
|
||||
- (instancetype)initWithComponent:(RCTSurfaceHostingComponent *)component
|
||||
@@ -64,7 +64,7 @@
|
||||
- (void)updateSurfaceWithComponent:(RCTSurfaceHostingComponent *)component
|
||||
{
|
||||
// Updating `surface`
|
||||
RCTSurface *const surface = component.surface;
|
||||
id<RCTSurfaceProtocol> const surface = component.surface;
|
||||
if (surface != _surface) {
|
||||
if (_surface.delegate == self) {
|
||||
_surface.delegate = nil;
|
||||
|
||||
Reference in New Issue
Block a user