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:
Nick Lockwood
2016-06-07 00:08:16 -07:00
committed by Facebook Github Bot 7
parent 2a92b52ac8
commit 46c02b6ae5
21 changed files with 173 additions and 244 deletions

View File

@@ -23,7 +23,6 @@ const CGFloat RCTMapZoomBoundBuffer = 0.01;
{
UIView *_legalLabel;
CLLocationManager *_locationManager;
NSMutableArray<UIView *> *_reactSubviews;
}
- (instancetype)init
@@ -31,7 +30,6 @@ const CGFloat RCTMapZoomBoundBuffer = 0.01;
if ((self = [super init])) {
_hasStartedRendering = NO;
_reactSubviews = [NSMutableArray new];
// Find Apple link label
for (UIView *subview in self.subviews) {
@@ -51,19 +49,9 @@ const CGFloat RCTMapZoomBoundBuffer = 0.01;
[_regionChangeObserveTimer invalidate];
}
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
- (void)reactUpdateSubviews
{
[_reactSubviews insertObject:subview atIndex:atIndex];
}
- (void)removeReactSubview:(UIView *)subview
{
[_reactSubviews removeObject:subview];
}
- (NSArray<UIView *> *)reactSubviews
{
return _reactSubviews;
// Do nothing, as annotation views are managed by `setAnnotations:` method
}
- (void)layoutSubviews