Refactor notification subscriptions in RCTDevLoadingView

Summary:
In bridegless mode, `setBridge` is never called on native modules. This diff refactors out some setup logic into the module's init method.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D26211620

fbshipit-source-id: 7a9910198852dea5ac679762aa93dfea6fc47d70
This commit is contained in:
Peter Argany 2021-02-03 11:50:41 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 690a29355e
Коммит 001dbf2068
1 изменённых файлов: 15 добавлений и 10 удалений

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

@ -15,7 +15,6 @@
#import <React/RCTConvert.h>
#import <React/RCTDefines.h>
#import <React/RCTDevLoadingViewSetEnabled.h>
#import <React/RCTModalHostViewController.h>
#import <React/RCTUtils.h>
#import "CoreModulesPlugins.h"
@ -39,6 +38,21 @@ using namespace facebook::react;
RCT_EXPORT_MODULE()
- (instancetype)init
{
if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hide)
name:RCTJavaScriptDidLoadNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hide)
name:RCTJavaScriptDidFailToLoadNotification
object:nil];
}
return self;
}
+ (void)setEnabled:(BOOL)enabled
{
RCTDevLoadingViewSetEnabled(enabled);
@ -53,15 +67,6 @@ RCT_EXPORT_MODULE()
{
_bridge = bridge;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hide)
name:RCTJavaScriptDidLoadNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hide)
name:RCTJavaScriptDidFailToLoadNotification
object:nil];
if (bridge.loading) {
[self showWithURL:bridge.bundleURL];
}