Skip to content

Instantly share code, notes, and snippets.

@Nomad-Go
Last active April 3, 2020 01:38
Show Gist options
  • Save Nomad-Go/98f67126ff29b9bf2ee8aeaf9c8c5d94 to your computer and use it in GitHub Desktop.
Save Nomad-Go/98f67126ff29b9bf2ee8aeaf9c8c5d94 to your computer and use it in GitHub Desktop.
Shows basic usage of my SwiftUI menu implementation
import SwiftUI
import GridMenu
struct ContentView: View {
//1) I abstracted out the variables that help control the menu behavior and state so that it's easier to manage in the scope of your project
@ObservedObject var gmMenuController = GMMenuController()
var body: some View {
//2) So far my favorite way of positioning a SwiftUI view in a specific corner.
ZStack {
VStack {
HStack {
Spacer()
//3) The collapsed menu is borken out so that the user can choose placement.
GMCollapsedMenu(controller: self.gmMenuController).padding([.top], 40).padding([.trailing], 20).foregroundColor(Color.white)
}
Spacer()
}
//4) The condition to show or hide the menu is managed internally to the library but the consumer of the library
// gets to control all aspects of the display.
if self.gmMenuController.collapsed == false {
GMMenu(controller: self.gmMenuController).background(Color.white)
}
}
.background(Color.gray)
.edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment