Contents

mrasterisco/viewboundcontextmenu

ViewBoundContextMenu is a SwiftUI component that implements context menus that apply only to the view that defines them. While this should also be the case for SwiftUI's `contextMenu` view modifier, it doesn't work in views inside `List`: in this situation, the context menu is ap

Installation

ViewBoundContextMenu is available through Swift Package Manager.

.package(url: "https://github.com/MrAsterisco/ViewBoundContextMenu", from: "<see GitHub releases>")

Latest Release

To find out the latest version, look at the Releases tab of this repository.

Usage

ViewBoundContextMenu is exposed as a ViewModifier that you can apply to any view:

Text("Left Label")
  .bold()
  .viewBoundContextMenu {
    [
      .init(
        identifier: "Unique Identifier",
        title: "Action Title",
        image: nil, // Optional,
        children: [] // Optional,
        action: { // Do something } // Passing `nil` will disable the menu item
      )
    ]
  }

The content of the menu is defined by an array of ContextAction:

struct ContextAction {
  let identifier: String
  let title: String
  let image: UImage?|NSImage? // Optional: images will not be displayed when running on Mac Catalyst.
  let action: () -> ()
  let children: [ContextAction] // Actions in this array will be displayed as submenu items.
}

Example App

To see ViewBoundContextMenu in action, you can open the ViewBoundContextMenu workspace and run the "ViewBoundContextMenuExample" app.

Compatibility

ViewBoundContextMenu is compatible with iOS, macOS, and Mac Catalyst.

ViewBoundContextMenu targets iOS 13.0 or later and macOS 10.15 or later. The following dependencies are required:

  • SwiftUIX version 0.1.2.

Contributions

All contributions to expand the library are welcome. Fork the repo, make the changes you want, and open a Pull Request.

If you make changes to the codebase, I am not enforcing a coding style, but I may ask you to make changes based on how the rest of the library is made.

Status

This library is under active development. It is used in one app in Production (running on iOS and Mac Catalyst).

Even if most of the APIs are pretty straightforward, they may change in the future; but you don't have to worry about that, because releases will follow Semanting Versioning 2.0.0.

License

RxFireAuth is distributed under the MIT license. See LICENSE for details.

Package Metadata

Repository: mrasterisco/viewboundcontextmenu

Default branch: main

README: README.md