-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Mac context menu #73882
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
Mac context menu #73882
Conversation
@@ -1784,6 +1784,17 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { | |||
|
|||
Offset? _lastTapDownPosition; | |||
|
|||
/// The position of the most recent tap down event on this text input. | |||
Offset? get lastTapDownPosition => _lastTapDownPosition; |
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 to expose this in order to position the menu at the tap position (on mobile, it's positioned centered on the selection). Any objections to this or better ideas?
Ideally I'll be able to clean up RenderEditable stuff like this in my refactor later...
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.
Probably OK in the short term. We should really be using the existing menu system to show desktop menus.
a3b723d
to
343c2ec
Compare
const double _kToolbarWidth = 222.0; | ||
const Color _kToolbarBorderColor = Color(0xFF505152); | ||
const Radius _kToolbarBorderRadius = Radius.circular(4.0); | ||
const Color _kToolbarBackgroundColor = Color(0xFF2D2E31); |
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 do I get this from the theme so that it depends on light/dark mode?
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.
CupertinoDynamicColor values in CupertinoColors resolve to different color values, depending on the theme's CupertinoTheme's brightness. CupertinoDynamicColor.resolve(CupertinoColors.systemBlue, context).
child: CupertinoButton( | ||
alignment: Alignment.centerLeft, | ||
borderRadius: null, | ||
color: _isHovered ? CupertinoTheme.of(context).primaryColor : null, | ||
minSize: 0.0, | ||
onPressed: widget.onPressed, | ||
padding: _kToolbarButtonPadding, | ||
pressedOpacity: 0.7, | ||
child: widget.child, | ||
), |
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.
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.
It's not, although we could improve the situation a little by tweaking the padding for now. Part of the root problem is #72521 (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.
I've improved it by a pixel or two with padding and it looks noticeably better.
|
||
// These values were measured from a screenshot of TextEdit on MacOS 10.15.7 on | ||
// a Macbook Pro. | ||
const double _kToolbarWidth = 222.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.
Hello Justin !
It seems that the width is not fixed and depends on the widest menu item according to Apple documentation.
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.
Good point, thanks! I'll make that a minimum width.
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 as easy as I thought. I think it might need a custom layout widget. The parent needs to size itself to the biggest intrinsic width of its children, and the children then need to all match that.
I've added this to the "Known limitations" above since this PR is somewhat rushed. Given more time this is definitely doable, though.
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.
Similar to #72023.
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.
Okok perfect!
/// * [TextSelectionToolbar.toolbarBuilder], which is of this type. | ||
/// * [CupertinoTextSelectionToolbar.toolbarBuilder], which is similar, but | ||
/// for a Cupertino-style toolbar. | ||
typedef ToolbarBuilder = Widget Function(BuildContext context, Widget child); |
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.
Moved to widgets so it can be shared.
The Google testing failure is just because #73900, which this PR depends on, has not yet been rolled into google3. |
43eebd8
to
1dbb384
Compare
This pull request is not suitable for automatic merging in its current state.
|
I'm going to merge this even though Google tests are failing because:
CC @HansMuller |
@@ -131,6 +142,7 @@ abstract class TextSelectionControls { | |||
List<TextSelectionPoint> endpoints, | |||
TextSelectionDelegate delegate, | |||
ClipboardStatusNotifier clipboardStatus, | |||
Offset? lastSecondaryTapDownPosition, |
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.
@justinmc This is a breaking change.
What is the suggested migration?
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 breaks flutter_math
e.g. - I will link the PR)
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.
Ah sorry about that. The migration should be to pass renderObject.lastSecondaryTapDownPosition
. See https://github.com/flutter/flutter/pull/73882/files#diff-6f186b82dcb3d864ea23246744ea7a67bcb64d369e0da5495cd0bd0e038f9bd9R600
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.
Alright, thanks ❤️
A minimal Mac context menu.
Native is left, Flutter is right.

Tests
Breaking change
No.
Known limitations
I'm tracking all of these in #74255.
However, it is possible to customize the buttons with a little work (similar to how it is on Android/iOS now).Disallowing customization until the menu is done in a more robust way.