proper `reactSuperview` implementation
Summary: React view hierarchy doesn't have to always match uiview hierarchy. Plus if we clip view we loose knowledge about view's react superview if we just use `self.superview` as react superview. This diff fixes it by storing a strong ref to reactSuperview in an associated object. This is needed for new view clipping implementation (see the dependent diff). Reviewed By: mmmulani Differential Revision: D4081844 fbshipit-source-id: 9317d9db46fbd474382c5469b7922f88e5ee7568
This commit is contained in:
parent
bc9bbb5533
commit
47839307f3
|
@ -15,6 +15,13 @@
|
|||
#import "RCTLog.h"
|
||||
#import "RCTShadowView.h"
|
||||
|
||||
@interface RCTWeakObjectContainer : NSObject
|
||||
@property (nonatomic, weak) id object;
|
||||
@end
|
||||
|
||||
@implementation RCTWeakObjectContainer
|
||||
@end
|
||||
|
||||
@implementation UIView (React)
|
||||
|
||||
- (NSNumber *)reactTag
|
||||
|
@ -27,6 +34,18 @@
|
|||
objc_setAssociatedObject(self, @selector(reactTag), reactTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (UIView *)reactSuperview
|
||||
{
|
||||
return [(RCTWeakObjectContainer *)objc_getAssociatedObject(self, @selector(reactSuperview)) object];
|
||||
}
|
||||
|
||||
- (void)setReactSuperview:(UIView *)reactSuperview
|
||||
{
|
||||
RCTWeakObjectContainer *wrapper = [RCTWeakObjectContainer new];
|
||||
wrapper.object = reactSuperview;
|
||||
objc_setAssociatedObject(self, @selector(reactSuperview), wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
#if RCT_DEV
|
||||
|
||||
- (RCTShadowView *)_DEBUG_reactShadowView
|
||||
|
@ -61,11 +80,6 @@
|
|||
return objc_getAssociatedObject(self, _cmd);
|
||||
}
|
||||
|
||||
- (UIView *)reactSuperview
|
||||
{
|
||||
return self.superview;
|
||||
}
|
||||
|
||||
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
|
||||
{
|
||||
// We access the associated object directly here in case someone overrides
|
||||
|
@ -76,6 +90,7 @@
|
|||
objc_setAssociatedObject(self, @selector(reactSubviews), subviews, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
[subviews insertObject:subview atIndex:atIndex];
|
||||
[subview setReactSuperview:self];
|
||||
}
|
||||
|
||||
- (void)removeReactSubview:(UIView *)subview
|
||||
|
@ -85,6 +100,7 @@
|
|||
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(reactSubviews));
|
||||
[subviews removeObject:subview];
|
||||
[subview removeFromSuperview];
|
||||
[subview setReactSuperview:nil];
|
||||
}
|
||||
|
||||
- (NSInteger)reactZIndex
|
||||
|
|
Loading…
Reference in New Issue