Skip to content
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

Use SystemContextMenu by default on iOS #165354

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

justinmc
Copy link
Contributor

With this change, widgets based on EditableText will show the system context menu by default on iOS. Anyone with a custom contextMenuBuilder will not be affected and will have to opt-in to using SystemContextMenu. Also, this does not affect SelectionArea, which can't receive paste.

Fixes #163067

@justinmc justinmc requested a review from hellohuanlin March 17, 2025 23:34
@justinmc justinmc self-assigned this Mar 17, 2025
@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Mar 17, 2025
),
)
as WidgetsBindingObserver;
widgetsBindingObserver.didChangeMetrics();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does anyone know of a better way to do this? MediaQuery.fromView gets its values set from the view once per run of flutter test. When I change isSupported on the view, MediaQuery does not reflect the updated value unless I call something like didChangeMetrics on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Renzo-Olivares had an idea to insert another MediaQuery into the tree and set its value of supportsShowingSystemContextMenu. I tried it and it didn't seem to work. SystemContextMenu is built in contextMenuBuilder, and the BuildContext it gets is from its OverlayEntry, which is near the root of the tree. So unfortunately when it looks up the nearest MediaQuery, it misses the one that I put in the tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another thing to try from @Renzo-Olivares was changing the AppLifecycleState to get the view to rebuild. This succeeded in getting _MediaQueryFromView.didUpdateWidget to be called, but the logic in that method does not update the view data unless the entire view changes.

I suspect that might be a bug, so I opened an issue: #165519.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would consider making this method private if we intend to change it, but I also think its fine as is since its in the framework tests.

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 made it private, I think that's probably a good call despite the duplication. Hopefully we can fix the bug and then remove it.

@justinmc justinmc requested a review from Renzo-Olivares March 17, 2025 23:40
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM modulo analyzer errors.

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

Thank you for writing so many tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository 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.

[ios]Use native edit menu by default, if there's no custom actions
3 participants