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

[ios][secure_paste]Show context items based on framework's data #56362

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Nov 4, 2024

This PR shows the context menu based on what's received from the framework via method channel. There are 2 cases:

1. For basic editing actions (e.g. copy/paste):

We perform a DFS search inside suggestedActions, so that we don't have to specify things like keyboard shortcut.

2. For additional actions (e.g. look up, share, search web):

We manually create UICommand because (1) some actions are not provided by suggestedActions (2) these are simply UICommand (rather than UIKeyCommand), so we just need title and action (3) the actions are private APIs. However this would require framework to send the item title.

List which issues are fixed by this PR. You must list at least one issue.

Second milestone for flutter/flutter#103163

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@hellohuanlin
Copy link
Contributor Author

hellohuanlin commented Nov 4, 2024

@justinmc This PR is not complete, but it should be good enough to start the framework side on top of it.

Example usage:

SystemChannels.platform.invokeMethod<void>(
      'ContextMenu.showSystemContextMenu',
      <String, dynamic>{
        'targetRect': <String, dynamic>{
          'x': 100,
          'y': 100,
          'width': 100,
          'height': 100,
        },
        'items': <dynamic>[
          <String, dynamic>{
            'type': 'default',
            'action': 'paste',
          },
          <String, dynamic>{
            'type': 'default',
            'action': 'cut',
          },
          <String, dynamic>{
            'type': 'default',
            'action': 'copy',
          },
          <String, dynamic>{
            'type': 'default',
            'action': 'selectAll',
          },
          <String, dynamic>{
            'type': 'default',
            'title': 'Look Up',
            'action': 'lookUp',
          },
          <String, dynamic>{
            'type': 'default',
            'title': "Search Web",
            'action': 'searchWeb',
          },
          <String, dynamic>{
            'type': 'default',
            'title': "Share",
            'action': 'share',
          },
        ],
      }
    );

I haven't implemented the additional actions (e.g. look up), so currently simply print out a log.

Also notice that I added title field for the additional actions. You can decide either add title to all actions for consistency, or just the additional actions.

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

Successfully merging this pull request may close these issues.

1 participant