Skip to content

Commit

Permalink
Improve "Purchased" view (#979)
Browse files Browse the repository at this point in the history
- Show eligible features first
- Render ineligible features as secondary
  • Loading branch information
keeshux authored Dec 4, 2024
1 parent 4ef47df commit d8f5caa
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions Library/Sources/UILibrary/Views/About/PurchasedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ private extension PurchasedView {
}

var allFeatures: [AppFeature] {
AppFeature.allCases.sorted()
AppFeature.allCases.sorted {
let lRank = $0.rank(with: iapManager)
let rRank = $1.rank(with: iapManager)
if lRank != rRank {
return lRank < rRank
}
return $0 < $1
}
}
}

Expand Down Expand Up @@ -124,18 +131,41 @@ private extension PurchasedView {
var featuresSection: some View {
Group {
ForEach(allFeatures, id: \.self) { feature in
HStack {
Text(feature.localizedDescription)
Spacer()
ThemeImage(iapManager.isEligible(for: feature) ? .marked : .close)
}
.scrollableOnTV()
FeatureView(text: feature.localizedDescription, isEligible: iapManager.isEligible(for: feature))
.scrollableOnTV()
}
}
.themeSection(header: Strings.Views.Purchased.Sections.Features.header)
}
}

private struct FeatureView: View {
let text: String

let isEligible: Bool

var body: some View {
HStack {
Text(text)
Spacer()
ThemeImage(isEligible ? .marked : .close)
}
.foregroundStyle(isEligible ? .primary : .secondary)
}
}

// MARK: -

private extension AppFeature {

@MainActor
func rank(with iapManager: IAPManager) -> Int {
iapManager.isEligible(for: self) ? 0 : 1
}
}

// MARK: - Previews

#Preview {
PurchasedView()
.withMockEnvironment()
Expand Down

0 comments on commit d8f5caa

Please sign in to comment.