Behavior of reading frames through GeometryReader is confusing on macOS.
Apparently when you read a frame in local or named coordinate space, returned frame is in the "SwiftUI coordinate system" where the (0,0) point is in the upper-left corner.
However, when you read a frame in a global space, returned frame is in the "native macOS system" where the (0,0) is in the bottom-left corner.
Is this behavior documented anywhere or is it a bug?
I would suspect SwiftUI to always return frames in the same way on all the platforms.
I'm trying to figure out if I'm missing something here.
My sample code:
Output:
Apparently when you read a frame in local or named coordinate space, returned frame is in the "SwiftUI coordinate system" where the (0,0) point is in the upper-left corner.
However, when you read a frame in a global space, returned frame is in the "native macOS system" where the (0,0) is in the bottom-left corner.
Is this behavior documented anywhere or is it a bug?
I would suspect SwiftUI to always return frames in the same way on all the platforms.
I'm trying to figure out if I'm missing something here.
My sample code:
Code Block swift struct ContentView: View { var body: some View { ZStack(alignment: .bottom) { Color.blue .frame(width: 100, height: 150) Color.red .frame(width: 20, height: 60) .background( GeometryReader { geo -> Color in let g = geo.frame(in: .global) let s = geo.frame(in: .named("stack")) print("Global: \(g) | Stack: \(s)") return Color.purple } ) .padding(.bottom, 5) } .padding(40) .coordinateSpace(name: "stack") .background(Color.pink) }
Output:
Global: (80.0, 45.0, 20.0, 60.0) | Stack: (80.0, 125.0, 20.0, 60.0)