-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[macOS] Formalize FlutterViewController's initialization flow, and prohibit replacing #38981
Conversation
@@ -18,7 +18,7 @@ | |||
* backward compatibility, single-view APIs will always operate the view with | |||
* this ID. Also, the first view assigned to the engine will also have this ID. | |||
*/ | |||
constexpr uint64_t kFlutterDefaultViewId = 0; | |||
constexpr uint64_t kFlutterDefaultViewId = 1; |
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.
Just so this comment isn't lost: #38855 (comment)
Consider double-checking with @goderbauer that the framework does not have any expectations that the default view has an ID of 0
.
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.
The framework makes no assumption about the value of the id. Why does this have to change from 0 to 1, though?
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.
LGTM, but please get sign-off from folks that are more familiar with the macOS embedder
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.
LGTM
shell/platform/darwin/macos/framework/Headers/FlutterViewController.h
Outdated
Show resolved
Hide resolved
@@ -18,7 +18,7 @@ | |||
* backward compatibility, single-view APIs will always operate the view with | |||
* this ID. Also, the first view assigned to the engine will also have this ID. | |||
*/ | |||
constexpr uint64_t kFlutterDefaultViewId = 0; | |||
constexpr uint64_t kFlutterDefaultViewId = 1; |
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.
The framework makes no assumption about the value of the id. Why does this have to change from 0 to 1, though?
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Headers/FlutterViewController.h
Outdated
Show resolved
Hide resolved
/** | ||
* The identifier for this view controller. | ||
* | ||
* The ID is assigned when the view controller is added to FlutterEngine. |
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.
Maybe expand on this, like:
* The ID is assigned when the view controller is added to FlutterEngine. | |
* The ID is assigned when the view controller is assigned to the | |
* FlutterEngine.viewController property. |
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.
The mechanism is a little more complicated than this, so I decided to explain everything in FlutterViewController's doc. Can you take a look?
shell/platform/darwin/macos/framework/Headers/FlutterViewController.h
Outdated
Show resolved
Hide resolved
@cbracken @goderbauer I should have addressed all your comments. Can you take another look? |
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.
LGTM
* Some single-view APIs will eventually be replaced by their multi-view | ||
* variant. During the deprecation period, the single-view APIs will coexist with | ||
* and work with the multi-view APIs as if the other views don't exist. For | ||
* backward compatibility, single-view APIs will always operate the view with |
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.
nit: operate on (or something like that)?
…ion flow, and prohibit replacing (flutter#38981)" (flutter#39144)" This reverts commit 36db005.
…ow, and prohibit replacing (flutter/engine#38981)
…119208) * e3b278239 [macOS] Formalize FlutterViewController's initialization flow, and prohibit replacing (flutter/engine#38981) * 36db005dd Revert "[macOS] Formalize FlutterViewController's initialization flow, and prohibit replacing (#38981)" (flutter/engine#39144) * a20609120 Roll buildroot (flutter/engine#39141) * 8f1e5dc1b Reland "[macOS] Formalize FlutterViewController's initialization flow, and prohibit replacing" (flutter/engine#39145)
FlutterViewController.id
, and formalizes howFlutterViewController
is initialized byFlutterEngine
:FlutterViewController
is set to the engine, the engine callsFlutterViewController#attachToEngine:withId:
.FlutterViewController
is unset from the engine, the engine callsFlutterViewController#detachFromEngine
.This allows the ID to be generated by the engine.
The default View ID is now 1 instead of 0. In this way, we can use 0 as an empty value, the value for
FlutterViewController.id
when the FVC is not attached to an engine. (IDs are meant to be opaque, and views should be a map, not an array anyway.)This PR moves almost all initialization code into
FVC
'sCommonInit
to ensure that all init path produces the expected result.With this PR, FlutterEngine no long supports replacing viewController (from non-null to a different non-null). Setting the view controller (from null to non-null) is intended to allow pre-warming an engine before displaying it in add-to-app, but replacing the view controller does not make much sense.
As a result, unit tests that used to create
FVC
with the wrong initializer are fixed.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.