mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
### Before: <img width="333" alt="Screenshot 2023-11-19 at 16 01 15" src="https://github.com/RevenueCat/purchases-ios/assets/685609/4286c281-b2e9-463b-a368-726ae44bdc69"> ### After: <img width="328" alt="Screenshot 2023-11-19 at 16 01 06" src="https://github.com/RevenueCat/purchases-ios/assets/685609/234b8c8d-f2ec-4ff4-8153-2c461dc92987">
96 lines
2.8 KiB
Swift
96 lines
2.8 KiB
Swift
//
|
|
// 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
|
|
//
|
|
// TemplateViewConfiguration+Extensions.swift
|
|
//
|
|
// Created by Nacho Soto on 11/19/23.
|
|
|
|
import Foundation
|
|
import RevenueCat
|
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
|
extension TemplateViewConfiguration.PackageConfiguration {
|
|
|
|
/// - Returns: `true` if the packages contain more than one different text
|
|
/// for the given `display`.
|
|
/// This allows determining whether animations are required when transitioning between
|
|
/// packages.
|
|
@MainActor
|
|
func packagesProduceDifferentLabels(
|
|
for display: IntroEligibilityStateView.Display,
|
|
eligibility: IntroEligibilityViewModel
|
|
) -> Bool {
|
|
return self.packagesProduceDifferentLabels(
|
|
for: display,
|
|
eligibility: eligibility.allEligibility
|
|
)
|
|
}
|
|
|
|
/// - Returns: `true` if any of the packages produce text for the given `display`.
|
|
/// This allows determining whether a label is required to be rendered.
|
|
@MainActor
|
|
func packagesProduceAnyLabel(
|
|
for display: IntroEligibilityStateView.Display,
|
|
eligibility: IntroEligibilityViewModel
|
|
) -> Bool {
|
|
return self.packagesProduceAnyLabel(
|
|
for: display,
|
|
eligibility: eligibility.allEligibility
|
|
)
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Implementation
|
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
|
extension TemplateViewConfiguration.PackageConfiguration {
|
|
|
|
typealias Eligibility = [Package: IntroEligibilityStatus]
|
|
|
|
func packagesProduceDifferentLabels(
|
|
for display: IntroEligibilityStateView.Display,
|
|
eligibility: Eligibility
|
|
) -> Bool {
|
|
return self.labels(for: display, eligibility: eligibility).count > 1
|
|
}
|
|
|
|
func packagesProduceAnyLabel(
|
|
for display: IntroEligibilityStateView.Display,
|
|
eligibility: Eligibility
|
|
) -> Bool {
|
|
return self
|
|
.labels(for: display, eligibility: eligibility)
|
|
.contains { !$0.isEmpty }
|
|
}
|
|
|
|
}
|
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
|
private extension TemplateViewConfiguration.PackageConfiguration {
|
|
|
|
private func labels(
|
|
for display: IntroEligibilityStateView.Display,
|
|
eligibility: Eligibility
|
|
) -> Set<String> {
|
|
return Set(
|
|
self.all
|
|
.lazy
|
|
.map {
|
|
IntroEligibilityStateView.text(
|
|
for: display,
|
|
localization: $0.localization,
|
|
introEligibility: eligibility[$0.content]
|
|
)
|
|
}
|
|
)
|
|
}
|
|
|
|
}
|