Files
purchases-ios/RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift
T

110 lines
4.4 KiB
Swift
Raw Normal View History

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// ProcessedLocalizedConfiguration.swift
import Foundation
import RevenueCat
/// A `PaywallData.LocalizedConfiguration` with processed variables
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration {
typealias Feature = PaywallData.LocalizedConfiguration.Feature
var title: String
var subtitle: String?
var callToAction: String
var callToActionWithIntroOffer: String?
var offerDetails: String?
var offerDetailsWithIntroOffer: String?
2023-07-26 12:48:52 +02:00
var offerName: String?
var offerBadge: String?
var features: [Feature]
2024-07-01 12:37:21 -07:00
var tierName: String?
var locale: Locale
init(
_ configuration: PaywallData.LocalizedConfiguration,
_ dataProvider: VariableDataProvider,
_ context: VariableHandler.Context,
_ locale: Locale
) {
let packageIdentifier = dataProvider.packageIdentifier
let offerOverrides = configuration.offerOverrides[packageIdentifier]
let offerDetails = offerOverrides?.offerDetails ?? configuration.offerDetails
let offerDetailsWithIntroOffer = offerOverrides?.offerDetailsWithIntroOffer
?? configuration.offerDetailsWithIntroOffer
let offerName = offerOverrides?.offerName ?? configuration.offerName
let offerBadge: String?
if let offerOverrides {
offerBadge = offerOverrides.offerBadge
} else if let discount = context.discountRelativeToMostExpensivePerMonth {
offerBadge = dataProvider.localizedRelativeDiscount(discount, locale)
} else {
offerBadge = nil
}
self.init(
title: configuration.title.processed(with: dataProvider, context: context, locale: locale),
subtitle: configuration.subtitle?.processed(with: dataProvider, context: context, locale: locale),
callToAction: configuration.callToAction.processed(with: dataProvider, context: context, locale: locale),
callToActionWithIntroOffer: configuration.callToActionWithIntroOffer?.processed(with: dataProvider,
context: context,
locale: locale),
offerDetails: offerDetails?.processed(with: dataProvider, context: context, locale: locale),
offerDetailsWithIntroOffer: offerDetailsWithIntroOffer?.processed(with: dataProvider,
context: context,
locale: locale),
offerName: offerName?.processed(with: dataProvider, context: context, locale: locale),
offerBadge: offerBadge?.processed(with: dataProvider, context: context, locale: locale),
features: configuration.features.map {
.init(title: $0.title.processed(with: dataProvider, context: context, locale: locale),
content: $0.content?.processed(with: dataProvider, context: context, locale: locale),
iconID: $0.iconID)
2024-07-01 12:37:21 -07:00
},
tierName: configuration.tierName,
locale: locale
)
}
private init(
title: String,
subtitle: String?,
callToAction: String,
callToActionWithIntroOffer: String?,
offerDetails: String?,
2023-07-26 12:48:52 +02:00
offerDetailsWithIntroOffer: String?,
offerName: String?,
offerBadge: String?,
2024-07-01 12:37:21 -07:00
features: [Feature],
tierName: String?,
locale: Locale
) {
self.title = title
self.subtitle = subtitle
self.callToAction = callToAction
self.callToActionWithIntroOffer = callToActionWithIntroOffer
self.offerDetails = offerDetails
self.offerDetailsWithIntroOffer = offerDetailsWithIntroOffer
2023-07-26 12:48:52 +02:00
self.offerName = offerName
self.offerBadge = offerBadge
self.features = features
2024-07-01 12:37:21 -07:00
self.tierName = tierName
self.locale = locale
}
}
2023-07-24 14:41:43 +02:00
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
2023-07-24 14:41:43 +02:00
extension ProcessedLocalizedConfiguration: Equatable {}