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

Conversation

@cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Aug 22, 2020

Description

This PR makes PlatformViewsController get FlutterViewController as early as possible when first launch.

Related Issues

Fixes flutter/flutter#64228

Tests

I added the following tests:

testViewFlutterViewControllerIsSetForPlatformView

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

This is fine to fix the immediate issue. We still have some problems if someone creates a headless engine and tries to make a platform view before assigning the VC

We also have problems if someone creates the engine first and the VC doesn't get shown soon enough (e.g. they use initWithEngine).

@cyanglaz
Copy link
Contributor Author

cyanglaz commented Aug 22, 2020

I think nevertheless, this helps the PlatformViewsController to get the FlutterViewController instance as early as possible in initWithProject scenarios.

I can also add a fix for headless mode too. Something like I mentioned in flutter/flutter#64228 (comment)

One alternative could be that we cache all the gesture recognizers that were created without 
FlutterViewController and SetFlutterViewController will go through those and set those.
Just need to add locks to make sure there are no synchronization issues since
onCreated is called on UIThread and SetFlutterViewController is called on PlatformThread.

@cyanglaz
Copy link
Contributor Author

cyanglaz commented Aug 22, 2020

Actually, for initWithEngine, we can set view controller to platformviewscontroller here: https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm#L108
If the PlatformViewsController has been initialized. If not, and when initializing PlatformViewsController, we can try to set the view controller again.

@cyanglaz cyanglaz force-pushed the set_flutter_view_eariler branch 2 times, most recently from f271130 to cfe0cd2 Compare August 22, 2020 03:52
return pixel[3];
}


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove extra newline

- (void)maybeSetupPlatformViewChannels {
if (_shell && self.shell.IsSetup()) {
if ([self platformViewsController] != nullptr) {
[self platformViewsController]->SetFlutterViewController([self viewController]);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this gets called from headless, we're toast :)

We could consider calling this from setViewController in here. In fact, I'm not clear on why we wouldn't.

But we could still run into the issue where the PlatformViewsController is created after the shell is, and the VC isn't attached until some later point in time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would this fail on headless? Unless they call this as private API, maybeSetupPlatformViewChannels is only called in 2 places in this class and both places look fine.

If the PlatformViewsController is created after the shell, maybeSetupPlatformViewChannels should be called in setViewController when FlutterViewController is available, which then it is possible for the platform views to receive touch events.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's called here:

[self maybeSetupPlatformViewChannels];

And we don't necessarily have a view controller yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

And that is called by runEngine, which is public API. And it's normal to call that before adding a VC to the engine or add to app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we can't fix this way then. Probably better to go back to the fix that we discussed in the issue.

@cyanglaz cyanglaz changed the title PlatformViewsController gets FlutterViewController as early as possible PlatformViewsController gets FlutterViewController as early as possible, PlatformViewsController update FlutterViewController when available Aug 22, 2020
@cyanglaz cyanglaz force-pushed the set_flutter_view_eariler branch from a2d2782 to 4b4be43 Compare August 22, 2020 16:23
@cyanglaz
Copy link
Contributor Author

@dnfield Updated so that PlatformViewsController can update FlutterViewController when available. I haven't added tests yet, will be back to add tests later. Also, it looks like current test for "setting flutter view controller earlier" timed out. I'm not entirely sure why :(

#include "flutter/shell/platform/darwin/ios/ios_context.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"

@class FlutterTouchInterceptingView;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to forward declare here because now FlutterTouchInterceptingView references to FlutterPlatformViewsController.

LongTerm, we should refactor all the objc class in this file to their own files.

@cyanglaz
Copy link
Contributor Author

@dnfield Ready for another review :)

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM

@cyanglaz cyanglaz changed the title PlatformViewsController gets FlutterViewController as early as possible, PlatformViewsController update FlutterViewController when available The ForwardingGestureRecognizers to have back reference to the PlatformViewsController so it can access FlutterViewController when its available Aug 24, 2020
@cyanglaz cyanglaz added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Aug 24, 2020
@fluttergithubbot fluttergithubbot merged commit 1c13aba into flutter:master Aug 24, 2020
cyanglaz pushed a commit to cyanglaz/engine that referenced this pull request Aug 24, 2020
…tformViewsController` so it can access `FlutterViewController` when its available (flutter#20708)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 24, 2020
…the `PlatformViewsController` so it can access `FlutterViewController` when its available (flutter/engine#20708)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 24, 2020
…the `PlatformViewsController` so it can access `FlutterViewController` when its available (flutter/engine#20708)
christopherfujino added a commit that referenced this pull request Aug 27, 2020
* update dart revision
* Fix EGL_BAD_SURFACE when app is paused (#20735)
* The `ForwardingGestureRecognizers` to have back reference to the `PlatformViewsController` so it can access `FlutterViewController` when its available  (#20708)
* Remove image sizes from Picture::GetAllocationSize (#20673)
* update licenses golden

Co-authored-by: Emmanuel Garcia <[email protected]>
Co-authored-by: Chris Yang <[email protected]>
Co-authored-by: Jason Simmons <[email protected]>
christopherfujino added a commit that referenced this pull request Aug 31, 2020
* Update 1.20 engine to use Dart 2.9.2
* update license goldens
* Fix EGL_BAD_SURFACE when app is paused (#20735)
* The `ForwardingGestureRecognizers` to have back reference to the `PlatformViewsController` so it can access `FlutterViewController` when its available  (#20708)
* cherry-pick e09af86
* skip linting since this was enabled in CI after this release branch cut commit.

Co-authored-by: Emmanuel Garcia <[email protected]>
Co-authored-by: Chris Yang <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[webView_flutter][iOS] WebView is frozen in release mode with flutter 1.20.2 stable version

4 participants