Skip to content

Commit

Permalink
Project configuration
Browse files Browse the repository at this point in the history
Adding support for Cocoapods and Carthage
Updating documentation
Adding resources
SwiftUIMenuExample

Fixing image source in README
  • Loading branch information
Fernando Moya de Rivas committed Feb 25, 2020
1 parent e8f6e21 commit 2fc0645
Show file tree
Hide file tree
Showing 30 changed files with 1,229 additions and 38 deletions.
4 changes: 4 additions & 0 deletions Example/SwiftUIMenuExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
6B6C737D24002C3A009C1FC6 /* ProfileHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B6C737C24002C3A009C1FC6 /* ProfileHeader.swift */; };
6BD68FCA23F57CED00A518D3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BD68FC923F57CED00A518D3 /* AppDelegate.swift */; };
6BD68FCC23F57CED00A518D3 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BD68FCB23F57CED00A518D3 /* SceneDelegate.swift */; };
6BD68FCE23F57CED00A518D3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BD68FCD23F57CED00A518D3 /* ContentView.swift */; };
Expand All @@ -23,6 +24,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
6B6C737C24002C3A009C1FC6 /* ProfileHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeader.swift; sourceTree = "<group>"; };
6BD68FC623F57CED00A518D3 /* SwiftUIMenuExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUIMenuExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
6BD68FC923F57CED00A518D3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6BD68FCB23F57CED00A518D3 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -74,6 +76,7 @@
6BD68FDD23F57D5400A518D3 /* Support */,
6BD68FCD23F57CED00A518D3 /* ContentView.swift */,
6BD68FEE23F57FEE00A518D3 /* MenuItem.swift */,
6B6C737C24002C3A009C1FC6 /* ProfileHeader.swift */,
6BD68FD123F57CF100A518D3 /* Preview Content */,
);
path = SwiftUIMenuExample;
Expand Down Expand Up @@ -202,6 +205,7 @@
6BD68FEA23F57D7600A518D3 /* Buildable.swift in Sources */,
6BD68FCE23F57CED00A518D3 /* ContentView.swift in Sources */,
6BD68FF023F57FEE00A518D3 /* MenuItem.swift in Sources */,
6B6C737D24002C3A009C1FC6 /* ProfileHeader.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
29 changes: 21 additions & 8 deletions Example/SwiftUIMenuExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,36 @@ struct ContentView: View {

@State var index = 0
@State var isMenuOpen = false
var isMenuOnLeft = true

var body: some View {
NavigationView {
Menu(indexSelected: self.$index,
isOpen: self.$isMenuOpen,
menuItems: menuItems,
id: \.name,
menuItemRow: { Text($0.name) },
menuItemRow: {
Text($0.name)
.foregroundColor($0.color)
},
menuItemContent: { section in
ZStack {
Rectangle().fill(Color.white)
Text("This is section \(section)")
}.navigationBarItems(leading: self.menuButton)
.navigationBarTitle(Text("Section \(section + 1)"), displayMode: .inline)
Rectangle().fill(menuItems[self.index].color)
Text("Welcome to ").font(.system(size: 20))
+ Text(menuItems[self.index].name).font(.system(size: 30)).bold().italic()
}.navigationBarItems(leading: self.isMenuOnLeft ? AnyView(self.menuButton) : AnyView(EmptyView()),
trailing: self.isMenuOnLeft ? AnyView(EmptyView()) : AnyView(self.menuButton))
.navigationBarTitle(Text("SwiftUIMenu"), displayMode: .inline)
})
.style(.stretch)
.overlappingRatio(0.8)
.allowDragging()
.style(.overlap)
.revealRatio(0.8)
.header(header: {
ProfileHeader()
})
.alignment(isMenuOnLeft ? .left : .right)
.footer(footer: {
Text("Copyright © 2020 Fernando Moya de Rivas. All rights reserved.")
})
.shadeContent()
}
}
Expand All @@ -44,6 +56,7 @@ extension ContentView {
}
}) {
Image(systemName: self.isMenuOpen ? "xmark" : "list.bullet")
.padding()
}
}

Expand Down
20 changes: 8 additions & 12 deletions Example/SwiftUIMenuExample/MenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
//

import Foundation
import SwiftUI

struct MenuItem: Equatable {

enum Kind {
case text
case image
}

var name: String
var kind: Kind
var color: Color
}

let menuItems: [MenuItem] = [
MenuItem(name: "Setion 1", kind: .text),
MenuItem(name: "Setion 2", kind: .text),
MenuItem(name: "Setion 3", kind: .image),
MenuItem(name: "Setion 4", kind: .text),
MenuItem(name: "Setion 5", kind: .image),
MenuItem(name: "Setion 6", kind: .text)
MenuItem(name: "Section 1", color: .blue),
MenuItem(name: "Section 2", color: .red),
MenuItem(name: "Section 3", color: .green),
MenuItem(name: "Section 4", color: .orange),
MenuItem(name: "Section 5", color: .yellow),
MenuItem(name: "Section 6", color: .purple)
]
32 changes: 32 additions & 0 deletions Example/SwiftUIMenuExample/ProfileHeader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ProfileHeader.swift
// SwiftUIMenuExample
//
// Created by Fernando Moya de Rivas on 21/02/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI

struct ProfileHeader: View {
var body: some View {
HStack {
Image("profile")
.resizable()
.frame(size: CGSize(width: 60, height: 60))
Spacer()
VStack(alignment: .trailing) {
Text("Name and surname")
Text("email@example.com")
.font(.system(size: 12))
.italic()
}
}
}
}

struct ProfileHeader_Previews: PreviewProvider {
static var previews: some View {
ProfileHeader()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "profile.jpg"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 142 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,144 @@
# SwiftUIMenu

A description of this package.
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
[![Cocoapods](https://img.shields.io/cocoapods/v/SwiftUIMenu.svg)](https://cocoapods.org/pods/SwiftUIMenu)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods platforms](https://img.shields.io/cocoapods/p/SwiftUIMenu.svg)](https://cocoapods.org/pods/SwiftUIMenu)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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:
* File -> Swift Packages -> Add Package Dependency...
* Use the URL https://github.com/fermoya/SwiftUIMenu.git

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

```swift
Menu(indexSelected: self.$index,
isOpen: self.$isMenuOpen,
menuItems: menuItems,
menuItemRow: { index in
Text("Option \(index)")
},
menuItemContent: { section in
Text("Welcome to section \(section)")
})
})
```

<img src="resources/usage.gif" alt="Example of usage" height="640"/>

### 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.

```swift
Menu(...)
.alignment(.right)
```

##### Left Menu

<img src="resources/left-menu.gif" alt="Left menu" height="640"/>

##### Right Menu

<img src="resources/right-menu.gif" alt="Right menu" height="640"/>

#### Header & Footer

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

```swift
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.

```swift
Menu(...)
.style(.stretch)
```

##### Overlap

<img src="resources/overlap.gif" alt="Overlap-style menu" height="640"/>

##### Push

<img src="resources/push.gif" alt="Push-style menu" height="640"/>

##### Stretch

<img src="resources/stretch.gif" alt="Stretch-style menu" height="640"/>

#### 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`
- Shade the content when `Menu` is open with `shadeContent`

```swift
Menu(...)
.revealRatio(0.8)
.shadeContent()
```

### Sample projects

For more information, please check the [sample app](/Example).

Your feedback is more than welcome, don't hesitate to open an issue or ping me at [fmdr.ct@gmail.com](mailto:fmdr.ct@gmail.com).

Feel free to collaborate and make this framework better.

## License

`SwiftUIMenu` is available under the MIT license. See the [LICENSE](/LICENSE) file for more info.
2 changes: 1 addition & 1 deletion Sources/SwiftUIMenu/Helpers/SizeViewModifier.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SizeViewModifier.swift
// SwiftUIPager
// SwiftUIMenu
//
// Created by Fernando Moya de Rivas on 19/01/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftUIMenu/Helpers/View+Helper.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// View+Helper.swift
// SwiftUIPager
// SwiftUIMenu
//
// Created by Fernando Moya de Rivas on 19/01/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftUIMenu/Menu+Buildable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ extension Menu: Buildable {
}

/// Sets the drawer size proportion relative to the size of the menu
public func overlappingRatio(_ value: CGFloat) -> Self {
mutating(keyPath: \.overlappingRatio, value: value)
public func revealRatio(_ value: CGFloat) -> Self {
mutating(keyPath: \.revealRatio, value: value)
}

/// Adds a `DragGesture` to swipe the menu open / close
public func allowDragging(_ value: Bool = true) -> Self {
mutating(keyPath: \.allowDragging, value: value)
mutating(keyPath: \.allowsDragging, value: value)
}

/// Removes the `DragGesture` used to swipe the menu open / close
public func disableDragging() -> Self {
mutating(keyPath: \.allowDragging, value: false)
mutating(keyPath: \.allowsDragging, value: false)
}

/// Adds a header to the menu drawer
Expand Down
Loading

0 comments on commit 2fc0645

Please sign in to comment.