-
Notifications
You must be signed in to change notification settings - Fork 6k
[iOS] Fix platfotm view called multiple times #19292
[iOS] Fix platfotm view called multiple times #19292
Conversation
|
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. |
|
@blasten As I remembered, after landing unobstructed platform views, we recommend against creating new views each time when @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 |
|
@zhongwuzw You are right, "we only create a new view when init rather than each frame". I think the engine calls the I think this PR does fix the issue. However, I'm more worried about plugins starting to call UIView's constructor in |
…fotm_view_called_multiple_times
|
@cyanglaz To print out a warning, we need to call |
|
@zhongwuzw FML_DCHECK only runs in debug mode. I think maybe we can utilize it? Something like: |
@cyanglaz I added. |
shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Outdated
Show resolved
Hide resolved
cyanglaz
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.
Code looks good! Can we test this? Maybe in https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm?
|
@cyanglaz To test whether |
|
@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. |
|
@cyanglaz I think we can't catch the crash( |
|
@zhongwuzw 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 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. |
94e6386 to
fff8d8d
Compare
|
Offline discussion: The code looks good.
|
|
@cyanglaz Done. |
cyanglaz
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.
LGTM!
…fotm_view_called_multiple_times
|
This pull request is not suitable for automatic merging in its current state.
|
|
@zhongwuzw CI seems still failing and upstream is green. Maybe rebase and try again? |
…fotm_view_called_multiple_times
Description
Related Prs: #17336
cc. @blasten
Users may return a newly created embedded view when call
viewmethod ofFlutterPlatformViewprotocol. After #17336, we callviewmethod ofFlutterPlatformViewprotocol multiple times, causesGetPlatformViewRectreturn 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.Breaking Change
Did any tests fail when you ran them? Please read handling breaking changes.