mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-09 22:35:56 +05:45
### Motivation Template 5 but with multiple tiers 😊 ### Description Enabling Template 7 by changing `7_disabled` to `7` - Changed a `header.jpg` to `header.heic` to try and fix issue with weirdly failing snapshot UI test - Changed visibility on `TestData` from `public` to `internal` - Hides tier selector if only one tier - Changed `color_overrides_by_tier` to `colors_by_tier` and `image_overrides_by_tier` to `images_by_tier` - The original implementation was going to default to existing color and images configurations and then override by tier - However, this turned out to be harder to implement on the configuration side - `Colors` got four new optional values - `tier_control_background` - `tier_control_foreground` - `tier_control_selected_background` - `tier_control_selected_foreground` ### Demo #### Full Screen https://github.com/RevenueCat/purchases-ios/assets/401294/e5317a53-428c-415e-a1a1-b4231d32a776 ### Footer https://github.com/RevenueCat/purchases-ios/assets/401294/8905b55e-0fa2-49f0-aa1c-d4c1e694fb5b ### Footer Condensed https://github.com/RevenueCat/purchases-ios/assets/401294/311d78fb-bdeb-43cd-b601-9c60a8a54b6f
50 lines
1.5 KiB
Swift
50 lines
1.5 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
|
|
//
|
|
// ConsistentPackageContentView.swift
|
|
//
|
|
// Created by Nacho Soto on 9/22/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// A wrapper view that can display content based on a selected package
|
|
/// and maintain a consistent layout when that selected package changes.
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
|
struct ConsistentPackageContentView<Content: View>: View {
|
|
|
|
typealias Creator = @Sendable @MainActor (TemplateViewConfiguration.Package) -> Content
|
|
|
|
private let packages: [TemplateViewConfiguration.Package]
|
|
private let selected: TemplateViewConfiguration.Package
|
|
private let creator: Creator
|
|
|
|
init(
|
|
packages: [TemplateViewConfiguration.Package],
|
|
selected: TemplateViewConfiguration.Package,
|
|
@ViewBuilder creator: @escaping Creator
|
|
) {
|
|
self.packages = packages
|
|
self.selected = selected
|
|
self.creator = creator
|
|
}
|
|
|
|
var body: some View {
|
|
// We need to layout all possible packages to accomodate for the longest text
|
|
return ZStack {
|
|
ForEach(self.packages, id: \.self.content) { package in
|
|
self.creator(package).opacity(0)
|
|
}
|
|
|
|
self.creator(self.selected)
|
|
}
|
|
}
|
|
|
|
}
|