Skip to content

Context menu API #30976

Closed
Closed

Description

@dkwingsmt

Objective

Design a set of API for context menu that meets the following requirements:

  • Easy and intuitive for developers to apply to their custom widgets
  • Provide default context menu for certain widgets:
    • EditableText
    • SelectableText (upcoming)
    • (Please add more)
  • Widgets with default context menu should allow override
  • Menu should be rendered in proper style, which should be apparent to widgets
    • In a material app it should be rendered in Material PopupMenu
    • In a desktop app or on Web, it should be rendered in native menu (long-term goal)

Activity

  1. self-assigned this
    on Apr 12, 2019
  2. dkwingsmt commented on May 31, 2019

    @dkwingsmt
    ContributorAuthor

    Progress as of 5/31/2019, #33685

    What's in this PR

    1

    As shown in the GIF above, this PR contains the following features:

    • Show a context menu when right clicking an editable text
    • Correctly control focus and selection
    • Change menu item according to context, and implement them
    • Stall the style of text field when context menu is shown

    Feature-wise this should be close to complete as a first phase, except for perhaps the following features:

    • Shortcut
    • Submenus

    Please correct me if we have plan for more.

    Current API

    There are two dimensions of extensibility, which are independent from each other:

    • Control the rendering: The menu should be able to render in multiple ways, such as Material popup menu, other design languages, as well as native system menu, and this layer should be transparent to the widget.
    • Control the content: We should give widgets like editable text a default menu, while also allowing developers to extend it.

    Content control

    • ContextMenuContent is a configuration of what to show in a context menu
    • ContextMenuEntry is an entry in a context menu. It is platform-neutral, unlike PopupMenuEntry. It has subclasses such as menu item, divider, and submenus.
    • TextContextMenuFactory is how editable text will define its context menu.

    Render control

    • RenderContextMenu is an abstract class that platforms can implement how to render the menu and each kind of menu entry.

    Remaining question

    How to design the API for rendering control?

    Currently EditableText has two new parameters in this PR:

    • TextContextMenuFactory contextMenuFactory controls content
    • RenderContextMenu renderContextMenu controls render

    It makes sense to keep contextMenuFactory as a parameter of EditableText, but renderContextMenu should really be a global configuration. I wonder what the idiomatic way is for this (should I design another class that has static method .of?)

    Will RenderContextMenu work for native menu?

    I would really like to make it work on at least one platform before confirming, such as macOS and Web.

    How to design API for menu entry?

    It will very likely depend on the upcoming Action API.

  3. changed the title [-]Add context menu to editable text[/-] [+]Context menu API[/+] on May 31, 2019
  4. krisgiesing commented on Jun 3, 2019

    @krisgiesing
    Contributor

    Just so I understand the direction here: is the intention that (at least initially) the context menu would be drawn by Flutter rather than by the platform? This has the observable effect of needing to draw within Flutter's window, rather than at an edge where some of the rendering occurs outside the window.

  5. dkwingsmt commented on Jun 3, 2019

    @dkwingsmt
    ContributorAuthor

    @krisgiesing Menu drawn by Flutter will be used on Android, or as a fallback (e.g. on GLFW).
    The long-term plan is to eventually use native menu when possible, such as on Desktops and on Web.
    But yes, it will be the initial implementation.
    Also +cc @stuartmorgan @gspencergoog

  6. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jul 26, 2019
  7. dkwingsmt commented on Aug 5, 2019

    @dkwingsmt
    ContributorAuthor

    Update as of 8/5/2019:

    Development on this has been paused.

    Multiple problems were found. One of them is #34025, which severely affects user experience, but I'm not aware of solution or workaround unless we re-implement modals into multiple activities (?).

    I'm still planning to come back and implement a non-extensible context menu that supports basic operations at some point.

  8. added this to the milestone on Aug 13, 2019
  9. gspencergoog commented on Nov 13, 2019

    @gspencergoog
    Contributor

    Closing this as a duplicate of #31955

  10. github-actions commented on Aug 14, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: desktopRunning on desktopc: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions