-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: handle missing paywalls gracefully (#2855)
- Improved `PaywallView` API: now there's only 2 constructors (with optional `Mode` parameters): - `PaywallView()` - `PaywallView(offering:)` - New `PaywallData.default` as a fallback when trying to present a paywall with missing data (either because it failed to decode, or it's missing) - Extracted error state handling to `ErrorDisplay` (used by `PaywallView` and `AsyncButton` now). It can optionally dismiss the presenting sheet. - Handling offering loading errors in `PaywallView` - Improved `DebugErrorView` to allow displaying a fallback view: ```swift DebugErrorView( "Offering '\(offering.identifier)' has no configured paywall.\n" + "The displayed paywall contains default configuration.\n" + "This error will be hidden in production.", releaseBehavior: .replacement( AnyView( LoadedOfferingPaywallView( offering: offering, paywall: .default, mode: mode, introEligibility: checker, purchaseHandler: purchaseHandler ) ) ) ) ``` - Added `LoadingPaywallView` as a placeholder view during loading - Improved `MultiPackageTemplate` and `RemoteImage` to fix some layout issues during transitions - Added transition animations between loading state and loaded paywall
- Loading branch information
Showing
25 changed files
with
533 additions
and
195 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
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,33 @@ | ||
// | ||
// PaywalError.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/21/23. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Error produced when displaying paywalls. | ||
enum PaywallError: Error { | ||
|
||
/// RevenueCat dashboard does not have a current offering configured | ||
case noCurrentOffering | ||
|
||
} | ||
|
||
extension PaywallError: CustomNSError { | ||
|
||
var errorUserInfo: [String: Any] { | ||
return [ | ||
NSLocalizedDescriptionKey: self.description | ||
] | ||
} | ||
|
||
private var description: String { | ||
switch self { | ||
case .noCurrentOffering: | ||
return "The RevenueCat dashboard does not have a current offering configured." | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
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,35 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/21/23. | ||
// | ||
|
||
import RevenueCat | ||
import SwiftUI | ||
|
||
struct LocalizedAlertError: LocalizedError { | ||
|
||
private let underlyingError: NSError | ||
|
||
init(error: NSError) { | ||
self.underlyingError = error | ||
} | ||
|
||
var errorDescription: String? { | ||
return "\(self.underlyingError.domain) \(self.underlyingError.code)" | ||
} | ||
|
||
var failureReason: String? { | ||
if let errorCode = self.underlyingError as? ErrorCode { | ||
return errorCode.description | ||
} else { | ||
return self.underlyingError.localizedDescription | ||
} | ||
} | ||
|
||
var recoverySuggestion: String? { | ||
self.underlyingError.localizedRecoverySuggestion | ||
} | ||
|
||
} |
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,66 @@ | ||
// | ||
// PaywallData+Default.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/20/23. | ||
// | ||
|
||
import Foundation | ||
import RevenueCat | ||
|
||
#if canImport(SwiftUI) && swift(>=5.7) | ||
|
||
extension PaywallData { | ||
|
||
/// Default `PaywallData` to display when attempting to present a ``PaywallView`` with an offering | ||
/// that has no paywall configuration, or when that configuration is invalid. | ||
public static let `default`: Self = .init( | ||
template: .multiPackage, | ||
config: .init( | ||
packages: [.weekly, .monthly, .annual], | ||
imageNames: [ | ||
Self.backgroundImage | ||
], | ||
colors: Self.colors, | ||
blurredBackgroundImage: true, | ||
displayRestorePurchases: true | ||
), | ||
localization: Self.localization, | ||
assetBaseURL: Self.defaultTemplateBaseURL | ||
) | ||
|
||
} | ||
|
||
private extension PaywallData { | ||
|
||
// swiftlint:disable force_try | ||
static let colors: PaywallData.Configuration.ColorInformation = .init( | ||
light: .init( | ||
background: try! .init(stringRepresentation: "#FFFFFF"), | ||
foreground: try! .init(stringRepresentation: "#000000"), | ||
callToActionBackground: try! .init(stringRepresentation: "#EC807C"), | ||
callToActionForeground: try! .init(stringRepresentation: "#FFFFFF") | ||
), | ||
dark: .init( | ||
background: try! .init(stringRepresentation: "#000000"), | ||
foreground: try! .init(stringRepresentation: "#FFFFFF"), | ||
callToActionBackground: try! .init(stringRepresentation: "#ACD27A"), | ||
callToActionForeground: try! .init(stringRepresentation: "#000000") | ||
) | ||
) | ||
// swiftlint:enable force_try | ||
|
||
static let localization: PaywallData.LocalizedConfiguration = .init( | ||
title: "Subscription", | ||
subtitle: "Unlock access", | ||
callToAction: "Purchase", | ||
offerDetails: "{{ price_per_month }} per month", | ||
offerDetailsWithIntroOffer: "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month" | ||
) | ||
|
||
static let backgroundImage = "background.jpg" | ||
static let defaultTemplateBaseURL = Bundle.module.resourceURL ?? Bundle.module.bundleURL | ||
|
||
} | ||
|
||
#endif |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.