-
Notifications
You must be signed in to change notification settings - Fork 6k
Add warning message when PlatformView's origin is not 0 #35501
Add warning message when PlatformView's origin is not 0 #35501
Conversation
| XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); | ||
| XCTAssertEqual(platform_view.frame.origin.x, 25); | ||
| XCTAssertEqual(platform_view.frame.origin.y, 25); | ||
| XCTAssertEqual(platform_view.frame.origin.x, 0); |
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.
Since the frame of the platform view changed, there are some changes in the frame of the platform views and overlays in this test.
| finishBuilder( | ||
| builder, | ||
| overlayOffset: const Offset(150, 250), | ||
| overlayOffset: const Offset(150, 240), |
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.
Because the platform view's frame changed, the old offset won't create an overlay. To make the test valid again, i had to update the offset so that the widget is partially cover the platformview and an overlay is created.
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.
I think this is an iOS only test so no android tests are effected by this change.
| if (!CGPointEqualToPoint([touchInterceptor embeddedView].frame.origin, CGPointZero)) { | ||
| FML_LOG(WARNING) | ||
| << "Embedded PlatformView's origin is not CGPointZero." | ||
| "A none-zero origin might cause undefined behavior." |
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.
non-zero (and below).
Do we want them to file a new issue or to add a comment to the existing issue?
How does an application developer fix their code if they see this warning?
We should at least log the view_id, which hopefully is enough for them to figure out which view it is - if it's possible to tell them something about the type that would be good too (e.g. if an application has multiple platform views).
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.
Do we want them to file a new issue or to add a comment to the existing issue?
This is a good point, ill instead ask them to comment on the issue.
How does an application developer fix their code if they see this warning?
There is probably nothing they can do. It would be the same behavior they have been had. They will just have to ignore this error message. (It can be annoying seeing this every frame tho, I can add some code to only print this once. I'm not sure how to test this tho)
We should at least log the view_id, which hopefully is enough for them to figure out which view it is - if it's possible to tell them something about the type that would be good too (e.g. if an application has multiple platform views).
Good point, will do.
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.
How about we ifdef this out of release and profile builds, and just keep a set of view_ids - if the set contains the ID don't print the message, otherwise insert it and print.
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.
We should also make sure that this log level gets printed from the command line in an opt build without specifying --verbose-system-logs.
| binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger { | ||
| if ([super init]) { | ||
| _textView = [[UITextView alloc] initWithFrame:CGRectMake(50.0, 50.0, 250.0, 100.0)]; | ||
| _textView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.0, 100.0)]; |
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.
I know you asked offline, but I'm pretty sure I did this as a way to arbitrarily position the text within the view.
This seems like a valid use case to me and I'm not really sure why we need to restrict it. I think that if we pursue this,we should make sure the warning lands for at least a full stable cycle and we collect feedback on that before changing it.
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.
For example, in testing/scenario_app/ios/Scenarios/ScenariosUITests/golden_platform_view_clippath_iPhone 8_13.0_simulator.png the text is no longer as visible.
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.
The PlatformView developer should not determine where the PlatformView is displayed, the frame of the PlatformView should be determined by the user of the PlatformView. So the widget tree should be the source of truth where the PlatformView widget is displayed.
PlatformView developer can determine where the subviews of PlatformView is displayed, that is allowed. In this case, they will create the PlatformView with 0 origin and create a subview inside the PlatformView to position it arbitrarily. However, this can create an issue where in theory -- not sure what is a valid use case -- PlatformView developer can create a PlatformView that has a subview displaying way outside of the PlatformView widget's frame. It messed up the unobstructed platform view logic, which we used to determine the frame of overlays.
And I'm not sure how we can prevent it unless we loop through all the subviews of the PlatformView.
So I do think it is valid to restrict this, at least to give a warning. Because this change is harmless, we can wait for some time to gather feedbacks and decided if we should revert this or add the hard restriction.
For example, in testing/scenario_app/ios/Scenarios/ScenariosUITests/golden_platform_view_clippath_iPhone 8_13.0_simulator.png the text is no longer as visible.
~One thing we can do is to have a plain UIView as the PlatformView and having the textView to be a child of the UIView, where the origin of textView is (50, 50), so the text are still visible in those screenshots.
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.
Makes sense.
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.
We may want to print this kind of explanation in the warning.
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.
....alternatively, should we just automatically wrap non-zero origin in a UI view with a zero origin?
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.
....alternatively, should we just automatically wrap non-zero origin in a UI view with a zero origin?
Yeah we can do that when we know there is no valid case of having a non-zero origin. However, it doesn't solve the problem when there is a subview of the PlatformView displaying outside of the frame. Maybe clipToBounds is a better solution.
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.
We may want to print this kind of explanation in the warning.
This is explained in flutter/flutter#109700, i think having a link and ask people to comment on the issue is probably sufficient.
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.
....alternatively, should we just automatically wrap non-zero origin in a UI view with a zero origin?
Yeah we can do this, this can change the behavior of the platform view so we will wait for feedbacks before implement it.
|
If we don't receive any valid use case of displaying PlatformView outside of the frame, a potential fix is to have clipToBounds to be true. |
| << "Embedded PlatformView's origin is not CGPointZero." | ||
| "A none-zero origin might cause undefined behavior." | ||
| "If you are the author of the PlatformView and you have a valid case of using a " | ||
| "none-zero origin," |
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.
Dan already said this, but the typo is also here.
| "none-zero origin," | |
| "non-zero origin," |
|
Error message looks like: |
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.
| UIView* touchInterceptor = touch_interceptors_[view_id].get(); | ||
| FlutterTouchInterceptingView* touchInterceptor = touch_interceptors_[view_id].get(); | ||
| #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG | ||
| FML_CHECK(CGPointEqualToPoint([touchInterceptor embeddedView].frame.origin, CGPointZero)); |
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.
Please make this a dcheck.
This will cause the application to crash in debug mode for end developers.
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.
(as opposed to a crash/test failure for unopt builds by engine developers)
dnfield
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.
Once the comment about the FML_CHECK is addressed this LGTM.
|
|
In #35501, handling was added to log a debug message to the console in the case where a platform view with a non-zero origin was identified. Unfortunately: * In unopt builds, the first thing we do in that block is to call FML_DCHECK asserting that the origin is zero, so we never actually emit the log statement. * In opt builds, FML_DCHECK is a no-op, so users are unlikely to actually ever notice the crash. The proper fix is to eliminate this restriction, but in the meantime, this eliminates this block entirely and leaves the TODO. We've had only two comments on that bug in the 2.5 years since it was added. Issue: flutter/flutter#109700 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…ne#56796) In flutter/engine#35501, handling was added to log a debug message to the console in the case where a platform view with a non-zero origin was identified. Unfortunately: * In unopt builds, the first thing we do in that block is to call FML_DCHECK asserting that the origin is zero, so we never actually emit the log statement. * In opt builds, FML_DCHECK is a no-op, so users are unlikely to actually ever notice the crash. The proper fix is to eliminate this restriction, but in the meantime, this eliminates this block entirely and leaves the TODO. We've had only two comments on that bug in the 2.5 years since it was added. Issue: flutter#109700 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Add a DCheck and warning message when PlatformView's origin is not 0.
This PR also updates the PlatformView in scenario app to have a none-zero origin.
First step of: flutter/flutter#109700
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.