Skip to content

Commit

Permalink
Merge pull request #5 from SimformSolutionsPvtLtd/feature/UNT-T20561-…
Browse files Browse the repository at this point in the history
…update-example-and-readme

UNT-T20561: Add a tap to close feature and update ReadMe
  • Loading branch information
bhargavbajani-simformsolutions authored Dec 11, 2023
2 parents 1684e78 + 571ef45 commit a8e3250
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 45 deletions.
9 changes: 7 additions & 2 deletions Example/SSSwiftUISideMenuDemo/Container Views/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct Home: View {

// State variables for various configuration options
@State private var menuDirection = 0
@State private var tapToClose = true
@State private var swipeToClose = true
@State private var titleColor: Color = .black
@State private var iconTintColor: Color = .pink
Expand All @@ -47,7 +48,8 @@ struct Home: View {
backgroundColor: backgroundColor,
animationType: selectedAnimation,
menuDirection: menuDirection == 0 ? .left : .right,
swipeToClose: swipeToClose
swipeToClose: swipeToClose,
tapToClose: tapToClose
)
}

Expand Down Expand Up @@ -78,6 +80,9 @@ struct Home: View {
}
.pickerStyle(.menu)

// Toggle for tap to close menu
Toggle("Tap to close menu", isOn: $tapToClose)

// Toggle for swipe to close menu
Toggle("Swipe to close menu", isOn: $swipeToClose)
}
Expand Down Expand Up @@ -121,7 +126,7 @@ struct Home: View {
.padding(.horizontal, -20)
.listRowInsets(EdgeInsets())
}
.navigationBarTitle("SSSwiftUI SideMenu", displayMode: .inline)
.navigationBarTitle("SSSwiftUISideMenu", displayMode: .inline)
}
.padding(.horizontal, 24)
}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 mobile-simformsolutions
Copyright (c) 2023 mobile-simformsolutions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
86 changes: 44 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="https://www.simform.com/"><img src="https://github.com/SimformSolutionsPvtLtd/SSToastMessage/blob/master/simformBanner.png"></a>
![ScreenShot](/Resources/banner.png)

# SSSwiftUISideMenu

Expand All @@ -16,44 +16,49 @@ SwiftUI package for creating custom sidemenu with animation and flexible design
**About SSSwiftUISideMenu**<br/>
SSSwiftUISideMenu is highly customisable and easy to use Side menu control for iOS Applications. It support the SideMenu operations from left / right panel. user can navigate through the container views that added with the SideMenu MenuItems. It allows user to customise UI and animation style of their choice.

