iOS: Avoid double reload event when reloading JS

Summary:
@public
The bridge may send the reload event twice when reloading JS in some rare condition. The 2nd one was actually when the "new" bridge wasn't valid yet, so log an error if that happens. This may happen if the connection to Metro server gets into a weird state. Restarting Metro would solve the problem.

The issue was that `RCTBridgeWillReloadNotification` fired twice for each reload with metro connected.

Reviewed By: mmmulani

Differential Revision: D8509448

fbshipit-source-id: 647fb98c0a97503409a10451b8f152145947ae20
This commit is contained in:
Kevin Gozali 2018-06-19 18:38:47 -07:00 коммит произвёл Facebook Github Bot
Родитель 73c4df219a
Коммит 7b9b1559a7
3 изменённых файлов: 10 добавлений и 0 удалений

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

@ -876,6 +876,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
- (void)reload
{
if (!_valid) {
RCTLogError(@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", self);
}
[_parentBridge reload];
}

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

@ -61,6 +61,11 @@ using namespace facebook::react;
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)schedulerDidComputeMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions rootTag:(ReactTag)rootTag
{
[_mountingManager mutateComponentViewTreeWithMutationInstructions:instructions

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

@ -90,6 +90,8 @@
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self _stop];
}