Using .location in the stack coordinate space instead of .translation avoids the problem, whatever it was. The following works as desired with no infinite loop.
import Foundation
import SwiftUI
import PlaygroundSupport
PlaygroundPage.current.setLiveView(ContentView())
struct ContentView: View {
@State var position: Double = 50
var body: some View {
VStack(spacing: 0) {
Color.red.frame(width: 500, height: position)
PaneDivider(position: $position)
Color.blue
}
.frame(width: 500, height:500)
.coordinateSpace(name: "stack")
}
}
struct PaneDivider: View {
@Binding var position: Double
var body: some View {
Color.yellow.frame(height: 8)
.gesture(
DragGesture(minimumDistance: 1, coordinateSpace: .named("stack"))
.onChanged { position = max(0, $0.location.y) }
)
}
}