diff --git a/React/Base/Surface/RCTSurface.mm b/React/Base/Surface/RCTSurface.mm index 07c0521c774970..0f205b74a474e4 100644 --- a/React/Base/Surface/RCTSurface.mm +++ b/React/Base/Surface/RCTSurface.mm @@ -85,7 +85,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge _stage = _stage | RCTSurfaceStageBridgeDidLoad; } - [self _registerRootViewTag]; + [self _registerRootView]; [self _run]; } @@ -94,6 +94,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge - (void)dealloc { + [self _stop]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } @@ -297,7 +298,18 @@ - (void)_run [self _setStage:RCTSurfaceStageSurfaceDidRun]; } -- (void)_registerRootViewTag +- (void)_stop +{ + RCTBridge *batchedBridge = self._batchedBridge; + [batchedBridge enqueueJSCall:@"AppRegistry" + method:@"unmountApplicationComponentAtRootTag" + args:@[self->_rootViewTag] + completion:NULL]; + + [self _setStage:RCTSurfaceStageSurfaceDidStop]; +} + +- (void)_registerRootView { RCTBridge *batchedBridge; CGSize minimumSize; diff --git a/React/Base/Surface/RCTSurfaceStage.h b/React/Base/Surface/RCTSurfaceStage.h index 3cf91ad4f6d062..8021ba7fc73329 100644 --- a/React/Base/Surface/RCTSurfaceStage.h +++ b/React/Base/Surface/RCTSurfaceStage.h @@ -22,7 +22,7 @@ typedef NS_OPTIONS(NSInteger, RCTSurfaceStage) { RCTSurfaceStageSurfaceDidInitialRendering = 1 << 4, // UIManager created the first shadow views RCTSurfaceStageSurfaceDidInitialLayout = 1 << 5, // UIManager completed the first layout pass RCTSurfaceStageSurfaceDidInitialMounting = 1 << 6, // UIManager completed the first mounting pass - RCTSurfaceStageSurfaceDidInvalidate = 1 << 7, // Surface received `invalidate` message + RCTSurfaceStageSurfaceDidStop = 1 << 7, // Surface stopped }; /** diff --git a/React/Base/Surface/RCTSurfaceStage.m b/React/Base/Surface/RCTSurfaceStage.m index 932d1906db1a61..322185be42e0c1 100644 --- a/React/Base/Surface/RCTSurfaceStage.m +++ b/React/Base/Surface/RCTSurfaceStage.m @@ -12,11 +12,11 @@ BOOL RCTSurfaceStageIsRunning(RCTSurfaceStage stage) { return (stage & RCTSurfaceStageSurfaceDidInitialLayout) && - !(stage & RCTSurfaceStageSurfaceDidInvalidate); + !(stage & RCTSurfaceStageSurfaceDidStop); } BOOL RCTSurfaceStageIsPreparing(RCTSurfaceStage stage) { return !(stage & RCTSurfaceStageSurfaceDidInitialLayout) && - !(stage & RCTSurfaceStageSurfaceDidInvalidate); + !(stage & RCTSurfaceStageSurfaceDidStop); }