mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 11:57:46 +08:00
Refactored subview management
Summary: This diff refactors the view update process into two stages: 1. The `reactSubviews` array is set, whose order matches the order of the JS components and shadowView components, as specified by the UIManager. 2. The `didUpdateReactSubviews` method is called, which actually inserts the reactSubviews into the view hierarchy. This simplifies a lot of the hacks we had for special-case treatment of subviews: In many cases we don't want to actually insert `reactSubviews` into the parentView, and we had a bunch of component-specific solutions for that (typically overriding all of the reactSubviews methods to store views in an array). Now, we can simply override the `didUpdateReactSubviews` method for those views to do nothing, or do something different. Reviewed By: wwjholmes Differential Revision: D3396594 fbshipit-source-id: 92fc56fd31db0cfc66aac3d1634a4d4ae3903085
This commit is contained in:
committed by
Facebook Github Bot 7
parent
2a92b52ac8
commit
46c02b6ae5
@@ -893,16 +893,18 @@ static void RCTSetChildren(NSNumber *containerTag,
|
||||
[container insertReactSubview:view atIndex:index++];
|
||||
}
|
||||
}
|
||||
|
||||
[container didUpdateReactSubviews];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||
RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerTag
|
||||
moveFromIndices:(NSArray<NSNumber *> *)moveFromIndices
|
||||
moveToIndices:(NSArray<NSNumber *> *)moveToIndices
|
||||
addChildReactTags:(NSArray<NSNumber *> *)addChildReactTags
|
||||
addAtIndices:(NSArray<NSNumber *> *)addAtIndices
|
||||
removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices)
|
||||
{
|
||||
[self _manageChildren:containerReactTag
|
||||
[self _manageChildren:containerTag
|
||||
moveFromIndices:moveFromIndices
|
||||
moveToIndices:moveToIndices
|
||||
addChildReactTags:addChildReactTags
|
||||
@@ -911,7 +913,7 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)_shadowViewRegistry];
|
||||
|
||||
[self addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
|
||||
[uiManager _manageChildren:containerReactTag
|
||||
[uiManager _manageChildren:containerTag
|
||||
moveFromIndices:moveFromIndices
|
||||
moveToIndices:moveToIndices
|
||||
addChildReactTags:addChildReactTags
|
||||
@@ -921,7 +923,7 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)_manageChildren:(NSNumber *)containerReactTag
|
||||
- (void)_manageChildren:(NSNumber *)containerTag
|
||||
moveFromIndices:(NSArray<NSNumber *> *)moveFromIndices
|
||||
moveToIndices:(NSArray<NSNumber *> *)moveToIndices
|
||||
addChildReactTags:(NSArray<NSNumber *> *)addChildReactTags
|
||||
@@ -929,7 +931,7 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||
removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
|
||||
registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry
|
||||
{
|
||||
id<RCTComponent> container = registry[containerReactTag];
|
||||
id<RCTComponent> container = registry[containerTag];
|
||||
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");
|
||||
|
||||
@@ -963,6 +965,8 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
|
||||
[container insertReactSubview:destinationsToChildrenToAdd[reactIndex]
|
||||
atIndex:reactIndex.integerValue];
|
||||
}
|
||||
|
||||
[container didUpdateReactSubviews];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag
|
||||
|
||||
Reference in New Issue
Block a user