Improve appearance of "Purchased"

- Animate load
- Handle load errors
This commit is contained in:
Davide 2024-11-26 17:20:22 +01:00
parent aa9da8c9e0
commit b455701daa
No known key found for this signature in database
GPG Key ID: A48836171C759F5E

View File

@ -32,22 +32,36 @@ public struct PurchasedView: View {
@EnvironmentObject
private var iapManager: IAPManager
@State
private var isLoading = true
@State
private var products: [InAppProduct] = []
@StateObject
private var errorHandler: ErrorHandler = .default()
public init() {
}
public var body: some View {
contentView
.themeEmpty(if: isEmpty, message: Strings.Views.Purchased.noPurchases)
.withErrorHandler(errorHandler)
.themeProgress(if: isLoading)
.themeAnimation(on: isLoading, category: .diagnostics)
.onLoad {
Task {
do {
products = try await iapManager
.purchasableProducts(for: Array(iapManager.purchasedProducts))
.sorted {
$0.localizedTitle < $1.localizedTitle
}
isLoading = false
} catch {
errorHandler.handle(error)
isLoading = false
}
}
}
}
@ -93,17 +107,19 @@ private extension PurchasedView {
}
var productsSection: some View {
products.nilIfEmpty.map { products in
Group {
if !products.isEmpty {
ForEach(products, id: \.productIdentifier) {
Text($0.localizedTitle)
.themeTrailingValue($0.localizedPrice)
.scrollableOnTV()
}
} else {
Text(Strings.Views.Purchased.noPurchases)
}
}
.themeSection(header: Strings.Views.Purchased.Sections.Products.header)
}
}
var featuresSection: some View {
Group {