import SwiftUI
struct OuterView: View {
var body: some View {
VStack {
Text("Top")
InnerView()
Text("Bottom")
}
.background(Color.blue)
}
}
struct InnerView: View {
var body: some View {
HStack {
Text("Left")
GeometryReader { geo in
Text("Center")
.padding()
.background(Color.yellow)
.onTapGesture {
let localFrame = geo.frame(in: .local)
let globalFrame = geo.frame(in: .global)
let customFrame = geo.frame(in: .named("custom"))
print("Local center: (x: \(localFrame.midX), y: \(localFrame.midY))")
print("Global center: (x: \(globalFrame.midX), y: \(globalFrame.midY))")
print("Custom center: (x: \(customFrame.midX), y: \(customFrame.midY))")
}
}
.background(Color.orange)
Text("Right")
}
.background(Color.green)
}
}
struct Geo: View {
var body: some View {
// OuterView()
// .coordinateSpace(name: "custom")
// .border(Color.black, width: 2)
// TempView()
// .background(Color.yellow)
ColorView()
}
}
struct ColorView: View {
var body: some View {
HStack {
Color.red
Text("Top")
Color.green
}
.background(Color.yellow)
}
}
struct TempView: View {
var body: some View {
VStack {
Text("Top")
Text("Bottom")
}
.background(Color.yellow)
}
}
Why Color yellow does not fill all screen? Why blue go out of border? Why Blue fill safe area?
How I know so we propose frames from bottom to top ( modifiers ), then back then draw. So if we imagine that We have basic view it propose to outer view what? all screen with safe area? but Color is shape style so in goes beyond. Why then it not goes beyond the Text. Outer View has frame to safe area then why color not? Problem s in GeometryReader? SO Outer View respond to parent that it take frame = nil, like all available space? So OuterView does not have concrete Frame? thats the point? And TempView has, because Text returned instrict content size?
Why then ColorView make background yellow beyond safearea when colors itself not?