From 30fa906b30a791e22ea55ada1c53e2185a60e5eb Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 8 Apr 2020 12:24:42 -0700 Subject: [PATCH 1/5] add docs to platformviewios (and some drive-by changes) --- .../ios/framework/Source/FlutterEngine.mm | 1 - .../framework/Source/FlutterViewController.mm | 8 +--- .../framework/Source/accessibility_bridge.h | 7 ++++ .../framework/Source/accessibility_bridge.mm | 7 ++-- shell/platform/darwin/ios/platform_view_ios.h | 41 +++++++++++++++++-- .../platform/darwin/ios/platform_view_ios.mm | 10 +---- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 35cf9553b0c61..c7cca212714fa 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -394,7 +394,6 @@ - (void)maybeSetupPlatformViewChannels { [_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [_textInputPlugin.get() handleMethodCall:call result:result]; }]; - self.iosPlatformView->SetTextInputPlugin(_textInputPlugin); } } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index d051ff0038874..823426ed2cf07 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -417,10 +417,6 @@ - (void)installFirstFrameCallback { #pragma mark - Properties -- (FlutterView*)flutterView { - return _flutterView; -} - - (UIView*)splashScreenView { if (!_splashScreenView) { return nil; @@ -515,8 +511,8 @@ - (void)viewDidLoad { _engineNeedsLaunch = NO; } - FML_DCHECK([_engine.get() viewController] != nil) - << "FlutterViewController::viewWillAppear:AttachView ViewController was nil"; + FML_DCHECK([_engine.get() viewController] == self) + << "FlutterViewController shown but is not attached to a FlutterEngine"; [_engine.get() attachView]; [super viewDidLoad]; diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h index 7a990d965fc0b..cbb08421e17ac 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h @@ -27,6 +27,13 @@ namespace flutter { class PlatformViewIOS; +/** + * An accessibility instance is bound to one `FlutterViewController` and + * `FlutterView` instance. + * + * It helps populate the UIView's accessibilityElements property from Flutter's + * semantics nodes. + */ class AccessibilityBridge final : public AccessibilityBridgeIos { public: AccessibilityBridge(UIView* view, diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index c9c147bdacc55..4b25af93b4a53 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" -#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" #include "flutter/shell/platform/darwin/ios/platform_view_ios.h" @@ -38,7 +39,7 @@ } UIView* AccessibilityBridge::textInputView() { - return [platform_view_->GetTextInputPlugin() textInputView]; + return [[platform_view_->GetOwnerViewController().get().engine textInputPlugin] textInputView]; } void AccessibilityBridge::UpdateSemantics(flutter::SemanticsNodeUpdates nodes, diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index 95f6fc0ecfacf..b96267e200765 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -25,6 +25,18 @@ namespace flutter { +/** + * A bridge connecting the platform agnostic shell and the iOS embedding. + * + * The shell provides and requests for UI related data and this PlatformView subclass fulfills + * it with iOS specific capabilities. As an example, the iOS embedding (the `FlutterEngine` and the + * `FlutterViewController`) sends pointer data to the shell and receives the shell's request for a + * Skia GrContext and supplies it. + * + * Despite the name "view", this class is unrelated to UIViews on iOS and doesn't have the same + * lifecycle. It's a long lived bridge owned by the `FlutterEngine` and can be attached and + * detached sequentially to multiple `FlutterViewController`s and `FlutterView`s. + */ class PlatformViewIOS final : public PlatformView { public: explicit PlatformViewIOS(PlatformView::Delegate& delegate, @@ -33,21 +45,42 @@ class PlatformViewIOS final : public PlatformView { ~PlatformViewIOS() override; + /** + * The `PlatformMessageRouter` is the iOS bridge connecting the shell's + * platform agnostic `PlatformMessage` to iOS's channel message handler. + */ PlatformMessageRouter& GetPlatformMessageRouter(); + /** + * Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning + * this PlatformViewIOS. + */ fml::WeakPtr GetOwnerViewController() const; + + /** + * Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning + * this PlatformViewIOS. + */ void SetOwnerViewController(fml::WeakPtr owner_controller); + + /** + * Called one time per `FlutterViewController` when the `FlutterViewController`'s + * UIView is first loaded. + * + * Can be used to perform late initialization after `FlutterViewController`'s + * init. + */ void attachView(); + /** + * Called through when an external texture such as video or camera is + * given to the `FlutterEngine` or `FlutterViewController`. + */ void RegisterExternalTexture(int64_t id, NSObject* texture); // |PlatformView| PointerDataDispatcherMaker GetDispatcherMaker() override; - fml::scoped_nsprotocol GetTextInputPlugin() const; - - void SetTextInputPlugin(fml::scoped_nsprotocol plugin); - // |PlatformView| void SetSemanticsEnabled(bool enabled) override; diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index 772d5775bab6f..a5ae4af9ce129 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -99,6 +99,8 @@ void PlatformViewIOS::attachView() { FML_DCHECK(owner_controller_); + FML_DCHECK(owner_controller_.get().isViewLoaded) << "FlutterViewController's view should be loaded " + "before attaching to PlatformViewIOS."; ios_surface_ = [static_cast(owner_controller_.get().view) createSurface:ios_context_]; FML_DCHECK(ios_surface_ != nullptr); @@ -188,14 +190,6 @@ new AccessibilityBridge(static_cast(owner_controller_.get().view), [owner_controller_.get() platformViewsController]->Reset(); } -fml::scoped_nsprotocol PlatformViewIOS::GetTextInputPlugin() const { - return text_input_plugin_; -} - -void PlatformViewIOS::SetTextInputPlugin(fml::scoped_nsprotocol plugin) { - text_input_plugin_ = plugin; -} - PlatformViewIOS::ScopedObserver::ScopedObserver() : observer_(nil) {} PlatformViewIOS::ScopedObserver::~ScopedObserver() { From bebb1f0c56c5a10b0282249c7901ab317c129407 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 8 Apr 2020 12:29:04 -0700 Subject: [PATCH 2/5] a bit more import cleanups --- .../darwin/ios/framework/Source/accessibility_bridge.mm | 2 +- shell/platform/darwin/ios/platform_view_ios.mm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 4b25af93b4a53..57b23d5ab9e6a 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -6,7 +6,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" -#include "flutter/shell/platform/darwin/ios/platform_view_ios.h" +#import "flutter/shell/platform/darwin/ios/platform_view_ios.h" #pragma GCC diagnostic error "-Wundeclared-selector" diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index a5ae4af9ce129..80a8759d2b1ce 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -10,8 +10,8 @@ #include "flutter/fml/synchronization/waitable_event.h" #include "flutter/fml/trace_event.h" #include "flutter/shell/common/shell_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" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" namespace flutter { From 5d0b15152b5e6e3c1e28880906edc2a4b0056a17 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Thu, 9 Apr 2020 13:03:32 -0700 Subject: [PATCH 3/5] autoformat --- .../darwin/ios/framework/Source/accessibility_bridge.mm | 2 +- shell/platform/darwin/ios/platform_view_ios.mm | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 57b23d5ab9e6a..78f157381c182 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -3,8 +3,8 @@ // found in the LICENSE file. #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index 80a8759d2b1ce..d2f4cb48a26bd 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -99,8 +99,9 @@ void PlatformViewIOS::attachView() { FML_DCHECK(owner_controller_); - FML_DCHECK(owner_controller_.get().isViewLoaded) << "FlutterViewController's view should be loaded " - "before attaching to PlatformViewIOS."; + FML_DCHECK(owner_controller_.get().isViewLoaded) + << "FlutterViewController's view should be loaded " + "before attaching to PlatformViewIOS."; ios_surface_ = [static_cast(owner_controller_.get().view) createSurface:ios_context_]; FML_DCHECK(ios_surface_ != nullptr); From d10149c607b3cbd70dc5debf2d46c5f9dfcd9ddc Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 6 May 2020 00:19:50 -0700 Subject: [PATCH 4/5] add one more comment line --- shell/platform/darwin/ios/platform_view_ios.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index b96267e200765..a89192d908ca5 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -59,7 +59,8 @@ class PlatformViewIOS final : public PlatformView { /** * Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning - * this PlatformViewIOS. + * this PlatformViewIOS. This should be updated when the `FlutterEngine` + * is given a new `FlutterViewController`. */ void SetOwnerViewController(fml::WeakPtr owner_controller); From 2f311faa37308a2c4175dd8e4940b9e5232481a3 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Thu, 7 May 2020 12:13:51 -0700 Subject: [PATCH 5/5] tweak a sentence --- .../darwin/ios/framework/Source/FlutterViewController.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 823426ed2cf07..ea8afcf06e49d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -512,7 +512,7 @@ - (void)viewDidLoad { } FML_DCHECK([_engine.get() viewController] == self) - << "FlutterViewController shown but is not attached to a FlutterEngine"; + << "FlutterViewController's view is loaded but is not attached to a FlutterEngine"; [_engine.get() attachView]; [super viewDidLoad];