I'd like to use .fullScreenCover() or .sheet() to present a View, depending on the current horizontalSizeClass.
If starting the following code in an iPhone (in portrait mode = .compact) or in an iPad (= .regular), the View is correctly displayed in a Sheet (iPhone) or in a FullScreenCover (iPad).
However when using SplitScreen mode on an iPad (and thus switching between .compact and .regular the View remains in the container it was originally displayed.
How can I correctly update this when switching between sizes on-the-fly?
struct ContentView: View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass
var body: some View {
Group {
Text("hidden behind modal")
}
.modal(isPresented: .constant(true)) {
if horizontalSizeClass == .regular {
Rectangle()
.fill(Color.red)
.edgesIgnoringSafeArea(.all)
} else {
Rectangle()
.fill(Color.blue)
.edgesIgnoringSafeArea(.all)
}
}
}
}
struct Modal<ModalContent: View>: ViewModifier {
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@Binding var isPresented: Bool
@ViewBuilder let modalContent: ModalContent
func body(content: Content) -> some View {
if horizontalSizeClass == .regular {
content
.fullScreenCover(isPresented: $isPresented) {
modalContent
.overlay {
Text("horizontalSizeClass: regular")
}
}
} else {
content
.sheet(isPresented: $isPresented) {
modalContent
.overlay {
Text("horizontalSizeClass: compact")
}
}
}
}
}
extension View {
public func modal<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) -> some View {
modifier(Modal(isPresented: isPresented, modalContent: content))
}
}
Post
Replies
Boosts
Views
Activity
Hello folks
With a recent release of our SwiftUI iOS Enterprise app (around 500k active users/day) we have seen crashes spiking for iOS 15 only (iOS 16 seems unaffected).
Unfortunately we aren't able to reproduce the error (neither on iOS 15 physical devices nor on iOS 15 simulators) yet.
Also the crash logs aren't helping us either. Yes, we do use UserDefaults and @AppStorage, which the crash logs seem to draw our attention to, but don't know where to look for in our code.
9 SwiftUI 0x000000018a1263f4 UserDefaultObserver.Target.GraphAttribute.send() + 208 (AppStorage.swift:797)
Any ideas how to debug this?
2023-02-02_15-47-22.0623_+0100-d4b5f1e1feb6d90fb33c8c9c756751ac52db0ab7.crash
We are using WKWebView to display a website (developed by us) in our app. When triggering a reload through code (e.g. when foregrounding the app), sometimes WKWebView will set the CachePolicy to returnCacheDataElseLoad. This means that WKWebView will then show outdated content from the user, since it will load the site content from local cache.
We are not manually setting CachePolicy anywhere.
Why does WKWebView decide to use returnCacheDataElseLoad?
The server respons with the following cache-control header:
public, max-age=9, s-maxage=2592000