## Example
### Prerequisites
- iOS 13.0+
- Xcode 11.0+
- [CocoaPods](http://cocoapods.org/)

To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Example

## Requirements
![ScreenShot](/Resources/SSSwiftUISideMenu_example.gif)

This pod requires a deployment target of iOS 13.0 or greater
- To run the example project, clone the repo, and run `pod install` from the Example directory first.

## Installation
# Installation
#### CocoaPods

### Cocoapods
- You can use CocoaPods to install `SSSwiftUISideMenu` by adding it to your Podfile:

SSSwiftUISideMenu is available through [CocoaPods](https://cocoapods.org). <br/>To install
it, simply add the following line to your Podfile:
use_frameworks!
pod 'SSSwiftUISideMenu'

```ruby
pod 'SSSwiftUISideMenu'
```
and run `pod install` from the root directory of project and in your code add `import SSSwiftUISideMenu` and boom you're done.💥
- Import SSSwiftUISideMenu in your file:

### Swift Package Manager
import SSSwiftUISideMenu

When using Xcode 11 or later, you can install `SSLineChart` through [Swift Package Manager](https://swift.org/package-manager/) by going to your Project settings > `Swift Packages` and add the repository by providing the GitHub URL. Alternatively, you can go to `File` > `Swift Packages` > `Add Package Dependencies...`
**Manually**
- Download and drop **SSSwiftUISideMenu/Sources** folder in your project.
- Grab yourself a cold 🍺.

### Manually
#### Swift Package Manager (SPM)
- When using Xcode 11 or later, you can install `SSSwiftUISideMenu` by going to your Project settings > `Swift Packages` and add the repository by providing the GitHub URL. Alternatively, you can go to `File` > `Swift Packages` > `Add Package Dependencies...`

1. Add `SSSwiftUISideMenu.swift` and `SSMenuConfig.swift` to your project.
2. Grab yourself a cold 🍺.
dependencies: [
.package(url: "https://github.com/mobile-simformsolutions/SSSwiftUISideMenu.git", from: "1.0.0")
]

## Usage
# Usage Examples

Import the package in the file you would like to use it:
- Import the package in the file you would like to use it:

```swiftui
import SSSwiftUISideMenu
```

This library shares one View which you can use as a sidemenu with many customizations like UI, animation, direction and many more.
- This library shares one View which you can use as a sidemenu with many customizations like UI, animation, direction and many more.
Basic example:

```swift
Expand All @@ -74,13 +79,12 @@ var body: some Scene {
```
The results of any interaction from sidemenu item will available in declared selectedIndex state variable. Also sidemnu open / close toggle value will be available in the openSideMenu state variable.

Customizations
===
# Customizations

You can customize almost every main thing in this library.
For Customizations you have to pass another value of `menuConfig` during call of SSSwiftUISideMenu. This menuConfig argument is optional as well as Every arguments in `SSMenuConfig` is also Optional. So, you need to add only those arguments which yo wanted to customize. Here's the examples :
- You can customize almost every main thing in this library.
- For Customizations you have to pass another value of `menuConfig` during call of SSSwiftUISideMenu. This menuConfig argument is optional as well as Every arguments in `SSMenuConfig` is also Optional. So, you need to add only those arguments which yo wanted to customize. Here's the examples :

Change in Style
## Change in Style
-----
*An example of customisation of styles*

Expand All @@ -94,7 +98,7 @@ var body: some Scene {
}
```

Change SideMenu direction - Left / Right
## Change SideMenu direction - Left / Right
-----
*An example of change sidemenu direction. left direction is default*

Expand All @@ -106,7 +110,7 @@ var body: some Scene {
}
```

Add animation to your sidemenu
## Add animation to your sidemenu
-----
*An example of applying a animation type to the sidemenu*

Expand All @@ -118,10 +122,9 @@ var body: some Scene {
}
```

Other Customizations
===
# Other Customizations

SideMenu width
#### SideMenu width
----
*You can change the menu width of your choice with the menuWidth. By default is '280'.*<br/>

Expand All @@ -133,13 +136,13 @@ var body: some Scene {
}
```

Icon color and customizations
#### Icon color and customizations
-------

1. You can add leftIconPadding argument to change the icon padding from the left side of the sidemenu view.<br/>
2. You can add imageToTitlePadding argument for adding a padding between a icon and title.<br/>
3. You can add iconTintColor argument to change the icon tint color of your choice.<br/>
4. You can add iconHeight and iconWidth argument change the size of the row icons.<br/>
- You can add leftIconPadding argument to change the icon padding from the left side of the sidemenu view.<br/>
- You can add imageToTitlePadding argument for adding a padding between a icon and title.<br/>
- You can add iconTintColor argument to change the icon tint color of your choice.<br/>
- You can add iconHeight and iconWidth argument change the size of the row icons.<br/>

```swift

Expand All @@ -153,13 +156,13 @@ var body: some Scene {
}
```

Show App Version
#### Show App Version
-------
*An example of showing your app version at bottom of the sidemenu. you can configure its style and color. All are optionally configured.*

1. Add showAppVersion argument to weather to show app versio or not. Default is false<br/>
2. Add versionText argument for adding a pass the text of the version.<br/>
3. Add versionTitleColor, versionAlignment or versionFont argument to change the font style and color of the version string.<br/>
- Add showAppVersion argument to weather to show app versio or not. Default is false<br/>
- Add versionText argument for adding a pass the text of the version.<br/>
- Add versionTitleColor, versionAlignment or versionFont argument to change the font style and color of the version string.<br/>

```swift

Expand All @@ -174,7 +177,7 @@ var body: some Scene {

## Coming Soon

1. Pass custom view directly to the sidemenu to create sidemenu of your choice.<br/>
- Pass custom view directly to the sidemenu to create sidemenu of your choice.<br/>

**Up for a suggestions. Give suggestions for more features and customisations.**

Expand All @@ -200,4 +203,3 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
[PR-url]:http://makeapullrequest.com
[swift-image]:https://img.shields.io/badge/swift-5.0-orange.svg
[swift-url]: https://swift.org/

Binary file added Resources/SSSwiftUISideMenu_example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Sources/SSSwiftUISideMenu/SSMenuConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public struct SSMenuConfig {
private(set) var menuDirection: Directions
/** Boolean for whether you want the menu close on swipe gesture . Default is: Enabled**/
private(set) var swipeToClose: Bool
/** Boolean for whether you want the close the menu on tap gesture(out side) . Default is: Enabled**/
private(set) var tapToClose: Bool
/** Boolean for whether you want to show App version . Default is: False**/
private(set) var showAppVersion: Bool
/** Specify the App version string . Default is: Empty**/
Expand Down Expand Up @@ -71,6 +73,7 @@ public struct SSMenuConfig {
animationType: Animation = .default,
menuDirection: Directions = .left,
swipeToClose: Bool = true,
tapToClose: Bool = true,
showAppVersion: Bool = false,
versionText: String = "",
versionFont: Font = .caption,
Expand All @@ -92,6 +95,7 @@ public struct SSMenuConfig {
self.animationType = animationType
self.menuDirection = menuDirection
self.swipeToClose = swipeToClose
self.tapToClose = tapToClose
self.showAppVersion = showAppVersion
self.versionText = versionText
self.versionFont = versionFont
Expand Down
8 changes: 8 additions & 0 deletions Sources/SSSwiftUISideMenu/SSSwiftUISideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public struct SSSwiftUISideMenu: View {
Button(action: {
withAnimation(.spring()) {
self.selectedIndex = value
if menuConfig.tapToClose { return }
self.openSideMenu.toggle()
}
}, label: {
Expand Down Expand Up @@ -121,6 +122,13 @@ public struct SSSwiftUISideMenu: View {
}
}
})
.gesture(
TapGesture()
.onEnded { _ in
if !menuConfig.tapToClose { return }
self.openSideMenu.toggle()
}
)
}

}

0 comments on commit a8e3250

Please sign in to comment.