Skip to content

Commit

Permalink
RCTSurface: Stopping the app on surface object deallocation
Browse files Browse the repository at this point in the history
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 ba60751
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions React/Base/Surface/RCTSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_stage = _stage | RCTSurfaceStageBridgeDidLoad;
}

[self _registerRootViewTag];
[self _registerRootView];
[self _run];
}

Expand All @@ -94,6 +94,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge

- (void)dealloc
{
[self _stop];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion React/Base/Surface/RCTSurfaceStage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down
4 changes: 2 additions & 2 deletions React/Base/Surface/RCTSurfaceStage.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.