From ceffb085d0f2a15210da91cdd4aa491bb46acd36 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 13 Jul 2016 08:01:44 -0700 Subject: [PATCH] Remove more weakSelf/strongSelf errors Reviewed By: mmmulani Differential Revision: D3555000 fbshipit-source-id: 13b75571a0d09374ee82977cb2acbf1f894479ca --- React/Modules/RCTDevMenu.m | 15 ++++++++++++--- React/Modules/RCTUIManager.m | 37 +++++++++++++----------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/React/Modules/RCTDevMenu.m b/React/Modules/RCTDevMenu.m index 3708028aa2..830bcc6c29 100644 --- a/React/Modules/RCTDevMenu.m +++ b/React/Modules/RCTDevMenu.m @@ -476,19 +476,28 @@ RCT_EXPORT_MODULE() if (_liveReloadURL) { NSString *liveReloadTitle = _liveReloadEnabled ? @"Disable Live Reload" : @"Enable Live Reload"; [items addObject:[RCTDevMenuItem buttonItemWithTitle:liveReloadTitle handler:^{ - weakSelf.liveReloadEnabled = !self->_liveReloadEnabled; + __typeof(self) strongSelf = weakSelf; + if (strongSelf) { + strongSelf.liveReloadEnabled = !strongSelf->_liveReloadEnabled; + } }]]; NSString *profilingTitle = RCTProfileIsProfiling() ? @"Stop Systrace" : @"Start Systrace"; [items addObject:[RCTDevMenuItem buttonItemWithTitle:profilingTitle handler:^{ - weakSelf.profilingEnabled = !self->_profilingEnabled; + __typeof(self) strongSelf = weakSelf; + if (strongSelf) { + strongSelf.profilingEnabled = !strongSelf->_profilingEnabled; + } }]]; } if ([self hotLoadingAvailable]) { NSString *hotLoadingTitle = _hotLoadingEnabled ? @"Disable Hot Reloading" : @"Enable Hot Reloading"; [items addObject:[RCTDevMenuItem buttonItemWithTitle:hotLoadingTitle handler:^{ - weakSelf.hotLoadingEnabled = !self->_hotLoadingEnabled; + __typeof(self) strongSelf = weakSelf; + if (strongSelf) { + strongSelf.hotLoadingEnabled = !strongSelf->_hotLoadingEnabled; + } }]]; } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index af667f2e82..668fa91cad 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -229,14 +229,10 @@ RCT_EXPORT_MODULE() - (void)didReceiveNewContentSizeMultiplier { - __weak RCTUIManager *weakSelf = self; dispatch_async(RCTGetUIManagerQueue(), ^{ - RCTUIManager *strongSelf = weakSelf; - if (strongSelf) { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification - object:strongSelf]; - [strongSelf batchDidComplete]; - } + [[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification + object:self]; + [self batchDidComplete]; }); } @@ -383,20 +379,19 @@ dispatch_queue_t RCTGetUIManagerQueue(void) CGRect frame = rootView.frame; // Register shadow view - __weak RCTUIManager *weakSelf = self; dispatch_async(RCTGetUIManagerQueue(), ^{ - RCTUIManager *strongSelf = weakSelf; if (!self->_viewRegistry) { return; } + RCTRootShadowView *shadowView = [RCTRootShadowView new]; shadowView.reactTag = reactTag; shadowView.frame = frame; shadowView.backgroundColor = rootView.backgroundColor; shadowView.viewName = NSStringFromClass([rootView class]); shadowView.sizeFlexibility = sizeFlexibility; - strongSelf->_shadowViewRegistry[shadowView.reactTag] = shadowView; - [strongSelf->_rootViewTags addObject:reactTag]; + self->_shadowViewRegistry[shadowView.reactTag] = shadowView; + [self->_rootViewTags addObject:reactTag]; }); [[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerDidRegisterRootViewNotification @@ -473,14 +468,12 @@ dispatch_queue_t RCTGetUIManagerQueue(void) RCTAssertMainQueue(); NSNumber *reactTag = view.reactTag; - - __weak RCTUIManager *weakSelf = self; dispatch_async(RCTGetUIManagerQueue(), ^{ - RCTUIManager *strongSelf = weakSelf; if (!self->_viewRegistry) { return; } - RCTShadowView *shadowView = strongSelf->_shadowViewRegistry[reactTag]; + + RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag]; RCTAssert(shadowView != nil, @"Could not locate root view with tag #%@", reactTag); shadowView.backgroundColor = color; [self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView]; @@ -515,19 +508,15 @@ dispatch_queue_t RCTGetUIManagerQueue(void) @"-[RCTUIManager addUIBlock:] should only be called from the " "UIManager's queue (get this using `RCTGetUIManagerQueue()`)"); - if (!block) { + if (!block || !_viewRegistry) { return; } - if (!_viewRegistry) { - return; - } - - __weak RCTUIManager *weakViewManager = self; + __weak RCTUIManager *weakSelf = self; dispatch_block_t outerBlock = ^{ - RCTUIManager *strongViewManager = weakViewManager; - if (strongViewManager && strongViewManager->_viewRegistry) { - block(strongViewManager, strongViewManager->_viewRegistry); + RCTUIManager *strongSelf = weakSelf; + if (strongSelf && strongSelf->_viewRegistry) { + block(strongSelf, strongSelf->_viewRegistry); } };