0

I have a View that has similar properties to this and I am trying to create a gesture so the user can drag it down to make it compact:

struct myView: View {
    @State var isCompact = false
    var body: some View {
        Text("")
        Text("")
        if isCompact {
            Text("")
        }
        Image("")
        Text("")
        Button {
            isCompact.toggle()
        } label: {
            Text("button")
        }
    }
}

What would be the best way to make this view draggable in such a way?

I am currently using a gesture like this:

.gesture(DragGesture(minimumDistance: 30)
                .onEnded { value in
                    if !compact.isCompact {
                        if value.translation.height > 0 {
                            withAnimation {
                                compact.isCompact = true
                            }
                        }
                    }
                })

but this will only detect the swipe then toggle the isCompact bool, so it doesn't interactively drag the view

Halpo
  • 2,982
  • 3
  • 25
  • 54
  • Have you tried keying a `.frame(height:)` to the drag gesture? – Yrb Jul 22 '23 at 20:14
  • what if you don't know the exact height? how can you reduce the intrinsic height by the value of a state variable? – Halpo Jul 24 '23 at 08:25
  • A percentage of the view height. There are lots of tutorials and answers on this. – Yrb Jul 24 '23 at 18:40

0 Answers0