Remove unneeded NSNotification center removeObserver

Summary:
A very common pattern I've seen in RN codebase:

     - (instancetype) init {
        [[NSNotificationCenter defaultCenter] addObserver:self ...]
      }

    - (void) dealloc {
       [[NSNotificationCenter defaultCenter] removeObserver:self ...]
     }

From Apple:

https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver?language=objc

> If your app targets iOS 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its dealloc method.

RN targets iOS9+

Changelog: [Internal][Cleanup] Remove unneeded NSNotification center removeObserver

Reviewed By: shergin

Differential Revision: D18264235

fbshipit-source-id: 684e5f5555cec96b055b13cd83daaeb393f4fac9
This commit is contained in:
Peter Argany
2019-11-04 10:19:30 -08:00
committed by Facebook Github Bot
parent 56c7ae729a
commit dc3b5ad275
25 changed files with 5 additions and 99 deletions
@@ -59,11 +59,6 @@ RCT_EXPORT_MODULE(ImagePickerIOS);
return NO;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"AVCaptureDeviceDidStartRunningNotification" object:nil];
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
-1
View File
@@ -164,7 +164,6 @@
CFRelease(_imageSource);
_imageSource = NULL;
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}
@end
-5
View File
@@ -54,11 +54,6 @@ static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat sc
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)clearCache
{
[_decodedImageCache removeAllObjects];
-5
View File
@@ -103,11 +103,6 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
RCT_NOT_IMPLEMENTED(- (instancetype)init)
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
-1
View File
@@ -311,7 +311,6 @@ static NSUInteger RCTDeviceFreeMemory() {
// Removes the display link from all run loop modes.
[_displayLink invalidate];
_displayLink = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}
- (void)didReceiveMemoryWarning:(NSNotification *)notification
-5
View File
@@ -52,11 +52,6 @@ RCT_EXPORT_MODULE()
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (facebook::react::ModuleConstants<JS::NativeSettingsManager::Constants>)constantsToExport
{
return (facebook::react::ModuleConstants<JS::NativeSettingsManager::Constants>)[self getConstants];
-5
View File
@@ -50,11 +50,6 @@ RCT_EXPORT_VIEW_PROPERTY(selectable, BOOL)
lazilyLoadIfNecessary:YES]];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (UIView *)view
{
return [RCTTextView new];
@@ -51,11 +51,6 @@ static UIColor *defaultPlaceholderColor()
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Accessibility
- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement
@@ -95,11 +95,6 @@ RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
lazilyLoadIfNecessary:YES]];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - RCTUIManagerObserver
- (void)uiManagerWillPerformMounting:(__unused RCTUIManager *)uiManager
@@ -32,11 +32,6 @@
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)_textDidChange
{
_textWasPasted = NO;
@@ -62,11 +62,6 @@ RCT_EXPORT_MODULE()
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
@interface RCTModuleInitNotificationRaceTests : XCTestCase <RCTBridgeDelegate>
-1
View File
@@ -385,7 +385,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_contentView invalidate];
}
-1
View File
@@ -106,7 +106,6 @@
- (void)dealloc
{
[self _stop];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Immutable Properties (no need to enforce synchronization)
@@ -94,11 +94,6 @@ RCT_EXPORT_MODULE()
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveNewContentSizeCategory:(NSNotification *)note
{
self.contentSizeCategory = note.userInfo[UIContentSizeCategoryNewValueKey];
+1 -2
View File
@@ -8,8 +8,7 @@
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
@interface RCTDeviceInfo : NSObject <RCTBridgeModule, RCTInvalidating>
@interface RCTDeviceInfo : NSObject <RCTBridgeModule>
@end
-13
View File
@@ -112,19 +112,6 @@ static NSDictionary *RCTExportedDimensions(RCTBridge *bridge)
};
}
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)invalidate
{
RCTExecuteOnMainQueue(^{
self->_bridge = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
});
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return [self getConstants];
-1
View File
@@ -160,7 +160,6 @@ RCT_EXPORT_MODULE()
{
[self markEndOfBackgroundTaskIfNeeded];
[_sleepTimer invalidate];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)markStartOfBackgroundTaskIfNeeded
-5
View File
@@ -34,11 +34,6 @@ RCT_EXPORT_MODULE()
isEnabled = enabled;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
+2 -4
View File
@@ -157,9 +157,7 @@ RCT_EXPORT_MODULE()
{
_presentedItems = nil;
[_actionSheet dismissViewControllerAnimated:YES
completion:^(void){
}];
[[NSNotificationCenter defaultCenter] removeObserver:self];
completion:^(void){}];
}
- (void)showOnShake
@@ -425,7 +423,7 @@ RCT_EXPORT_METHOD(show)
_presentedItems = items;
[RCTPresentedViewController() presentViewController:_actionSheet animated:YES completion:nil];
[_bridge enqueueJSCall:@"RCTNativeAppEventEmitter"
method:@"emit"
args:@[@"RCTDevMenuShown"]
@@ -92,7 +92,6 @@ static RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
- (void)dealloc
{
[_surfacePresenter suspend];
[self _removeBridgeObservers:_bridge];
}
- (RCTBridge *)bridge
-1
View File
@@ -204,7 +204,6 @@ RCT_EXPORT_MODULE()
#if ENABLE_PACKAGER_CONNECTION
[[RCTPackagerConnection sharedPackagerConnection] removeHandler:_reloadToken];
#endif
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSArray<NSString *> *)supportedEvents
-1
View File
@@ -210,7 +210,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
{
_stackTraceTableView.dataSource = nil;
_stackTraceTableView.delegate = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSString *)stripAnsi:(NSString *)text
@@ -32,11 +32,6 @@ RCT_EXPORT_MODULE()
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSArray<NSString *> *)supportedEvents
{
return @[TVNavigationEventName];
+2 -7
View File
@@ -88,11 +88,6 @@ RCT_EXPORT_MODULE()
return NO;
}
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)invalidate
{
/**
@@ -339,9 +334,9 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
if (name) {
return name;
}
UIView *view = _viewRegistry[reactTag];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
@@ -118,11 +118,6 @@ static Class getFallbackClassFromName(const char *name)
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)notifyAboutTurboModuleSetup:(const char *)name
{
NSString *moduleName = [[NSString alloc] initWithUTF8String:name];