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 applied to the entire row.
This problem has been reported multiple times. Here are some examples:
The current workaround is to remove List
and replace it with a VStack
(or a LazyVStack
) and a ScrollView
. This solution isn't ideal, because List
provides a different experience and supports additional interactions (such as swipe actions).
ViewBoundContextMenu solves this problem!
ViewBoundContextMenu is available through Swift Package Manager.
.package(url: "https://github.com/MrAsterisco/ViewBoundContextMenu", from: "<see GitHub releases>")
To find out the latest version, look at the Releases tab of this repository.
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.
}
To see ViewBoundContextMenu in action, you can open the ViewBoundContextMenu
workspace and run the "ViewBoundContextMenuExample" app.
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.
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.
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.
RxFireAuth is distributed under the MIT license. See LICENSE for details.