3

I know that it's common to use .background or .overlay to wrap a GeometryReader so that it doesn't modify parent views, but in this instance I don't have any views in the VStack to attach .background or .overlay to. I tried using an EmptyView then using .overlay but my view disappeared.

struct TestView: View {
    
    var body: some View {
        VStack {
            GeometryReader { geometry in  //how can I wrap this in a .overlay so it doesn't manipulate parent views?
                SecondView(proxy: geometry)
            }
        }
    }
    
}
GarySabo
  • 5,806
  • 5
  • 49
  • 124

1 Answers1

1

Try Color.clear - it won't make your view disappear and will keep the layout.

struct TestView: View {
    var body: some View {
        VStack {
            
            /// here!
            Color.clear.overlay(
                GeometryReader { geometry in  //how can I wrap this in a .overlay so it doesn't manipulate parent views?
                    SecondView(proxy: geometry)
                }
            )
        }
    }
}
aheze
  • 24,434
  • 8
  • 68
  • 125