Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swiftui slide menu

struct MenuContent: View {
    var body: some View {
        List {
            Text("My Profile").onTapGesture {
                print("My Profile")
            }
            Text("Posts").onTapGesture {
                print("Posts")
            }
            Text("Logout").onTapGesture {
                print("Logout")
            }
        }
    }
}

struct SideMenu: View {
    let width: CGFloat
    let isOpen: Bool
    let menuClose: () -> Void
    
    var body: some View {
        ZStack {
            GeometryReader { _ in
                EmptyView()
            }
            .background(Color.gray.opacity(0.3))
            .opacity(self.isOpen ? 1.0 : 0.0)
            .animation(Animation.easeIn.delay(0.25))
            .onTapGesture {
                self.menuClose()
            }
            
            HStack {
                MenuContent()
                    .frame(width: self.width)
                    .background(Color.white)
                    .offset(x: self.isOpen ? 0 : -self.width)
                    .animation(.default)
                
                Spacer()
            }
        }
    }
}

struct ContentView: View {
    @State var menuOpen: Bool = false
    
    var body: some View {
        ZStack {
            if !self.menuOpen {
                Button(action: {
                    self.openMenu()
                }, label: {
                    Text("Open")
                })
            }
            
            SideMenu(width: 270,
                     isOpen: self.menuOpen,
                     menuClose: self.openMenu)
        }
    }
    
    func openMenu() {
        self.menuOpen.toggle()
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: do something when your HTTP response finishes. swift 
Swift :: Swift Find Number of Dictionary Elements 
Swift :: how to change the tint color of tab bar on storyboard swift 
Swift :: uilabel font size and bold 
Swift :: Typealias for built-in types 
Swift :: swift how to append an element 
Swift :: ns transport swift code 
Swift :: Swift Overriding Methods and Properties 
Swift :: key path expression as functions ios swift 
Swift :: Swift Access Control 
Swift :: swift overlay view 
Swift :: Swift Bitwise OR Operator 
Swift :: Adapt sfsymbol to frame swiftui 
Swift :: microsoft flight simulator uses which language 
Ruby :: kill rails 
Ruby :: If the version you need is missing, try upgrading ruby-build. linux 
Ruby :: rails delete link 
Ruby :: ruby constructor 
Ruby :: rails g model references 
Ruby :: contains ruby array 
Ruby :: check rails version 
Ruby :: ruby unshift method 
Ruby :: how to link to with font awesome rails 
Ruby :: ruby prepend array 
Ruby :: contain .where rails 
Ruby :: rails secure uuid 
Ruby :: ruby class variable 
Ruby :: get all the associations of a rails model 
Ruby :: rails string to html 
Ruby :: ruby function arguments 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =