My SwiftUI app freezes when completing a purchase in StoreKit if I have .fullScreenCover
modifier applied anywhere in the View hierarchy.
It doesn't matter where I put the .fullScreenCover
modifier in the view hierarchy. Even if I place it somewhere else in the hierarchy and don't trigger it, the app will still freeze on completed purchase. As soon as I remove .fullScreenCover
modifier everything works great.
Anyone else had this issue? Is this a known issue? Is there a fix for this?
struct ShopView: View {
@EnvironmentObject var store: Store
@State var isFullScreenCoverPresented: Bool = false
@State var purchasedTip: Tip? = nil
var body: some View {
VStack {
VStack {
ForEach(store.products.sorted(by: { $0.price < $1.price })) { product in
ProductView(product) {
Image("productImage")
}
}
}
}
.onInAppPurchaseCompletion { product, result in
if case .success(.success(.verified(let transaction))) = result {
await store.process(transaction)
// make sure there's a Tip corresponding to the purchased product
if let tip = Tip(rawValue: product.id) {
purchasedTip = tip
}
// show thank you note in full screen cover
isFullScreenCoverPresented = true
}
}
.fullScreenCover(isPresented: $isFullScreenCoverPresented) {
if let tip = purchasedTip {
ThankYouNote(tip: tip)
}
}
}
}