2018-04-10 16:36:54 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTMountingManager.h"
|
|
|
|
|
|
|
|
#import <fabric/core/LayoutableShadowNode.h>
|
|
|
|
#import <React/RCTAssert.h>
|
|
|
|
#import <React/RCTUtils.h>
|
|
|
|
|
|
|
|
#import "RCTComponentViewProtocol.h"
|
|
|
|
#import "RCTComponentViewRegistry.h"
|
|
|
|
#import "RCTMountItemProtocol.h"
|
|
|
|
|
|
|
|
#import "RCTCreateMountItem.h"
|
2018-06-22 11:53:44 -07:00
|
|
|
#import "RCTConversions.h"
|
2018-04-10 16:36:54 -07:00
|
|
|
#import "RCTDeleteMountItem.h"
|
|
|
|
#import "RCTInsertMountItem.h"
|
|
|
|
#import "RCTRemoveMountItem.h"
|
|
|
|
#import "RCTUpdatePropsMountItem.h"
|
2018-06-09 13:02:55 -07:00
|
|
|
#import "RCTUpdateEventEmitterMountItem.h"
|
2018-04-26 17:51:52 -07:00
|
|
|
#import "RCTUpdateLocalDataMountItem.h"
|
2018-04-10 16:36:54 -07:00
|
|
|
#import "RCTUpdateLayoutMetricsMountItem.h"
|
|
|
|
|
|
|
|
using namespace facebook::react;
|
|
|
|
|
|
|
|
@implementation RCTMountingManager
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
_componentViewRegistry = [[RCTComponentViewRegistry alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
- (void)performTransactionWithMutations:(facebook::react::ShadowViewMutationList)mutations
|
|
|
|
rootTag:(ReactTag)rootTag
|
2018-04-10 16:36:54 -07:00
|
|
|
{
|
|
|
|
NSMutableArray<RCTMountItemProtocol> *mountItems =
|
2018-09-03 22:53:18 -07:00
|
|
|
[[NSMutableArray<RCTMountItemProtocol> alloc] initWithCapacity:mutations.size() * 2 /* ~ the worst case */];
|
2018-04-10 16:36:54 -07:00
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
for (const auto &mutation : mutations) {
|
|
|
|
switch (mutation.type) {
|
|
|
|
case ShadowViewMutation::Create: {
|
|
|
|
NSString *componentName = RCTNSStringFromString(mutation.newChildShadowView.componentName, NSASCIIStringEncoding);
|
2018-04-10 16:36:54 -07:00
|
|
|
RCTCreateMountItem *mountItem =
|
|
|
|
[[RCTCreateMountItem alloc] initWithComponentName:componentName
|
2018-09-03 22:53:18 -07:00
|
|
|
tag:mutation.newChildShadowView.tag];
|
2018-04-10 16:36:54 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
break;
|
|
|
|
}
|
2018-05-22 15:48:21 -07:00
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
case ShadowViewMutation::Delete: {
|
|
|
|
NSString *componentName = RCTNSStringFromString(mutation.oldChildShadowView.componentName, NSASCIIStringEncoding);
|
2018-04-10 16:36:54 -07:00
|
|
|
RCTDeleteMountItem *mountItem =
|
|
|
|
[[RCTDeleteMountItem alloc] initWithComponentName:componentName
|
2018-09-03 22:53:18 -07:00
|
|
|
tag:mutation.oldChildShadowView.tag];
|
2018-04-10 16:36:54 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
case ShadowViewMutation::Insert: {
|
2018-04-10 16:36:54 -07:00
|
|
|
// Props
|
2018-09-03 22:53:18 -07:00
|
|
|
[mountItems addObject:[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
2018-04-10 16:36:54 -07:00
|
|
|
oldProps:nullptr
|
2018-09-03 22:53:18 -07:00
|
|
|
newProps:mutation.newChildShadowView.props]];
|
2018-04-10 16:36:54 -07:00
|
|
|
|
2018-06-09 13:02:55 -07:00
|
|
|
// EventEmitter
|
2018-09-03 22:53:18 -07:00
|
|
|
[mountItems addObject:[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
|
|
|
eventEmitter:mutation.newChildShadowView.eventEmitter]];
|
2018-05-22 15:48:21 -07:00
|
|
|
|
2018-04-26 17:51:52 -07:00
|
|
|
// LocalData
|
2018-09-03 22:53:18 -07:00
|
|
|
if (mutation.newChildShadowView.localData) {
|
|
|
|
[mountItems addObject:[[RCTUpdateLocalDataMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
2018-04-26 17:51:52 -07:00
|
|
|
oldLocalData:nullptr
|
2018-09-03 22:53:18 -07:00
|
|
|
newLocalData:mutation.newChildShadowView.localData]];
|
2018-04-26 17:51:52 -07:00
|
|
|
}
|
|
|
|
|
2018-04-10 16:36:54 -07:00
|
|
|
// Layout
|
2018-09-03 22:53:18 -07:00
|
|
|
if (mutation.newChildShadowView.layoutMetrics != EmptyLayoutMetrics) {
|
|
|
|
[mountItems addObject:[[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
2018-04-10 16:36:54 -07:00
|
|
|
oldLayoutMetrics:{}
|
2018-09-03 22:53:18 -07:00
|
|
|
newLayoutMetrics:mutation.newChildShadowView.layoutMetrics]];
|
2018-04-10 16:36:54 -07:00
|
|
|
}
|
2018-05-22 15:48:21 -07:00
|
|
|
|
|
|
|
// Insertion
|
|
|
|
RCTInsertMountItem *mountItem =
|
2018-09-03 22:53:18 -07:00
|
|
|
[[RCTInsertMountItem alloc] initWithChildTag:mutation.newChildShadowView.tag
|
|
|
|
parentTag:mutation.parentShadowView.tag
|
|
|
|
index:mutation.index];
|
2018-05-22 15:48:21 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
|
2018-04-10 16:36:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
case ShadowViewMutation::Remove: {
|
2018-04-10 16:36:54 -07:00
|
|
|
RCTRemoveMountItem *mountItem =
|
2018-09-03 22:53:18 -07:00
|
|
|
[[RCTRemoveMountItem alloc] initWithChildTag:mutation.oldChildShadowView.tag
|
|
|
|
parentTag:mutation.parentShadowView.tag
|
|
|
|
index:mutation.index];
|
2018-04-10 16:36:54 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
case ShadowViewMutation::Update: {
|
|
|
|
auto oldChildShadowView = mutation.oldChildShadowView;
|
|
|
|
auto newChildShadowView = mutation.newChildShadowView;
|
2018-04-10 16:36:54 -07:00
|
|
|
|
|
|
|
// Props
|
2018-09-03 22:53:18 -07:00
|
|
|
if (oldChildShadowView.props != newChildShadowView.props) {
|
2018-04-10 16:36:54 -07:00
|
|
|
RCTUpdatePropsMountItem *mountItem =
|
2018-09-03 22:53:18 -07:00
|
|
|
[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
|
|
|
oldProps:mutation.oldChildShadowView.props
|
|
|
|
newProps:mutation.newChildShadowView.props];
|
2018-04-10 16:36:54 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
}
|
|
|
|
|
2018-06-09 13:02:55 -07:00
|
|
|
// EventEmitter
|
2018-09-03 22:53:18 -07:00
|
|
|
if (oldChildShadowView.eventEmitter != newChildShadowView.eventEmitter) {
|
2018-06-09 13:02:55 -07:00
|
|
|
RCTUpdateEventEmitterMountItem *mountItem =
|
2018-09-03 22:53:18 -07:00
|
|
|
[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
|
|
|
eventEmitter:mutation.oldChildShadowView.eventEmitter];
|
2018-05-22 15:48:21 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
}
|
|
|
|
|
2018-04-26 17:51:52 -07:00
|
|
|
// LocalData
|
2018-09-03 22:53:18 -07:00
|
|
|
if (oldChildShadowView.localData != newChildShadowView.localData) {
|
2018-04-26 17:51:52 -07:00
|
|
|
RCTUpdateLocalDataMountItem *mountItem =
|
2018-09-03 22:53:18 -07:00
|
|
|
[[RCTUpdateLocalDataMountItem alloc] initWithTag:newChildShadowView.tag
|
|
|
|
oldLocalData:oldChildShadowView.localData
|
|
|
|
newLocalData:newChildShadowView.localData];
|
2018-04-26 17:51:52 -07:00
|
|
|
[mountItems addObject:mountItem];
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:36:54 -07:00
|
|
|
// Layout
|
2018-09-03 22:53:18 -07:00
|
|
|
if (oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) {
|
|
|
|
RCTUpdateLayoutMetricsMountItem *mountItem =
|
|
|
|
[[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
|
|
|
oldLayoutMetrics:oldChildShadowView.layoutMetrics
|
|
|
|
newLayoutMetrics:newChildShadowView.layoutMetrics];
|
|
|
|
[mountItems addObject:mountItem];
|
2018-04-10 16:36:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
[self _performMountItems:mountItems rootTag:rootTag];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_performMountItems:(NSArray<RCTMountItemProtocol> *)mountItems
|
|
|
|
rootTag:(ReactTag)rootTag
|
|
|
|
{
|
|
|
|
RCTAssertMainQueue();
|
|
|
|
|
|
|
|
[self.delegate mountingManager:self willMountComponentsWithRootTag:rootTag];
|
|
|
|
|
|
|
|
for (id<RCTMountItemProtocol> mountItem in mountItems) {
|
|
|
|
[mountItem executeWithRegistry:_componentViewRegistry];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.delegate mountingManager:self didMountComponentsWithRootTag:rootTag];
|
|
|
|
}
|
|
|
|
|
2018-06-29 19:57:43 -07:00
|
|
|
- (void)preliminaryCreateComponentViewWithName:(NSString *)componentName
|
|
|
|
{
|
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
[self->_componentViewRegistry preliminaryCreateComponentViewWithName:componentName];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:36:54 -07:00
|
|
|
@end
|