Skip to content

Wrap PopupMenuButton in SafeArea to prevent overlap on status bar#55489

Closed
arthurdenner wants to merge 1 commit into
flutter:masterfrom
arthurdenner:fix/wrap-popupmenubutton-safearea
Closed

Wrap PopupMenuButton in SafeArea to prevent overlap on status bar#55489
arthurdenner wants to merge 1 commit into
flutter:masterfrom
arthurdenner:fix/wrap-popupmenubutton-safearea

Conversation

@arthurdenner

@arthurdenner arthurdenner commented Apr 23, 2020

Copy link
Copy Markdown
Contributor

Description

Currently, if one use a PopupMenuButton, the widget won't respect the status bar of the device. This is due to the usage of MediaQuery.removePadding in one of the inner widgets. Replacing this with a SafeArea solves the issue. See screenshots below.

Android

  • Current behavior with few items:

current_behavior_few_items

  • Current behavior with many items:

current_behavior_many_items

  • Proposed behavior with few items:

proposed_behavior_few_items

  • Proposed behavior with many items:

proposed_behavior_many_items


iOS

  • Current behavior with few items:

current_behavior_few_items

  • Current behavior with many items:

current_behavior_many_items

  • Proposed behavior with few items:

proposed_behavior_few_items

  • Proposed behavior with many items:

proposed_behavior_many_items

Related Issues

Closes #19954.

Tests

All current tests are passing - some of them assert positioning.

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 Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • 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.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 23, 2020
@fluttergithubbot

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

@HansMuller HansMuller requested a review from Piinks April 24, 2020 22:34

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @arthurdenner thanks for the contribution!

Can you first provide the code you are using to create the screenshots you provided? I am curious that your proposed behavior seems variable across platforms, and it is not clear why. For example, the alignment of the proposed 'few items' example looks very different from iOS to Android. I would think they would produce the same alignment based on the images.

@arthurdenner

arthurdenner commented Apr 27, 2020

Copy link
Copy Markdown
Contributor Author

@Piinks, both examples are based on examples/catalog/basic_app_bar.dart and you can find them here.

The difference you pointed wasn't introduced by this PR because the position is calculated here, way before those widgets, but you couldn't notice so much before since the PopupMenuButton was not avoiding the status bar.

@Piinks

Piinks commented Apr 28, 2020

Copy link
Copy Markdown
Contributor

@Piinks, both examples are based on examples/catalog/basic_app_bar.dart and you can find them here.

The difference you pointed wasn't introduced by this PR because the position is calculated here, way before those widgets, but you couldn't notice so much before since the PopupMenuButton was not avoiding the status bar.

Thanks for clarifying and providing the code! @shihaohong went ahead (and saved us a bunch of time! 🎉 ) checking this against the tests it would undergo during the roll to the dev channel (See Rolling to the dev channel), and it looks like this will be a breaking change. Breaking Changes require a few more steps in order to land, which are laid out in that wiki link. This change will probably need to be phased, with an initial opt-in flag to prevent breaking developers.

It will also need tests. It looks like the current framework tests don't check the alignment, so this is awesome that our coverage will be better here! Check out the wiki links I provided and let me know if you need any guidance on proceeding with this change. :)

@Piinks

Piinks commented May 6, 2020

Copy link
Copy Markdown
Contributor

@arthurdenner would you like to move forward with this change?

@arthurdenner

arthurdenner commented May 6, 2020

Copy link
Copy Markdown
Contributor Author

Sorry, but unfortunately I can't - forgot to reply here, thanks for the ping. Breaking changes usually take some time and I'm not so familiar with the inner bits of the framework. Last time I tried to implement a breaking change here, it took many days and the PR ended up being closed. 😕

I'd rather leave the changes to someone more experienced with the inner bits and with more time to deal with the interaction. I'd just kindly ask you to update the labels on the linked issue because it's currently tagged as easy fix and that may mislead someone else.

@JuYeong0413

Copy link
Copy Markdown
Contributor

Hi @Piinks, I would like to proceed with this change based on this pull request.
I wrote a design doc, and now writing a test for this change.

I'm thinking of comparing the status bar height and the first popupMenuItem's y axis. (If the top left y axis of first popupMenuItem is greater than the status bar height, we can say that they are not overlapping.)
However, I'm struggling with getting the status bar height - we can easily get it when running the emulator, but seems like there is no status bar on the testing environment. 😓
Can I get some help with writing test about this change?

@Piinks

Piinks commented Aug 20, 2020

Copy link
Copy Markdown
Contributor

Hi @Piinks, I would like to proceed with this change based on this pull request.
I wrote a design doc, and now writing a test for this change.

I'm thinking of comparing the status bar height and the first popupMenuItem's y axis. (If the top left y axis of first popupMenuItem is greater than the status bar height, we can say that they are not overlapping.)
However, I'm struggling with getting the status bar height - we can easily get it when running the emulator, but seems like there is no status bar on the testing environment. 😓
Can I get some help with writing test about this change?

Hey @JuYeong0413 thanks for working on a solution for this!
The status bar would be represented in MediaQuery.data as a MediaQueryData.viewInsets IIRC, but it may be MediaQueryData.viewPadding. I would check to see what MediaQueryData is informing the layout of your widgets. In order to test for this, you can create your own MediaQuery in your test and mimic the MediaQueryData you see when executing on your emulator.

I recently wrote a test like this to check safe area, here I included MediaQueryData.viewPadding in my test to simulate a notch on the bottom: https://github.com/flutter/flutter/pull/64268/files

Let me know if this helps in your test writing! Thanks! :)

@JuYeong0413

JuYeong0413 commented Aug 25, 2020

Copy link
Copy Markdown
Contributor

Thank you for your kind guidance @Piinks!
I have created MediaQuery.data for mimicking status bar and bottom notch, but I'm getting the same results before&after wrapping PopupMenu with SafeArea. 😞
Executing the same widgets on the emulator works as expected, so I think there's some problem with MediaQueryData or getTopLeft/getBottomLeft of PopupMenu in my test code. (BTW, using MediaQueryData.viewInsets and MediaQueryData.viewPadding both give me the same result when representing the status bar... I think MediaQueryData.viewInsets may be correct.)

Here are the tests I wrote:

  1. few items in AppBar(overlapping with status bar)
  2. many items covering the screen vertically(overlapping with status bar&bottom notch)

I've tried for several days, but cannot figure out why these tests are giving the same result although the PopupMenu is wrapped with SafeArea. 🤔
Could you please help me with this?

@Piinks

Piinks commented Aug 26, 2020

Copy link
Copy Markdown
Contributor

@JuYeong0413 do you have an open PR with these changes? It may be easier to discuss there. Feel free to ping me on a PR for review. :)

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tall popup menus go under the system status bar

6 participants