New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement CupertinoMenuAnchor and CupertinoMenuItem #143712
base: master
Are you sure you want to change the base?
Implement CupertinoMenuAnchor and CupertinoMenuItem #143712
Conversation
…ocalizedShortcutLabeler and DirectionalFocusIntent for use in CupertinoMenuAnchor
…hicks980/flutter into feat/cupertino_menu_anchor
Hello @davidhicks980, sorry for the delay on this one. It looks like this change is failing some checks. Could you take a look at those and fix the issues? Thanks. |
@goderbauer Sure thing! I'll take a look later this week. Edit 04/29: I have to make a few changes to accommodate text height differences across platforms (particularly browser), and only got around to some of the changes this weekend. I'll have more time later this week/weekend to finish up. |
Okay, assuming I correctly fixed the last four linux warnings, this should be good for a prelim look! There is a lot of weirdness in this PR, particularly with regard to color blending. I tried to explain most of it, but please let me know if anything doesn't make sense. Also, as I've already mentioned, the _PanRegion and related classes were added to match native behavior, but it may make sense to split this feature off into a separate file. I wanted to get feedback on it before doing so, as the implementation I've written is primitive (e.g. there is no way to isolate pans to a single region). I'd also be curious to hear whether we should incorporate menu text theming into the CupertinoTheme class... but I was afraid to add too much complexity with this commit. |
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.
So excited about this! I have not reviewed all of the PR, the import of material into cupertino will need to be resolved first.
Also, in the earlier PR, we talked about splitting this up over multiple PRs. A change of this size is difficult to review and verify test coverage for. There are some changes in the material library in addition to new cupertino widgets here. Is it possible we can split this up a bit?
import '../material/material_localizations.dart' | ||
show MaterialLocalizations; | ||
import '../material/menu_anchor.dart' |
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 is not a valid import, the Cupertino library cannot import the material library, since material already imports cupertino. It creates a circular dependency between the libraries.
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 circular dependency problem is something I was unsure of how to fix. I asked a (long winded) question in the Discord chat, but no one got back to me (see here). Would you suggest I try moving the MenuAnchor core to the Widgets library, or do you have a suggestion? I'm mostly concerned about compromising any plans you all have, but I wasn't sure who to ask.
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.
Would you suggest I try moving the MenuAnchor core to the Widgets library
This might be an option, let me ask some folks about it and circle back.
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.
Sounds good! I'll see what parts I can shed off of the CupertinoMenuAnchor to make it smaller.
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.
Moving MenuAnchor and MenuController --> widgets SGT-everyone I spoke with! Is this something you are interested in doing in a separate change? If not, I can send a PR. :)
The only material-specific bit we would need to leave in material would be MenuAnchor.menuStyle. So this would probably look like a RawMenuAnchor class in widgets, with MenuAnchor as a subclass in material so it can have the MenuStyle.
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.
That's exciting! I'd be happy to. I believe I tried in the past and there are a few tricky dependencies between the two (mostly related to _Submenu, which depends on _MenuAnchorState internals, material theming, and DismissMenuAction, and MenuDirectionalFocusAction) but I'll go ahead and get a PR in so that we can discuss. I'll be out-of-town this weekend, but will submit ASAP!
const bool _kDebugMenus = false; | ||
|
||
/// Whether [defaultTargetPlatform] is an Apple platform (Mac or iOS). | ||
bool get _isApple { |
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 would use _isCupertino here. Avoiding brand names.
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.
Fixed! This was in the material repo so I submitted a PR here: #148432.
This PR implements CupertinoMenuAnchor, CupertinoMenuItem, CupertinoLargeMenuDivider using MenuAnchor as a base.
Resolves #60298, notDmDrl/pull_down_button#26, #137936
Tests modeled after MenuAnchor have been added to cover the API surface... perhaps too many tests. I split CupertinoMenuItem tests from CupertinoMenuAnchor tests to improve performance.
Four examples have been added with tests
Before implementing tests for the modifications made to MenuAnchor (a MenuAnchor.withOverlayBuilder constructor was added), I wanted to get some feedback. I initially made MenuAnchorState public and made the overlayBuilder a protected method, but found that adding a separate constructor required fewer changes and felt simpler overall. The tradeoff is that users would need to know how to properly set up semantics, focus, and actions if they were to use this constructor.
Also, I'm curious whether it would be valuable for me to fullfill this PR: #135025. I attempted to build a generic Panel widget that would encompass functionality and animations without providing structure, but I decided to stick to a wrapper until I heard feedback.
Some features that were going to be included in a future PR made it into this PR because they were either necessary to fulfill a core functionality of the menu (_PanRegion, which is modeled after _TapRegion, and _CupertinoMenuDivider), or they were so simple that it'd be more work to leave them out (CupertinoLargeMenuDivider). In the case of the former, all classes are private, fully documented, and have been tested in the context of their use in the menu anchor. With regard to CupertinoLargeMenuDivider, it has tests, documentation, and a public API.
A few loose ends:
Last, CupertinoMenuItem, CupertinoMenuAnchor, MenuItemButtons, and MenuAnchor all interop and can be swapped out pretty easily.
Screen.Recording.2024-02-19.at.12.47.24.PM.mov
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
@Piinks @MitchellGoodwin Sorry in advance if you guys already saw this, but I forgot to tag you both