Coder Social home page Coder Social logo

nscruiser / viewboundcontextmenu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrasterisco/viewboundcontextmenu

0.0 0.0 0.0 19 KB

A SwiftUI wrapper view that supports context menus in SwiftUI List rows.

License: MIT License

Swift 100.00%

viewboundcontextmenu's Introduction

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 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!

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.

viewboundcontextmenu's People

Contributors

mrasterisco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.