-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Add a viewController
getter to the ios FlutterPluginRegistrar
protocol
#174168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add a viewController
getter to the ios FlutterPluginRegistrar
protocol
#174168
Conversation
Hi @loic-sharma according to Multi-view runner APIs the only plugin registrar change required to add multiview support to the macOS plugin registrar is to add a get view by id method (which is pretty similar to what this PR does but for macOS). But adding that method now will require some plugins to add a |
@@ -34,7 +34,7 @@ FLUTTER_DARWIN_EXPORT | |||
* @param frame The rectangle for the newly created `UIView` measured in points. | |||
* @param viewId A unique identifier for this `UIView`. | |||
* @param args Parameters for creating the `UIView` sent from the Dart side of the Flutter app. | |||
* If `createArgsCodec` is not implemented, or if no creation arguments were sent from the Dart | |||
* If `createArgsCodec` is not implemented, or if no creation arguments were sent from the Dart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(unrelated change, removed an invisible character)
For iOS that seems reasonable, yes. Plumbing view IDs around is a significant/painful migration, so it seems reasonable to do separate migrations for |
To answer my own question regarding whether the platform view factory registration methods on the registrar interface would need a view ID parameter: looks like each layer (including those representing platform views) knows which view it is supposed to render on, so it probably doesn't need a view ID. flutter/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm Lines 71 to 132 in 5c23f4c
|
#104117
Adds a
viewController
(per #104117 (comment), presumably because iOS plugins want to presenting new view controllers) getter that makes the single-view assumption. This is a method instead of a weak + readonly property like the macOS registrar protocol because existing getters are also methods, e.g.,Unfortunately swift callers will have to use a preprocess macro and add different code paths for macOS and iOS.
Single view assumption
I've considered adding a
- (nullable UIViewController*)viewControllerForViewID: ViewIDType;
method but that will force plugins to make breaking changes in order to migrate off of the deprecatedkeyWindow
property. Take the text input plugin as an example, it has to add aviewID
argument to thesetTextInputClient
call when establishing a new text input connection, so the text input plugin knows which view hierarchy to add the text input view to. It is unclear to me whether moreFlutterPluginRegistrar
changes are needed to completely get rid of the single-view assumption in the protocol (the viewsFlutterPlatformViewFactory
creates are always added as subviews toflutterView
so I guess that interface may have to change in the future? According to according to Flutter’s multi-window status, only aviewForIdentifier
method will be added to registrar), so IMO it would be a better experience to not introduce theviewID
concept right now and force plugins to make break changes, since they may have to make more breaking changes in the future.Alternatively, we could also ignore the
viewID
args for now and always return the view controller of the implicit view in the implementation, so that plugin authors can use made-up view IDs to get the implicit view controller. But that's going to make future multiview migrations difficult since the compiler won't be able to catch unmigrated code if the plugin is using a bogus view ID.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.