Skip to content

Commit

Permalink
Keep engine alive if VC is not deallocated (flutter#7544)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Jan 22, 2019
1 parent 88fee08 commit 2123d3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ - (void)setViewController:(FlutterViewController*)viewController {
FML_DCHECK(self.iosPlatformView);
_viewController = [viewController getWeakPtr];
self.iosPlatformView->SetOwnerViewController(_viewController);
if (!viewController && !_allowHeadlessExecution) {
[self maybeSetupPlatformViewChannels];
}

- (void)notifyViewControllerDeallocated {
if (!_allowHeadlessExecution) {
[self resetChannels];

_shell.reset();
_threadHost.Reset();
} else {
[self maybeSetupPlatformViewChannels];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- (FlutterTextInputPlugin*)textInputPlugin;
- (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
- (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
- (void)notifyViewControllerDeallocated;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ - (void)viewDidDisappear:(BOOL)animated {
}

- (void)dealloc {
[_engine.get() notifyViewControllerDeallocated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Expand Down

0 comments on commit 2123d3a

Please sign in to comment.