-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing RCTSurfaceBackedComponent
Summary: RCTSurfaceBackedComponent is ComponentKit component represents a React Native Surface created (and stored in the state) with given `bridge`, `moduleName`, and `properties`. Differential Revision: D6217103 fbshipit-source-id: 2849f68e1975562cd47851bda232e389705b4229
- Loading branch information
1 parent
e75bd87
commit aa83b5a
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <ComponentKit/CKComponent.h> | ||
#import <ComponentKit/CKCompositeComponent.h> | ||
#import <RCTSurfaceHostingComponent/RCTSurfaceHostingComponentOptions.h> | ||
|
||
@class RCTBridge; | ||
|
||
/** | ||
* ComponentKit component represents a React Native Surface created | ||
* (and stored in the state) with given `bridge`, `moduleName`, | ||
* and `properties`. | ||
*/ | ||
@interface RCTSurfaceBackedComponent : CKCompositeComponent | ||
|
||
+ (instancetype)newWithBridge:(RCTBridge *)bridge | ||
moduleName:(NSString *)moduleName | ||
properties:(NSDictionary *)properties | ||
options:(RCTSurfaceHostingComponentOptions)options; | ||
|
||
@end |
68 changes: 68 additions & 0 deletions
68
Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "RCTSurfaceBackedComponent.h" | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <ComponentKit/CKComponentSubclass.h> | ||
#import <ComponentKit/CKOverlayLayoutComponent.h> | ||
#import <RCTSurfaceHostingComponent/RCTSurfaceHostingComponent.h> | ||
#import <React/RCTSurface.h> | ||
|
||
#import "RCTSurfaceBackedComponentState.h" | ||
|
||
@implementation RCTSurfaceBackedComponent | ||
|
||
+ (id)initialState | ||
{ | ||
return [RCTSurfaceBackedComponentState new]; | ||
} | ||
|
||
+ (instancetype)newWithBridge:(RCTBridge *)bridge | ||
moduleName:(NSString *)moduleName | ||
properties:(NSDictionary *)properties | ||
options:(RCTSurfaceHostingComponentOptions)options | ||
{ | ||
CKComponentScope scope(self, moduleName); | ||
|
||
RCTSurfaceBackedComponentState *state = scope.state(); | ||
|
||
if (state.surface == nil || state.surface.bridge != bridge || ![state.surface.moduleName isEqualToString:moduleName]) { | ||
RCTSurface *surface = | ||
[[RCTSurface alloc] initWithBridge:bridge | ||
moduleName:moduleName | ||
initialProperties:properties]; | ||
|
||
state = [RCTSurfaceBackedComponentState newWithSurface:surface]; | ||
|
||
CKComponentScope::replaceState(scope, state); | ||
} | ||
else { | ||
if (![state.surface.properties isEqualToDictionary:properties]) { | ||
state.surface.properties = properties; | ||
} | ||
} | ||
|
||
RCTSurfaceHostingComponent *surfaceHostingComponent = | ||
[RCTSurfaceHostingComponent newWithSurface:state.surface | ||
options:options]; | ||
|
||
CKComponent *component; | ||
if (options.activityIndicatorComponentFactory == nil || state.surface.stage & RCTSurfaceStageSurfaceDidInitialLayout) { | ||
component = surfaceHostingComponent; | ||
} else { | ||
component = [CKOverlayLayoutComponent newWithComponent:surfaceHostingComponent | ||
overlay:options.activityIndicatorComponentFactory()]; | ||
} | ||
|
||
return [super newWithComponent:component]; | ||
} | ||
|
||
@end |
20 changes: 20 additions & 0 deletions
20
Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class RCTSurface; | ||
|
||
@interface RCTSurfaceBackedComponentState: NSObject | ||
|
||
@property (atomic, readonly, strong) RCTSurface *surface; | ||
|
||
+ (instancetype)newWithSurface:(RCTSurface *)surface; | ||
|
||
@end |
30 changes: 30 additions & 0 deletions
30
Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponentState.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "RCTSurfaceBackedComponentState.h" | ||
|
||
#import <React/RCTSurface.h> | ||
|
||
@implementation RCTSurfaceBackedComponentState | ||
|
||
+ (instancetype)newWithSurface:(RCTSurface *)surface | ||
{ | ||
return [[self alloc] initWithSurface:surface]; | ||
} | ||
|
||
- (instancetype)initWithSurface:(RCTSurface *)surface | ||
{ | ||
if (self == [super init]) { | ||
_surface = surface; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
@end |