Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@sergiy-sc
Copy link
Contributor

…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, the nil view is not replaced with a new view.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@google-cla
Copy link

google-cla bot commented Sep 26, 2022

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.

Comment on lines +264 to +266
} @catch (...) {
return false;
}
Copy link
Member

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.

Copy link
Member

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.

@zanderso
Copy link
Member

From PR review triage: It looks like this PR needs feedback from @cbracken.

}
_engine = engine;
CommonInit(self);
[engine setViewController:self];
Copy link
Contributor

@dkwingsmt dkwingsmt Sep 29, 2022

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.

Copy link
Member

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 of setViewController seems 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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

  1. Engine is not running, then FVC is created (displaying FVC will start the engine)
  2. Engine is running, then FVC is created
  3. Engine is not running, then FVC is created, and the engine is started by the user, and later FVC is shown (not handled by this patch, but viewWillAppear perhaps 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.

@chinmaygarde
Copy link
Member

From Triage: Looks like the conversation here didn't come to a clear conclusion on direction. Are we still making progress on this?

@sergiy-sc
Copy link
Contributor Author

@chinmaygarde are you asking the reviewers or me?

@chinmaygarde
Copy link
Member

Both I guess. Couldn't tell if there was consensus to make progress on this patch.

Copy link
Member

@cbracken cbracken left a 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.

@jmagman
Copy link
Member

jmagman commented Oct 7, 2022

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.

It could look like module_test_ios but using flutter build macos-framework integration and need an example app like
https://github.com/flutter/samples/tree/main/add_to_app/prebuilt_module

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience - a lot of us were in meetings all week. Spent some time trying to break this and it lgtm :)

LGTM stamp from a Japanese personal seal

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FlutterViewController needs a way to correctly start running before being shown on macOS

6 participants