revert D2707930
Reviewed By: fkgozali Differential Revision: D2720828 fb-gh-sync-id: 53113fb33150b42a7b597a7dfd04bb9885def029
This commit is contained in:
parent
d1029d1b9d
commit
70f0dfc0e6
|
@ -104,11 +104,11 @@ ReactNativeBaseComponent.Mixin = {
|
||||||
// no children - let's avoid calling out to the native bridge for a large
|
// no children - let's avoid calling out to the native bridge for a large
|
||||||
// portion of the children.
|
// portion of the children.
|
||||||
if (mountImages.length) {
|
if (mountImages.length) {
|
||||||
|
var indexes = cachedIndexArray(mountImages.length);
|
||||||
// TODO: Pool these per platform view class. Reusing the `mountImages`
|
// TODO: Pool these per platform view class. Reusing the `mountImages`
|
||||||
// array would likely be a jit deopt.
|
// array would likely be a jit deopt.
|
||||||
var createdTags = [];
|
var createdTags = [];
|
||||||
for (var i = 0, l = mountImages.length; i < l; i++) {
|
for (var i = 0; i < mountImages.length; i++) {
|
||||||
var mountImage = mountImages[i];
|
var mountImage = mountImages[i];
|
||||||
var childTag = mountImage.tag;
|
var childTag = mountImage.tag;
|
||||||
var childID = mountImage.rootNodeID;
|
var childID = mountImage.rootNodeID;
|
||||||
|
@ -122,15 +122,8 @@ ReactNativeBaseComponent.Mixin = {
|
||||||
);
|
);
|
||||||
createdTags[i] = mountImage.tag;
|
createdTags[i] = mountImage.tag;
|
||||||
}
|
}
|
||||||
|
UIManager
|
||||||
// Fast path for iOS
|
.manageChildren(containerTag, null, null, createdTags, indexes, null);
|
||||||
if (UIManager.addChildren) {
|
|
||||||
UIManager.addChildren(containerTag, createdTags);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var indexes = cachedIndexArray(mountImages.length);
|
|
||||||
UIManager.manageChildren(containerTag, null, null, createdTags, indexes, null);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ var dangerouslyProcessChildrenUpdates = function(childrenUpdates, markupList) {
|
||||||
(updates.addChildTags || (updates.addChildTags = [])).push(tag);
|
(updates.addChildTags || (updates.addChildTags = [])).push(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note this enumeration order will be different on V8! Move `byContainerTag`
|
// Note this enumeration order will be different on V8! Move `byContainerTag`
|
||||||
// to a sparse array as soon as we confirm there are not horrible perf
|
// to a sparse array as soon as we confirm there are not horrible perf
|
||||||
// penalties.
|
// penalties.
|
||||||
|
|
|
@ -188,16 +188,6 @@ var ReactNativeMount = {
|
||||||
mountImage.rootNodeID,
|
mountImage.rootNodeID,
|
||||||
mountImage.tag
|
mountImage.tag
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fast path for iOS
|
|
||||||
if (UIManager.addChildren) {
|
|
||||||
UIManager.addChildren(
|
|
||||||
ReactNativeTagHandles.mostRecentMountedNodeHandleForRootNodeID(containerID),
|
|
||||||
[mountImage.tag]
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var addChildTags = [mountImage.tag];
|
var addChildTags = [mountImage.tag];
|
||||||
var addAtIndices = [0];
|
var addAtIndices = [0];
|
||||||
UIManager.manageChildren(
|
UIManager.manageChildren(
|
||||||
|
|
|
@ -720,33 +720,6 @@ RCT_EXPORT_METHOD(replaceExistingNonRootView:(nonnull NSNumber *)reactTag
|
||||||
removeAtIndices:removeAtIndices];
|
removeAtIndices:removeAtIndices];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(addChildren:(nonnull NSNumber *)containerTag
|
|
||||||
reactTags:(NSNumberArray *)reactTags)
|
|
||||||
{
|
|
||||||
RCTAddChildren(containerTag, reactTags,
|
|
||||||
(NSDictionary<NSNumber *, id<RCTComponent>> *)_shadowViewRegistry);
|
|
||||||
|
|
||||||
[self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
|
|
||||||
|
|
||||||
RCTAddChildren(containerTag, reactTags,
|
|
||||||
(NSDictionary<NSNumber *, id<RCTComponent>> *)viewRegistry);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void RCTAddChildren(NSNumber *containerTag,
|
|
||||||
NSArray<NSNumber *> *reactTags,
|
|
||||||
NSDictionary<NSNumber *, id<RCTComponent>> *registry)
|
|
||||||
{
|
|
||||||
id<RCTComponent> container = registry[containerTag];
|
|
||||||
NSInteger index = [container reactSubviews].count;
|
|
||||||
for (NSNumber *reactTag in reactTags) {
|
|
||||||
id<RCTComponent> view = registry[reactTag];
|
|
||||||
if (view) {
|
|
||||||
[container insertReactSubview:view atIndex:index++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||||
moveFromIndices:(NSNumberArray *)moveFromIndices
|
moveFromIndices:(NSNumberArray *)moveFromIndices
|
||||||
moveToIndices:(NSNumberArray *)moveToIndices
|
moveToIndices:(NSNumberArray *)moveToIndices
|
||||||
|
@ -781,57 +754,39 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||||
removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
|
removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
|
||||||
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry
|
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry
|
||||||
{
|
{
|
||||||
RCTAssert(moveFromIndices.count == moveToIndices.count,
|
|
||||||
@"moveFromIndices had size %tu, moveToIndices had size %tu",
|
|
||||||
moveFromIndices.count, moveToIndices.count);
|
|
||||||
|
|
||||||
RCTAssert(addChildReactTags.count == addAtIndices.count,
|
|
||||||
@"addChildReactTags had size %tu, addAtIndices had size %tu",
|
|
||||||
addChildReactTags.count, addAtIndices.count);
|
|
||||||
|
|
||||||
id<RCTComponent> container = registry[containerReactTag];
|
id<RCTComponent> container = registry[containerReactTag];
|
||||||
NSArray<id<RCTComponent>> *views = [container reactSubviews];
|
RCTAssert(moveFromIndices.count == moveToIndices.count, @"moveFromIndices had size %tu, moveToIndices had size %tu", moveFromIndices.count, moveToIndices.count);
|
||||||
|
RCTAssert(addChildReactTags.count == addAtIndices.count, @"there should be at least one React child to add");
|
||||||
|
|
||||||
// Get indices to insert/remove
|
// Removes (both permanent and temporary moves) are using "before" indices
|
||||||
NSUInteger purgeCount = removeAtIndices.count;
|
NSArray<id<RCTComponent>> *permanentlyRemovedChildren =
|
||||||
NSUInteger moveCount = moveFromIndices.count;
|
[self _childrenToRemoveFromContainer:container atIndices:removeAtIndices];
|
||||||
NSUInteger insertCount = addAtIndices.count;
|
NSArray<id<RCTComponent>> *temporarilyRemovedChildren =
|
||||||
NSUInteger removeCount = purgeCount + moveCount;
|
[self _childrenToRemoveFromContainer:container atIndices:moveFromIndices];
|
||||||
NSMutableArray<id<RCTComponent>> *toRemove = removeCount ? [NSMutableArray new] : nil;
|
[self _removeChildren:permanentlyRemovedChildren fromContainer:container];
|
||||||
NSMutableDictionary *toInsert = insertCount ? [NSMutableDictionary new] : nil;
|
[self _removeChildren:temporarilyRemovedChildren fromContainer:container];
|
||||||
for (NSNumber *index in removeAtIndices) {
|
|
||||||
id<RCTComponent> view = views[index.integerValue];
|
[self _purgeChildren:permanentlyRemovedChildren fromRegistry:registry];
|
||||||
[toRemove addObject:view];
|
|
||||||
RCTTraverseViewNodes(registry[view.reactTag], ^(id<RCTComponent> subview) {
|
// TODO (#5906496): optimize all these loops - constantly calling array.count is not efficient
|
||||||
RCTAssert(![subview isReactRootView], @"Root views should not be unregistered");
|
|
||||||
if ([subview conformsToProtocol:@protocol(RCTInvalidating)]) {
|
// Figure out what to insert - merge temporary inserts and adds
|
||||||
[(id<RCTInvalidating>)subview invalidate];
|
NSMutableDictionary *destinationsToChildrenToAdd = [NSMutableDictionary dictionary];
|
||||||
}
|
for (NSInteger index = 0, length = temporarilyRemovedChildren.count; index < length; index++) {
|
||||||
[registry removeObjectForKey:subview.reactTag];
|
destinationsToChildrenToAdd[moveToIndices[index]] = temporarilyRemovedChildren[index];
|
||||||
[_bridgeTransactionListeners removeObject:subview];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
NSInteger i = 0;
|
for (NSInteger index = 0, length = addAtIndices.count; index < length; index++) {
|
||||||
for (NSNumber *index in moveFromIndices) {
|
id<RCTComponent> view = registry[addChildReactTags[index]];
|
||||||
id<RCTComponent> view = views[index.integerValue];
|
if (view) {
|
||||||
[toRemove addObject:view];
|
destinationsToChildrenToAdd[addAtIndices[index]] = view;
|
||||||
toInsert[moveToIndices[i]] = view;
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
for (NSNumber *reactTag in addChildReactTags) {
|
|
||||||
toInsert[addAtIndices[i]] = registry[reactTag];
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove old views
|
NSArray<NSNumber *> *sortedIndices =
|
||||||
for (id<RCTComponent> view in toRemove) {
|
[destinationsToChildrenToAdd.allKeys sortedArrayUsingSelector:@selector(compare:)];
|
||||||
[container removeReactSubview:view];
|
for (NSNumber *reactIndex in sortedIndices) {
|
||||||
}
|
[container insertReactSubview:destinationsToChildrenToAdd[reactIndex]
|
||||||
|
atIndex:reactIndex.integerValue];
|
||||||
// Insert new views in ascending order
|
|
||||||
for (NSNumber *index in [toInsert.allKeys sortedArrayUsingSelector:@selector(compare:)]) {
|
|
||||||
[container insertReactSubview:toInsert[index] atIndex:index.integerValue];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue