i am trying to expand and collaps Vstack on the click of button as well as by using Drag.
I am able to to it using button click by below code but not sure hoe to use drag gesture.
import SwiftUI
struct ContentView: View {
@State private var Expand = false
var body: some View {
VStack {
Color
.red
}
.overlay(
GeometryReader { geometry in
VStack() {
VStack {
Text("1")
if Expand {
Text("2")
Text("3")
Text("4")
Text("5")
}
}
Button(Expand ? "Collaps" : "Expand") {
Expand.toggle()
}
}
.background(.yellow)
.frame(maxWidth: .infinity)
}
)
}
}
2
Answers
Here is something I did once. Today you might want to do it with PreferenceKey.
check it!
https://stackoverflow.com/a/59540581/17281765
Let me know if it’s not right