i'm playing around with SwiftUI and try to get correct screen size depending on orientation. The solution works fine in simulator on iPhone but lacks on iPad (i have no iPad for testing real). It seems on iPad it is just missing the redraw-event. Is there a bug in SwiftUI or did I need to add some code?
struct ContentView: View {
@Environment(\.layoutDirection) var layoutDir
// verticalSizeClass initiate redrawing UI based on new direction (horSizeClass won't work)
@Environment(\.verticalSizeClass) var vertSizeClass
var body: some View {
VStack{
Text("UIDevice.current.orientation").font(.title)
if UIDevice.current.orientation.isPortrait {
Text("Portrait")
} else if UIDevice.current.orientation.isLandscape {
Text("Landscape")
} else if UIDevice.current.orientation.isFlat {
Text("is Flat")
}
Text("UIScreen.main.bounds").font(.title)
Text("Width:\(UIScreen.main.bounds.width)")
Text("Height:\(UIScreen.main.bounds.height)")
Text("@Environment(\\.horizontalSizeClass").font(.title)
if vertSizeClass == .regular {
Text("regular")
} else if vertSizeClass == .compact {
Text("compact")
} else {
Text("default")
}
}
}
}