Breaking a retain cycle between `RCTSurfaceTouchHandler` and `RCTFabricSurface` (another approach)

Summary:
This is a different approach to break the retain cycle: instead of detaching a view manually, we store a pointer to a view weakly.

I am working on some change that will make possible (and make use of it) to call `start` and `stop` on Surface objects mutiple times, so to make it happens we need to remove detaching from `stop` method.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D24041524

fbshipit-source-id: 700b13d715d2eb84d52bf3e51e0fd2896a55baf8
This commit is contained in:
Valentin Shergin 2020-10-01 09:36:03 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 16afda2282
Коммит 61cfa97067
3 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -11,6 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
@interface RCTSurfaceTouchHandler : UIGestureRecognizer @interface RCTSurfaceTouchHandler : UIGestureRecognizer
/*
* Attaches (and detaches) a view to the touch handler.
* The receiver does not retain the provided view.
*/
- (void)attachToView:(UIView *)view; - (void)attachToView:(UIView *)view;
- (void)detachFromView:(UIView *)view; - (void)detachFromView:(UIView *)view;

Просмотреть файл

@ -159,7 +159,10 @@ struct PointerHasher {
std::unordered_map<__unsafe_unretained UITouch *, ActiveTouch, PointerHasher<__unsafe_unretained UITouch *>> std::unordered_map<__unsafe_unretained UITouch *, ActiveTouch, PointerHasher<__unsafe_unretained UITouch *>>
_activeTouches; _activeTouches;
UIView *_rootComponentView; /*
* We hold the view weakly to prevent a retain cycle.
*/
__weak UIView *_rootComponentView;
IdentifierPool<11> _identifierPool; IdentifierPool<11> _identifierPool;
} }

Просмотреть файл

@ -83,7 +83,6 @@ using namespace facebook::react;
} }
[_surfacePresenter unregisterSurface:self]; [_surfacePresenter unregisterSurface:self];
[_touchHandler detachFromView:_view];
return YES; return YES;
} }