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

Use getBoundingRects to add support inset MediaQuery/SafeArea when in freeform mode controls are shown. #54294

Merged
merged 15 commits into from
Aug 20, 2024

Conversation

yaakovschectman
Copy link
Contributor

@yaakovschectman yaakovschectman commented Aug 1, 2024

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 over getInsets.

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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@yaakovschectman yaakovschectman self-assigned this Aug 1, 2024
@yaakovschectman yaakovschectman marked this pull request as ready for review August 2, 2024 16:30
Copy link
Member

@gmackall gmackall left a 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

@chinmaygarde
Copy link
Member

Is this blocked on anything? Looks good to go.

@reidbaker
Copy link
Contributor

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.

@flutter-dashboard
Copy link

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.

@reidbaker reidbaker changed the title Add FlutterViewDelegate and BoundingRect methods Use getBoundingRects to add support inset MediaQuery/SafeArea when in freeform mode controls are shown. Aug 16, 2024

if (Build.VERSION.SDK_INT >= API_LEVELS.API_35) {
List<Rect> boundingRects = delegate.getCaptionBarInsets(getContext());
if (boundingRects != null && boundingRects.size() == 1) {
Copy link
Contributor

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?

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 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?

Copy link
Contributor

@reidbaker reidbaker Aug 16, 2024

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. */
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

public void setDelegate(@NonNull FlutterViewDelegate delegate) {
this.delegate = delegate;
}

private void sendViewportMetricsToFlutter() {
Copy link
Contributor

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?

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 just tested this, and it looks good. I've moved it to onApplyWindowInsets after the existing calculations.

Copy link
Contributor

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?

Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Great documentation

@yaakovschectman yaakovschectman merged commit d6bc4dc into flutter:main Aug 20, 2024
28 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 20, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 20, 2024
…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
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…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
@mengyanshou
Copy link

@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

@reidbaker
Copy link
Contributor

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants