2017-11-12 05:15:20 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-11-12 05:15:20 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-11-12 05:15:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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();
|
|
|
|
|
2018-08-01 22:23:06 +00:00
|
|
|
if (state.surface == nil || ![state.surface.moduleName isEqualToString:moduleName]) {
|
2017-11-12 05:15:20 +00:00
|
|
|
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;
|
2017-12-04 04:03:27 +00:00
|
|
|
if (options.activityIndicatorComponentFactory == nil || RCTSurfaceStageIsRunning(state.surface.stage)) {
|
2017-11-12 05:15:20 +00:00
|
|
|
component = surfaceHostingComponent;
|
|
|
|
} else {
|
|
|
|
component = [CKOverlayLayoutComponent newWithComponent:surfaceHostingComponent
|
|
|
|
overlay:options.activityIndicatorComponentFactory()];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super newWithComponent:component];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|