fix up double surface registration on JS load

Summary:
@public
When JS first starts up, Fabric surface end up double registering itself, causing events to not work. So let's guard it so that registration happens only on reload case.

Reviewed By: shergin

Differential Revision: D8521002

fbshipit-source-id: 441f121786e860dc10e959e940b411c2afaf96dc
This commit is contained in:
Kevin Gozali 2018-06-19 18:38:49 -07:00 committed by Facebook Github Bot
parent 7b9b1559a7
commit e7256a777e
1 changed files with 15 additions and 9 deletions

View File

@ -298,16 +298,22 @@
{ {
// TODO: Move the bridge lifecycle handling up to the RCTSurfacePresenter. // TODO: Move the bridge lifecycle handling up to the RCTSurfacePresenter.
// Note: this covers only JS reloads. // Note: this covers both JS reloads and initial load after the bridge starts.
[self _setStage:RCTSurfaceStageModuleDidLoad]; // When it's not a reload, surface should already be running since we run it immediately in the initializer, so do
[self _run]; // nothing.
// When it's a reload, we rely on the `RCTJavaScriptWillStartLoadingNotification` notification to reset the stage,
// then we need to run the surface and update its size.
if (!RCTSurfaceStageIsRunning(_stage)) {
[self _setStage:RCTSurfaceStageModuleDidLoad];
[self _run];
// After a reload surfacePresenter needs to know the last min/max size for this surface, because the surface hosting // After a reload surfacePresenter needs to know the last min/max size for this surface, because the surface hosting
// view was already attached to the ViewController's view. // view was already attached to the ViewController's view.
// TODO: Find a better automatic way. // TODO: Find a better automatic way.
[_surfacePresenter setMinimumSize:_minimumSize [_surfacePresenter setMinimumSize:_minimumSize
maximumSize:_maximumSize maximumSize:_maximumSize
surface:self]; surface:self];
}
} }
@end @end