I have the following code:
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
GeometryReader { geometry in
LocationPickerView()
.frame(maxWidth: geometry.size.width, maxHeight: geometry.size.height)
.ignoresSafeArea()
}
}
}
}
My goal is to have my LocationPickerView() take up the entire screen regardless of the orientation of the device. A LocationPickerView() is a custom view I built:
struct LocationView: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView()
return arView
}
func updateUIView(_ uiView: ARView, context: Context) { }
}
However, I have a problem. The safe area is not being ignored. At first glance, I thought this was because the frame was already set by a "constant" value from geometry.
So, I thought I would flip the order of when I ignore the safe area and when I set the frame. This only resulted in a much weirder configuration. At first, the view does take up the entire screen. However, when I change the device to another orientation, the view stays the original height and width it was without updating, despite using GeometryReader
.
What is happening here? I am certain this is valid behavior, but I don't understand why it is and how to fix it. I am trying to make things as simple as possible and thought I would add the frame and safe area options in my main struct, in an attempt to keep that code out of every view.
This feels like an easy fix, but I can't figure it out.