A simple customizable side menu written in SwiftUI.
Feel free to request an issue on github if you find bugs or request a new feature. If you find this useful, please give it a star to show your support for this project.
You can check the example app repo too.
Copy this url:
https://github.com/itisnajim/NSideMenu.git
then in Xcode project, select File > Add Packages... and past it in the input with the placeholder 'Search or Enter package URL'
pod 'NSideMenu'
Then import framework where you need to use the library:
import NSideMenu
In your content view body add NSideMenuView like the code below:
@StateObject var options = NSideMenuOptions()
var body: some View {
NSideMenuView(options: options){
Menu{
YourMenuView()
}
Main{
YourMainView()
}
}
}
You can Customize NSideMenuView via NSideMenuOptions viewModel.
options = NSideMenuOptions(
style: .normal, side: .leading, width: 220,
showSkeletonStack: false, skeletonStackColor: .white,
cornerRaduisIfNeeded: 16, rotationDegreeIfNeeded: 8,
onWillClose: {
print("menu:onWillClose!")
}, onWillOpen: {
print("menu:onWillOpen!")
}, onDidClose: {
print("menu:onDidClose!")
}, onDidOpen: {
print("menu:onDidOpen!")
})
// or
options.style = .slideAbove
...
Option | Type | Default value | Description |
---|---|---|---|
style |
NSideMenuStyle |
.normal |
Presentation Style |
side |
NSideMenuSide |
.leading |
Menu presentation side |
width |
CGFloat |
186 |
Menu content container width |
showSkeletonStack |
Bool |
false |
Main view content Skeleton stack visiblity |
skeletonStackColor |
Color |
Color(UIColor.systemBackground) |
Main view content Skeleton stack color |
cornerRaduisIfNeeded |
CGFloat |
16 |
When style is scale and Menu is visible this property will be applied on the Main view container corners. |
rotationDegreeIfNeeded |
Double |
6 |
When style is rotate and Menu is visible this property will be applied on the Main view container rotation degree. |
show |
Bool |
false |
Side menu view visiblity |
- onWillClose: fired when 'show' property asigned to false or when calling toggleMenu Method.
- onWillOpen: fired when 'show' property asigned to true or when calling toggleMenu Method.
- onDidClose: fired when the side menu close animation did finish.
- onDidOpen: fired when the side menu open animation did finish.
- toggleMenu(animation: Animation? = .default): this method to toggle the side menu visiblity from open to close or from close to open.
- showMenu(animation: Animation? = .default): this method to open the side menu
- hideMenu(animation: Animation? = .default): this method to close the side menu
- Make the code cleaner.
- Edge Drag Gesture to open or close the side menu.
itisnajim, [email protected]
NSideMenu is available under the MIT license. See the LICENSE file for more info.