mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Break retain cycle in RCTScrollViewComponentView
Summary: Breaks cycle by making self weak and storing delegates weakly. Reviewed By: fkgozali Differential Revision: D16579754 fbshipit-source-id: 17174b0e91898a14a86b8b44677090be3044382d
This commit is contained in:
committed by
Facebook Github Bot
parent
6764385c80
commit
14edd5d634
@@ -53,8 +53,9 @@ using namespace facebook::react;
|
||||
_containerView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[_scrollView addSubview:_containerView];
|
||||
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
_scrollViewDelegateSplitter = [[RNGenericDelegateSplitter alloc] initWithDelegateUpdateBlock:^(id delegate) {
|
||||
self->_scrollView.delegate = delegate;
|
||||
weakSelf.scrollView.delegate = delegate;
|
||||
}];
|
||||
|
||||
[_scrollViewDelegateSplitter addDelegate:self];
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#import "RNGenericDelegateSplitter.h"
|
||||
|
||||
@implementation RNGenericDelegateSplitter {
|
||||
NSMutableArray *_delegates;
|
||||
NSHashTable *_delegates;
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
@@ -17,7 +17,7 @@
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_delegateUpdateBlock = block;
|
||||
_delegates = [NSMutableArray new];
|
||||
_delegates = [NSHashTable weakObjectsHashTable];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -44,7 +44,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
_delegateUpdateBlock(_delegates.count == 1 ? _delegates.firstObject : self);
|
||||
_delegateUpdateBlock(_delegates.count == 1 ? [_delegates allObjects].firstObject : self);
|
||||
}
|
||||
|
||||
#pragma mark - Fast Forwarding
|
||||
|
||||
Reference in New Issue
Block a user