-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: extracted intro eligibility out of templates (#2901)
This simplifies template views further. Before they needed to get the `TrialOrIntroEligibilityChecker` environment and call the appropriate method. Now they just need to inject the new `IntroEligibilityViewModel`, and extract either `.allEligibility` or `singleEligibility` based on the type of template. Everything else is done automatically outside of templates.
- Loading branch information
Showing
5 changed files
with
65 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// IntroEligibilityViewModel.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/26/23. | ||
// | ||
|
||
import RevenueCat | ||
import SwiftUI | ||
|
||
/// Holds the state for dynamically computed `IntroEligibilityStatus` | ||
/// for single or multi-package templates, depending on `PackageConfiguration`. | ||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) | ||
@MainActor | ||
final class IntroEligibilityViewModel: ObservableObject { | ||
|
||
typealias PackageConfiguration = TemplateViewConfiguration.PackageConfiguration | ||
|
||
private let introEligibilityChecker: TrialOrIntroEligibilityChecker | ||
|
||
init(introEligibilityChecker: TrialOrIntroEligibilityChecker) { | ||
self.introEligibilityChecker = introEligibilityChecker | ||
} | ||
|
||
@Published | ||
private(set) var allEligibility: [Package: IntroEligibilityStatus] = [:] | ||
@Published | ||
private(set) var singleEligibility: IntroEligibilityStatus? | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) | ||
extension IntroEligibilityViewModel { | ||
|
||
func computeEligibility(for packages: PackageConfiguration) async { | ||
switch packages { | ||
case let .single(package): | ||
self.singleEligibility = await self.introEligibilityChecker.eligibility(for: package.content) | ||
|
||
case let .multiple(_, _, packages): | ||
self.allEligibility = await self.introEligibilityChecker.eligibility(for: packages.map(\.content)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters