mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-01-31 04:52:05 +00:00
Improve appearance of "Purchased"
- Animate load - Handle load errors
This commit is contained in:
parent
aa9da8c9e0
commit
b455701daa
@ -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 {
|
||||
products = try await iapManager
|
||||
.purchasableProducts(for: Array(iapManager.purchasedProducts))
|
||||
.sorted {
|
||||
$0.localizedTitle < $1.localizedTitle
|
||||
}
|
||||
do {
|
||||
products = try await iapManager
|
||||
.purchasableProducts(for: Array(iapManager.purchasedProducts))
|
||||
.sorted {
|
||||
$0.localizedTitle < $1.localizedTitle
|
||||
}
|
||||
isLoading = false
|
||||
} catch {
|
||||
errorHandler.handle(error)
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,16 +107,18 @@ private extension PurchasedView {
|
||||
}
|
||||
|
||||
var productsSection: some View {
|
||||
products.nilIfEmpty.map { products in
|
||||
Group {
|
||||
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)
|
||||
}
|
||||
.themeSection(header: Strings.Views.Purchased.Sections.Products.header)
|
||||
}
|
||||
|
||||
var featuresSection: some View {
|
||||
|
Loading…
Reference in New Issue
Block a user