-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: determine intro eligibility (#2808)
Follow up to #2796. This also makes `PaywallData.Configuration`'s intro strings optional. - Injected `TrialOrIntroEligibilityChecker` - Created mock `TrialOrIntroEligibilityChecker` for previews - Handling state and transitions for loading eligibility - Snapshot tests for the different new cases - Improved `SnapshotTesting` delay management - Expanded `DebugErrorView` to customize release behavior
- Loading branch information
Showing
18 changed files
with
358 additions
and
71 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,15 @@ | ||
// | ||
// Constants.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/13/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) | ||
enum Constants { | ||
|
||
static let defaultAnimation: Animation = .easeIn(duration: 0.2) | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// TrialOrIntroEligibilityChecker.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/13/23. | ||
// | ||
|
||
import Foundation | ||
import RevenueCat | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) | ||
final class TrialOrIntroEligibilityChecker: ObservableObject { | ||
|
||
typealias Checker = @Sendable (StoreProduct) async -> IntroEligibilityStatus | ||
|
||
let checker: Checker | ||
|
||
convenience init(purchases: Purchases = .shared) { | ||
self.init { product in | ||
guard product.hasIntroDiscount else { | ||
return .noIntroOfferExists | ||
} | ||
|
||
return await purchases.checkTrialOrIntroDiscountEligibility(product: product) | ||
} | ||
} | ||
|
||
/// Creates an instance with a custom checker, useful for testing or previews. | ||
init(checker: @escaping Checker) { | ||
self.checker = checker | ||
} | ||
|
||
} | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) | ||
extension TrialOrIntroEligibilityChecker { | ||
|
||
func eligibility(for product: StoreProduct) async -> IntroEligibilityStatus { | ||
return await self.checker(product) | ||
} | ||
|
||
func eligibility(for package: Package) async -> IntroEligibilityStatus { | ||
return await self.eligibility(for: package.storeProduct) | ||
} | ||
|
||
} | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) | ||
extension StoreProduct { | ||
|
||
var hasIntroDiscount: Bool { | ||
// Fix-me: this needs to handle other types of intro discounts | ||
return self.introductoryDiscount != nil | ||
} | ||
|
||
} |
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,23 @@ | ||
// | ||
// ViewExtensions.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/13/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) | ||
extension View { | ||
|
||
@ViewBuilder | ||
func hidden(if condition: Bool) -> some View { | ||
if condition { | ||
self.hidden() | ||
} else { | ||
self | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.