SwiftUIMenu 1.1.3

SwiftUIMenu 1.1.3

Maintained by fmnoyader.



  • By
  • fermoya

SwiftUIMenu

Swift Package Manager compatible Cocoapods Carthage compatible CocoaPods platforms License: MIT

SwiftUIMenu is a component that allows you to implement Menu Navigation Pattern in your App. Menu presents a content and a list of of options that's easily displayed by swiping or reacting to an external event such as a navbar button tap.

Requirements

  • iOS 13.0+
  • macOS 10.15+
  • watchOS 6.0+
  • Swift 5.1+

Installation

CocoaPods

pod 'SwiftUIMenu'

Swift Package Manager

Go to XCode:

Carthage

github "fermoya/SwiftUIMenu"

Usage

Initialization

You can create a Menu by passing:

  • Binding to the selected index
  • Binding to determine if Menu is open
  • Array of items to populate the menu
  • ViewBuilder to build each row
  • ViewBuilder to build the content for the selected index
Menu(indexSelected: self.$index,
     isOpen: self.$isMenuOpen,
     menuItems: menuItems,
     menuItemRow: { index in
         Text("Option \(index)")
     },
     menuItemContent: { section in
         Text("Welcome to section \(section)")
     })
})

Example of usage

UI customization

There're plenty of view-modifiers available to customize your Menu and give it a personal touch. You can specify its position, style or add a header, among others.

By default, Menu is configured to:

  • Reveal from the left
  • Have an overlap style
  • Take up the whole screen
  • Allow dragging

Alignment

Changes the position of the menu so that it reveals from the left or right of the screen.

Menu(...)
    .alignment(.right)
Left Menu

Left menu

Right Menu

Right menu

Header & Footer

Use these modifiers to add a header and/or footer to Menu.

Menu(...)
    .header { MyMenuHeader() } 
    .footer { MyMenuFooter() } 

<img src="resources/header-footer.gif" alt=Menu with header and footer" height="640"/>

Style

Adds a different effect to the way Menu is revealed.

Menu(...)
    .style(.stretch)
Overlap

Overlap-style menu

Push

Push-style menu

Stretch

Stretch-style menu

More features

You can also:

  • Change the ratio of available space that Menu will take up when open with revealRatio
  • Disable the DragGesture with disableDragging
  • Make the content dismiss Menu by a simple tap with allowContentTap()
  • Shade the content when Menu is open with shadeContent
Menu(...)
    .revealRatio(0.8)
    .shadeContent()

Sample projects

For more information, please check the sample app.

Your feedback is more than welcome, don't hesitate to open an issue or ping me at [email protected].

Feel free to collaborate and make this framework better.

License

SwiftUIMenu is available under the MIT license. See the LICENSE file for more info.