From 963ea104013d4af73fb73d2223b256212aff129d Mon Sep 17 00:00:00 2001 From: KyleWong Date: Fri, 18 Jan 2019 18:26:39 +0800 Subject: [PATCH 1/2] Fix https://github.com/flutter/flutter/issues/26660 --- .../ios/framework/Source/FlutterViewController.mm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ca73791013b6c..db780876d75f9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -36,7 +36,7 @@ @implementation FlutterViewController { blink::ViewportMetrics _viewportMetrics; BOOL _initialized; BOOL _viewOpaque; - BOOL _engineNeedsLaunch; + BOOL _isEmbedEngine; } #pragma mark - Manage and override all designated initializers @@ -49,7 +49,7 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine if (self) { _viewOpaque = YES; _engine.reset([engine retain]); - _engineNeedsLaunch = NO; + _isEmbedEngine = FALSE; _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); _weakFactory = std::make_unique>(self); @@ -70,9 +70,9 @@ - (instancetype)initWithProject:(FlutterDartProject*)projectOrNil _engine.reset([[FlutterEngine alloc] initWithName:@"io.flutter" project:projectOrNil allowHeadlessExecution:NO]); + _isEmbedEngine = TRUE; _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); [_engine.get() createShell:nil libraryURI:nil]; - _engineNeedsLaunch = YES; [self loadDefaultSplashScreenView]; [self performCommonViewControllerInitialization]; } @@ -388,10 +388,9 @@ - (void)surfaceUpdated:(BOOL)appeared { - (void)viewWillAppear:(BOOL)animated { TRACE_EVENT0("flutter", "viewWillAppear"); - - if (_engineNeedsLaunch) { + if (_isEmbedEngine) { + [_engine.get() createShell:nil libraryURI:nil]; [_engine.get() launchEngine:nil libraryURI:nil]; - _engineNeedsLaunch = NO; } [_engine.get() setViewController:self]; From 5b463bb9f94623c1fe388049d68c887fa70dd119 Mon Sep 17 00:00:00 2001 From: KyleWong Date: Fri, 18 Jan 2019 20:42:29 +0800 Subject: [PATCH 2/2] Ignore touch events when FlutterViewController is not visible. --- .../darwin/ios/framework/Source/FlutterViewController.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index db780876d75f9..079e01b5b659e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -500,6 +500,8 @@ - (void)applicationWillEnterForeground:(NSNotification*)notification { // touch is specified in the second argument. - (void)dispatchTouches:(NSSet*)touches pointerDataChangeOverride:(blink::PointerData::Change*)overridden_change { + if (!(self.isViewLoaded && self.view.window)) + return; const CGFloat scale = [UIScreen mainScreen].scale; auto packet = std::make_unique(touches.count);