ios – SwiftUI Sidebar Make Additional House Clickable


I learn that Spacer() doesn’t work with onTapGesture because it requires seen/opaque views(?).

It is a snippet of my code.

         HStack {
                SideMenuView(darkish: self.$darkish, present: self.$present, navigationManager: navigationManager)
                    .preferredColorScheme(self.darkish ? .darkish : .mild)
                    .offset(x: self.present ? 0 : -UIScreen.primary.bounds.width / 1.2)
                Spacer(minLength:  0)
            }
            .background(Coloration.main.opacity(self.present ? (self.darkish ? 0.05 : 0.2) : 0).edgesIgnoringSafeArea(.all))
            .onTapGesture {
                withAnimation(.default) {
                    present.toggle()
                }
            }

What I’m making an attempt to resolve is to make the additional area beside the sidebar clickable (so it may be collapsed). With the present code, in every single place within the display that doesn’t obtain enter will set off onTapGesture (Textual content labels within the sidebar, additional area beside it)

Is there a view I’m lacking right here? Or do i want so as to add a Rectangle() and calculate the additional area?

Leave a Reply