-
Notifications
You must be signed in to change notification settings - Fork 6k
Use getBoundingRects to add support inset MediaQuery/SafeArea when in freeform mode controls are shown. #54294
Use getBoundingRects to add support inset MediaQuery/SafeArea when in freeform mode controls are shown. #54294
Conversation
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Outdated
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterView.java
Outdated
Show resolved
Hide resolved
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 outside of nit
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Outdated
Show resolved
Hide resolved
Is this blocked on anything? Looks good to go. |
It is waiting on my review. I was reviewing the internal cl which has the test but the files diverged. |
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
||
if (Build.VERSION.SDK_INT >= API_LEVELS.API_35) { | ||
List<Rect> boundingRects = delegate.getCaptionBarInsets(getContext()); | ||
if (boundingRects != null && boundingRects.size() == 1) { |
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.
Why is it safe to ignore the boundingRects at positions 2 and beyond?
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 had assumed the caption bar would have only one rect. If this is false, what would you suppose we do if there are more, considering that the viewport metrics describe only a bounding rect for the view? Get the maximum to use for the padding value?
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 can sometimes work from assumptions. I am asking what evidence justifies ignoring that the api returns a list. I dont know if bounding recs are a single value or list. That is your responsibility as the author of a change.
When/if we would get multiple recs would help us decide what to do? Assuming we dont have that information then I would think the largest value is probably the one to choose.
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** A delegate class that performs the task of retrieving the bounding rect values. */ |
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.
Is there anything you can add here to let future maintainers know when logic should go into FlutterViewDelegate vs sendViewportMetricsToFlutter
/** A delegate class that performs the task of retrieving the bounding rect values. */ | ||
public class FlutterViewDelegate { | ||
/** | ||
* Return the WindowInsets object for the provided Context. Returns null if there is no associated |
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.
Can you document when 2 different context objects might have different windowInsets?
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.
Can you explain why this detail is relevant documentation to this method? I'm not sure I see the throughline.
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 dart docs is a hint for callers and for maintainers to help understand the behavior of the code documented. The existing dart doc, as written, helps a little bit by describing the null behavior but it could be more helpful if it describe when context might change. That is because the caller can know for their use case of FlutterViewDelegate if it matters which context to pass.
For example if the android documentation indicates that window insets will always be the same for an app regardless of which of the apps context is used it indicated to the caller that it might be safe in situations when launching another activity to use the application context. However if insets might change across activities maybe because of their window flags then it is important to use one FlutterViewDelate per activity.
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Outdated
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterView.java
Outdated
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterView.java
Outdated
Show resolved
Hide resolved
public void setDelegate(@NonNull FlutterViewDelegate delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
private void sendViewportMetricsToFlutter() { |
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.
Looking at the design of this class I am seeing a pattern of the flutterView having methods that trigger on different android lifecycle events, Then ViewportMetrics being updated then at the end of that triggering method calling sendViewportMetricsToFlutter
.
Looking at this code we do the calculation every send. When I was searching internally I did not find documentation of a lifecycle method to trigger on so maybe this is moot. If this code moved to onApplyWindowInsets would it still work?
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 just tested this, and it looks good. I've moved it to onApplyWindowInsets
after the existing calculations.
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.
Digging into go/customizable-window-headers I found APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND Can you test an app with that flag set vs the default and come up with a recommendation on if we should apply transparent caption bar by default or not?
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.
This comment should not be considered blocking.
* Return the WindowInsets object for the provided Context. A Context will only have a window if | ||
* it is an instance of Activity. If context does not have a window, or it is not an activity, | ||
* this method will return null. Otherwise, this method will return the WindowInsets for the | ||
* provided activity's window. |
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.
Great documentation
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Outdated
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterViewDelegate.java
Outdated
Show resolved
Hide resolved
…ea when in freeform mode controls are shown. (flutter/engine#54294)
…153781) flutter/engine@e10b075...d6bc4dc 2024-08-20 [email protected] Use getBoundingRects to add support inset MediaQuery/SafeArea when in freeform mode controls are shown. (flutter/engine#54294) 2024-08-20 [email protected] Manual roll Dart SDK from c5264a1bd1d2 to c22bf5aedbcf (2 revisions) (flutter/engine#54646) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#153781) flutter/engine@e10b075...d6bc4dc 2024-08-20 [email protected] Use getBoundingRects to add support inset MediaQuery/SafeArea when in freeform mode controls are shown. (flutter/engine#54294) 2024-08-20 [email protected] Manual roll Dart SDK from c5264a1bd1d2 to c22bf5aedbcf (2 revisions) (flutter/engine#54646) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@yaakovschectman Please take a look, this submission affects all Futter3.27.X In all Xiaomi Android 15 devices, in the suspended window mode, all apps built by Futter3.27.X will be white screen |
@mengyanshou yaakov no longer contributes to flutter it is unlikely you will get a response. Please file an issue so that the triage process can start. |
Original Title: Add FlutterViewDelegate and BoundingRect methods
Check the bounding rect for caption bar when sending viewport metrics to Flutter to account for freeform mode. Use the more recent
getBoundingRects
overgetInsets
.Tests will need to be kept separate until Robolectric publishes a version that supports API level 35.
Roboletric tests for this pr will be part of google testing until then.
Pr for tests here https://critique.corp.google.com/cl/657302386.
flutter/flutter#146658
Pre-launch Checklist
///
).