-
Notifications
You must be signed in to change notification settings - Fork 6k
[macos] expose runWithEngine constructor in FlutterViewController (#7… #36410
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| } @catch (...) { | ||
| return false; | ||
| } |
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.
(note for @cbracken not @dubik) I know this pattern was copied from the other tests in this file but why are these tests returning bool (it's not even BOOL...) instead of failing in place? For example this @catch hides the details of any exception instead of letting XCTest fail the test with the actual thing that happened.
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.
That's an excellent question that'll involve some archaeology. We should leave this for now and I'll follow-up with a cleanup PR once I figure out what the history of this was.
|
From PR review triage: It looks like this PR needs feedback from @cbracken. |
| } | ||
| _engine = engine; | ||
| CommonInit(self); | ||
| [engine setViewController:self]; |
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.
Bypassing the initialization logic by using .viewController = instead of setViewController seems very hacky. I'm surprised that viewController is not readonly (I suggest we make it so).
It feels to me that this PR complexes the relationship between FVC and FlutterEngine, which can be seen from the three initializeKeyboard calls throughout the file. It's hard to track how many ways are there we expect to use FVC and whether a line is executed by each, as well as how to add a new line to the initialization.
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.
Commenting only about
Bypassing the initialization logic by using
.viewController =instead ofsetViewControllerseems very hacky.
That's just Objective-C, they are completely identical under the covers. The dot notation .viewController = is a more idiomatic way to set a 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.
It feels to me that this PR complexes the relationship
It does. When the existing engine is passed, it can be running or not. So that increases the complexity of the initializer and the patch adds basically one if which loads FlutterView and initializes the keyboard if it's running. So to me the added complexity doesn't look excessive.
It's hard to track how many ways are there we expect to use FVC and whether a line is executed by each, as well as how to add a new line to the initialization.
There is CommonInit and all initializers use it. initWithEngine handles the case when the engine is running and I could extract that into the method, but I couldn't come up with a good name and it doesn't clarify anything in that context.
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.
three initializeKeyboard calls
To me, the story with the keyboard is rather complicated. There are quite a few cases to handle, and I'm not sure controller is the best place for that. There is a TODO comment in initializeKeyboard which I guess, could solve some of the problems. But fixing that TODO goes way beyond my capabilities/knowledge of the engine's internals.
- Engine is not running, then
FVCis created (displayingFVCwill start the engine) - Engine is running, then
FVCis created - Engine is not running, then
FVCis created, and the engine is started by the user, and laterFVCis shown (not handled by this patch, butviewWillAppearperhaps should check if the keyboard was correctly configured before)
One solution could be that the engine would fire an event when it's started, and FVC would subscribe to that. This can simplify keyboard initialization for cases 1. and 3.
|
From Triage: Looks like the conversation here didn't come to a clear conclusion on direction. Are we still making progress on this? |
|
@chinmaygarde are you asking the reviewers or me? |
|
Both I guess. Couldn't tell if there was consensus to make progress on this patch. |
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.
Overall this approach lgtm; we're going to want to add a devicelab test for this in the framework as well, which we'll need to do in a separate patch.
I necessarily agree this makes the code much more complex than it already is, but agree we should do some work to simplify what's already there. It does add one (really two: already running engine, not yet running engine) additional cases to consider for maintainers of the code.
I'll play around with this a bit this evening the finish up the review. Thanks again for the patch.
It could look like |
cbracken
left a comment
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.

…4735)
Exposes runWithEngine in FlutterViewController as suggested by jmagman in #74735
Fixes: flutter/flutter#74735
Removing
[engine setViewController:self];because view is not loaded, but in that function controller is saved. Later, when the view is loaded (loadView) passed as an argument controller is checked against the saved controller and since they match, thenilview is not replaced with a new view.Pre-launch Checklist
writing and running engine tests.
///).