I tried to do a resizable view with a gesture.
The problem is that when I move my gesture object left or right the app will be freeze with 100% processor usage. It is the loop between two Text
views.
What did I do wrong, and how do I make this correct?
struct TestView2 : View {
@State private var width : CGFloat = 400.0
var body : some View {
VStack {
ZStack(alignment: .bottomTrailing) {
Text("\(width)")
.frame(width: width)
Text(":")
.frame(width: 10, height: 30)
.background(.bar)
.gesture(
DragGesture()
.onChanged { value in
width = max(100, width + value.translation.width)
print(width)
}
)
}
.frame(width: width, height: 30, alignment: .topLeading)
.border(.gray, width: 1)
.background(.green)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
}
View:
Debugger:
For me, the solution was to explicitly set the gesture's
coordinateSpace
to.global
: