mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +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
@@ -77,8 +77,8 @@
|
||||
@"Expect to have 5 react subviews after calling manage children \
|
||||
with 5 tags to add, instead have %lu", (unsigned long)[[containerView reactSubviews] count]);
|
||||
for (UIView *view in addedViews) {
|
||||
XCTAssertTrue([view superview] == containerView,
|
||||
@"Expected to have manage children successfully add children");
|
||||
XCTAssertTrue([view reactSuperview] == containerView,
|
||||
@"Expected to have manage children successfully add children");
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@
|
||||
}
|
||||
for (NSInteger i = 2; i < 20; i++) {
|
||||
UIView *view = _uiManager.viewRegistry[@(i)];
|
||||
[containerView addSubview:view];
|
||||
[containerView insertReactSubview:view atIndex:containerView.reactSubviews.count];
|
||||
}
|
||||
|
||||
// Remove views 1-5 from view 20
|
||||
@@ -112,7 +112,7 @@
|
||||
with 5 tags to remove and 18 prior children, instead have %zd",
|
||||
containerView.reactSubviews.count);
|
||||
for (UIView *view in removedViews) {
|
||||
XCTAssertTrue([view superview] == nil,
|
||||
XCTAssertTrue([view reactSuperview] == nil,
|
||||
@"Expected to have manage children successfully remove children");
|
||||
// After removing views are unregistered - we need to reregister
|
||||
_uiManager.viewRegistry[view.reactTag] = view;
|
||||
@@ -155,7 +155,7 @@
|
||||
|
||||
for (NSInteger i = 1; i < 11; i++) {
|
||||
UIView *view = _uiManager.viewRegistry[@(i)];
|
||||
[containerView addSubview:view];
|
||||
[containerView insertReactSubview:view atIndex:containerView.reactSubviews.count];
|
||||
}
|
||||
|
||||
[_uiManager _manageChildren:@20
|
||||
|
||||
Reference in New Issue
Block a user