diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 798839fab4d1c..2b2245cecf729 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -152,6 +152,18 @@ return canvas; } +void FlutterPlatformViewsController::Reset() { + UIView* flutter_view = flutter_view_.get(); + for (UIView* sub_view in [flutter_view subviews]) { + [sub_view removeFromSuperview]; + } + views_.clear(); + overlays_.clear(); + composition_order_.clear(); + active_composition_order_.clear(); + composition_frames_.clear(); +} + bool FlutterPlatformViewsController::Present() { bool did_submit = true; for (size_t i = 0; i < composition_frames_.size(); i++) { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 92d308c244d43..337bcc50e552a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -53,6 +53,9 @@ class FlutterPlatformViewsController { const flow::EmbeddedViewParams& params, IOSSurface& surface); + // Discards all platform views instances and auxiliary resources. + void Reset(); + bool Present(); void OnMethodCall(FlutterMethodCall* call, FlutterResult& result); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 9c160cef29034..c145bf292eea8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -31,7 +31,6 @@ @implementation FlutterViewController { fml::scoped_nsobject _flutterView; fml::scoped_nsobject _splashScreenView; fml::ScopedBlock _flutterViewRenderedCallback; - std::unique_ptr _platformViewsController; UIInterfaceOrientationMask _orientationPreferences; UIStatusBarStyle _statusBarStyle; blink::ViewportMetrics _viewportMetrics; @@ -891,7 +890,7 @@ - (void)onPreferredStatusBarStyleUpdated:(NSNotification*)notification { #pragma mark - Platform views - (shell::FlutterPlatformViewsController*)platformViewsController { - return _platformViewsController.get(); + return [_engine.get() platformViewsController]; } #pragma mark - FlutterBinaryMessenger diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index 50e8fa7a1ec35..2835431de94d8 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -70,6 +70,9 @@ class PlatformViewIOS final : public PlatformView { // |shell::PlatformView| std::unique_ptr CreateVSyncWaiter() override; + // |shell::PlatformView| + void OnPreEngineRestart() const override; + FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS); }; diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index 6a701d06669da..48a555822cab4 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -12,6 +12,7 @@ #include "flutter/fml/synchronization/waitable_event.h" #include "flutter/fml/trace_event.h" #include "flutter/shell/common/io_manager.h" +#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" #include "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" #include "flutter/shell/platform/darwin/ios/ios_external_texture_gl.h" @@ -118,6 +119,13 @@ return std::make_unique(task_runners_); } +void PlatformViewIOS::OnPreEngineRestart() const { + if (!owner_controller_) { + return; + } + [owner_controller_.get() platformViewsController] -> Reset(); +} + fml::scoped_nsprotocol PlatformViewIOS::GetTextInputPlugin() const { return text_input_plugin_; }