mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
56c7ae729a
commit
dc3b5ad275
@@ -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();
|
||||
|
||||
@@ -164,7 +164,6 @@
|
||||
CFRelease(_imageSource);
|
||||
_imageSource = NULL;
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -385,7 +385,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[_contentView invalidate];
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -160,7 +160,6 @@ RCT_EXPORT_MODULE()
|
||||
{
|
||||
[self markEndOfBackgroundTaskIfNeeded];
|
||||
[_sleepTimer invalidate];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)markStartOfBackgroundTaskIfNeeded
|
||||
|
||||
@@ -34,11 +34,6 @@ RCT_EXPORT_MODULE()
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return YES;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -204,7 +204,6 @@ RCT_EXPORT_MODULE()
|
||||
#if ENABLE_PACKAGER_CONNECTION
|
||||
[[RCTPackagerConnection sharedPackagerConnection] removeHandler:_reloadToken];
|
||||
#endif
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)supportedEvents
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user