Use FeatureModel in paywall (#442)

Rather than anonymous tuples.
This commit is contained in:
Davide De Rosa 2023-12-23 12:38:00 +01:00 committed by GitHub
parent 7d7aaa8b0c
commit 47c6b02c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 7 deletions

View File

@ -75,6 +75,35 @@ extension PaywallView {
} }
} }
private struct FeatureModel: Identifiable, Comparable {
let productIdentifier: String
let title: String
let subtitle: String?
init(localProduct: LocalProduct, title: String) {
productIdentifier = localProduct.rawValue
self.title = title
subtitle = nil
}
init(product: InAppProduct) {
productIdentifier = product.productIdentifier
title = product.localizedTitle
let description = product.localizedDescription
subtitle = description != title ? description : nil
}
var id: String {
productIdentifier
}
static func < (lhs: Self, rhs: Self) -> Bool {
lhs.title.lowercased() < rhs.title.lowercased()
}
}
private struct PurchaseRow: View { private struct PurchaseRow: View {
var product: InAppProduct? var product: InAppProduct?
@ -94,12 +123,12 @@ private struct PurchaseRow: View {
private extension PaywallView.PurchaseView { private extension PaywallView.PurchaseView {
var featuresSection: some View { var featuresSection: some View {
Section { Section {
ForEach(features, id: \.productIdentifier) { product in ForEach(features) { feature in
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(product.localizedTitle) Text(feature.title)
.themeCellTitleStyle() .themeCellTitleStyle()
if product.localizedDescription != product.localizedTitle { feature.subtitle.map {
Text(product.localizedDescription) Text($0)
.themeCellSubtitleStyle() .themeCellSubtitleStyle()
.themeSecondaryTextStyle() .themeSecondaryTextStyle()
} }
@ -166,12 +195,12 @@ private extension PaywallView.PurchaseView {
return productManager.product(withIdentifier: .fullVersion) return productManager.product(withIdentifier: .fullVersion)
} }
var features: [InAppProduct] { var features: [FeatureModel] {
productManager.featureProducts(excluding: { productManager.featureProducts(excluding: {
$0 == .fullVersion || $0.isPlatformVersion $0 == .fullVersion || $0.isPlatformVersion
}) })
.sorted { .map {
$0.localizedTitle.lowercased() < $1.localizedTitle.lowercased() FeatureModel(product: $0)
} }
} }