Permalink
Browse files

RCTSurface: Stopping the app on surface object deallocation

Reviewed By: rsnara

Differential Revision: D6431628

fbshipit-source-id: 2b3fd39d77a1108516f00727dd21f648c2bf41b1
  • Loading branch information...
shergin authored and facebook-github-bot committed Dec 4, 2017
1 parent 43b2509 commit ba6075120af9c0086b449aafa7420913fa58f746
Showing with 17 additions and 5 deletions.
  1. +14 −2 React/Base/Surface/RCTSurface.mm
  2. +1 −1 React/Base/Surface/RCTSurfaceStage.h
  3. +2 −2 React/Base/Surface/RCTSurfaceStage.m
@@ -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;
@@ -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
};
/**
@@ -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);
}

0 comments on commit ba60751

Please sign in to comment.