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

Conversation

@zhongwuzw
Copy link
Member

Description

Related Prs: #17336
cc. @blasten

Users may return a newly created embedded view when call view method of FlutterPlatformView protocol. After #17336, we call view method of FlutterPlatformView protocol multiple times, causes GetPlatformViewRect return incorrect rect.

Related Issues

flutter/flutter#59751

Tests

I added the following tests:

N/A.

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.

@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@auto-assign auto-assign bot requested a review from chinmaygarde June 25, 2020 00:10
@zanderso zanderso requested review from cbracken and removed request for chinmaygarde September 10, 2020 22:00
@cyanglaz
Copy link
Contributor

cyanglaz commented Oct 8, 2020

@blasten As I remembered, after landing unobstructed platform views, we recommend against creating new views each time when view is called.
I have opened an issue to track documentation efforts. flutter/flutter#56736

@zhongwuzw Is there a way you can workaround the issue by not creating a new UIView each frame?

@zhongwuzw
Copy link
Member Author

zhongwuzw commented Oct 12, 2020

@blasten As I remembered, after landing unobstructed platform views, we recommend against creating new views each time when view is called.
I have opened an issue to track documentation efforts. flutter/flutter#56736

@zhongwuzw Is there a way you can workaround the issue by not creating a new UIView each frame?

@cyanglaz Did I miss something? 😄 I think we only create a new view when init rather than each frame? my PR fixes flutter/flutter#59751 because we call view of FlutterPlatformView twice when we create UIView, it's unnecessary.

@cyanglaz
Copy link
Contributor

@zhongwuzw You are right, "we only create a new view when init rather than each frame". I think the engine calls the view method multiple times that's why we recommend not to initialize the UIView instance in the view method.

I think this PR does fix the issue. However, I'm more worried about plugins starting to call UIView's constructor in view, which is a bad practice. I wonder if we can maybe print out a warning if the UIView was created multiple times during a single frame.

@zhongwuzw
Copy link
Member Author

@cyanglaz To print out a warning, we need to call view multiple twice for the check, I think maybe it would cause performance issues. What do you think? 🤔

@cyanglaz
Copy link
Contributor

@zhongwuzw FML_DCHECK only runs in debug mode. I think maybe we can utilize it? Something like:

UIView* platformView = [embedded_view view];
FML_DCHECK(platformView == [embedded_view view], "The [view] method should not return a new instance of UIView during the same frame.");

@zhongwuzw
Copy link
Member Author

@zhongwuzw FML_DCHECK only runs in debug mode. I think maybe we can utilize it? Something like:

UIView* platformView = [embedded_view view];
FML_DCHECK(platformView == [embedded_view view], "The [view] method should not return a new instance of UIView during the same frame.");

@cyanglaz I added.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

@zhongwuzw
Copy link
Member Author

@cyanglaz To test whether FML_DCHECK works? 🤔 we just add an FML_DCHECK, maybe we don't need it.

@cyanglaz
Copy link
Contributor

@zhongwuzw It would be nice if we have a test to make sure that if [view] returns different instance in a single frame, the plugin will receive the crash.

@zhongwuzw
Copy link
Member Author

@cyanglaz I think we can't catch the crash(abort()). 🤔

@zhongwuzw zhongwuzw changed the title Fix platfotm view called multiple times [iOS] Fix platfotm view called multiple times Oct 19, 2020
@cyanglaz
Copy link
Contributor

@zhongwuzw
After thinking about it twice, I actually liked your original idea better. I wanted to apologize for the back and force. I think we should revert all the changes after my review and get the code back to the original state of the PR. 

There was one thing I was afraid of, which was that after the fix, engine devs could still call [views_[0] view] to get the view and mess things up without knowing. (That was the major reason I didn't like the change)After another look at the code, I think we can actually get rid of views_ because there was no other critical sessions in the code that uses views_, expect some usage of .count(), which can be substituted by root_views_[0].count() or interceptors_[0].count()

Then we can actually test it by checking the instance of the platform view to always be the same even the factory returns a new instance every time. 

WDYT? Would you be willing to do that? :) I appreciate your patients in advance. 

@zhongwuzw zhongwuzw force-pushed the fix_platfotm_view_called_multiple_times branch from 94e6386 to fff8d8d Compare November 5, 2020 08:27
@cyanglaz
Copy link
Contributor

Offline discussion: The code looks good.
Need some updates in the tests:

  1. Remove the enableViewCreateOnceCheck in the unit test
  2. Possibly add the same "only call once" check in the scenario app and make sure the scenario app doesn't crash.

@zhongwuzw
Copy link
Member Author

@cyanglaz Done.

Copy link
Contributor

@cyanglaz cyanglaz 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 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 Nov 17, 2020
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux Android AOT Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 17, 2020
@cyanglaz
Copy link
Contributor

@zhongwuzw CI seems still failing and upstream is green. Maybe rebase and try again?

@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 Nov 18, 2020
@fluttergithubbot fluttergithubbot merged commit cfdcfca into flutter:master Nov 18, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
chaselatta pushed a commit to chaselatta/engine that referenced this pull request Nov 30, 2020
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.

4 participants