Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
03C72FC32D349BAE00297FEC /* IconComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C72FBF2D349BAE00297FEC /* IconComponentView.swift */; };
03C7305B2D35985900297FEC /* TextComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C7305A2D35985500297FEC /* TextComponentTests.swift */; };
03C730F32D35F14600297FEC /* PaywallV2CacheWarming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C730F22D35F13F00297FEC /* PaywallV2CacheWarming.swift */; };
03E1325D2E5007F70028D9FD /* PaywallSlotComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E1325C2E5007F70028D9FD /* PaywallSlotComponent.swift */; };
03E132602E500A570028D9FD /* SlotComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E1325F2E500A540028D9FD /* SlotComponentView.swift */; };
03E132622E500A600028D9FD /* SlotComponentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E132612E500A5B0028D9FD /* SlotComponentViewModel.swift */; };
03E132D92E510B7B0028D9FD /* PaywallSlotLottieComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E132D82E510B7B0028D9FD /* PaywallSlotLottieComponent.swift */; };
03E132E02E510C220028D9FD /* SlotLottieComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E132DE2E510C220028D9FD /* SlotLottieComponentView.swift */; };
03E132E12E510C220028D9FD /* SlotLottieComponentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E132DF2E510C220028D9FD /* SlotLottieComponentViewModel.swift */; };
03E133DA2E5343390028D9FD /* ViewRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E133D92E5343390028D9FD /* ViewRegistry.swift */; };
03E37BEA2D30B32200CD9678 /* PaywallTabsComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E37BE92D30B32200CD9678 /* PaywallTabsComponent.swift */; };
03F0B6512DD5700D00E82199 /* LocalizationDictionaryExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F0B6502DD5700D00E82199 /* LocalizationDictionaryExtensions.swift */; };
03F0B6712DD6364100E82199 /* NavigatetoURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F0B6702DD6363B00E82199 /* NavigatetoURL.swift */; };
Expand Down Expand Up @@ -1496,6 +1503,13 @@
03C7305A2D35985500297FEC /* TextComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextComponentTests.swift; sourceTree = "<group>"; };
03C730F22D35F13F00297FEC /* PaywallV2CacheWarming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallV2CacheWarming.swift; sourceTree = "<group>"; };
03CCFC172DE94FF70052B764 /* Paywall-Screenshots.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Paywall-Screenshots.xctestplan"; sourceTree = "<group>"; };
03E1325C2E5007F70028D9FD /* PaywallSlotComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallSlotComponent.swift; sourceTree = "<group>"; };
03E1325F2E500A540028D9FD /* SlotComponentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlotComponentView.swift; sourceTree = "<group>"; };
03E132612E500A5B0028D9FD /* SlotComponentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlotComponentViewModel.swift; sourceTree = "<group>"; };
03E132D82E510B7B0028D9FD /* PaywallSlotLottieComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallSlotLottieComponent.swift; sourceTree = "<group>"; };
03E132DE2E510C220028D9FD /* SlotLottieComponentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlotLottieComponentView.swift; sourceTree = "<group>"; };
03E132DF2E510C220028D9FD /* SlotLottieComponentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlotLottieComponentViewModel.swift; sourceTree = "<group>"; };
03E133D92E5343390028D9FD /* ViewRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewRegistry.swift; sourceTree = "<group>"; };
03E37BE92D30B32200CD9678 /* PaywallTabsComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallTabsComponent.swift; sourceTree = "<group>"; };
03F0B6502DD5700D00E82199 /* LocalizationDictionaryExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizationDictionaryExtensions.swift; sourceTree = "<group>"; };
03F0B6702DD6363B00E82199 /* NavigatetoURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigatetoURL.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2913,6 +2927,31 @@
path = __PreviewResources__;
sourceTree = "<group>";
};
03E1325E2E500A420028D9FD /* Slot */ = {
isa = PBXGroup;
children = (
03E1325F2E500A540028D9FD /* SlotComponentView.swift */,
03E132612E500A5B0028D9FD /* SlotComponentViewModel.swift */,
);
path = Slot;
sourceTree = "<group>";
};
03E132DD2E510C1D0028D9FD /* SlotLottie */ = {
isa = PBXGroup;
children = (
03E132DE2E510C220028D9FD /* SlotLottieComponentView.swift */,
03E132DF2E510C220028D9FD /* SlotLottieComponentViewModel.swift */,
);
path = SlotLottie;
sourceTree = "<group>";
};
03E133542E5331990028D9FD /* RevenueCatUILottie */ = {
isa = PBXGroup;
children = (
);
path = RevenueCatUILottie;
sourceTree = "<group>";
};
03F446222D2FE0B90046129A /* Properties */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2977,6 +3016,7 @@
2C7457432CEA6470004ACE52 /* Components */ = {
isa = PBXGroup;
children = (
03E132DD2E510C1D0028D9FD /* SlotLottie */,
2C7457472CEA66AB004ACE52 /* ComponentsView.swift */,
7707A94A2CAD936A006E0313 /* Button */,
03C06FC82D479C6300600693 /* Carousel */,
Expand All @@ -2987,6 +3027,7 @@
0354AA452D4029C300F9E330 /* Tabs */,
4D3BA5B12D47AB4400668AFC /* Timeline */,
88B1BADC2C813A3C001B7EE5 /* Text */,
03E1325E2E500A420028D9FD /* Slot */,
778360772CCA85D1000785B8 /* StickyFooter */,
778360742CCA84FA000785B8 /* Root */,
);
Expand Down Expand Up @@ -3953,6 +3994,7 @@
7707A93B2CAD8AA2006E0313 /* Local.xcconfig */,
77607FD72CAD87D60066C23C /* Global.xcconfig */,
887A60652C1D037000E1A461 /* RevenueCatUI */,
03E133542E5331990028D9FD /* RevenueCatUILottie */,
2DC5621724EC63420031F69B /* Sources */,
2DDE870027E5238500D8B390 /* Tests */,
887A5FBB2C1D036200E1A461 /* RevenueCatUIDev */,
Expand Down Expand Up @@ -5457,6 +5499,8 @@
03C730F22D35F13F00297FEC /* PaywallV2CacheWarming.swift */,
2CC791612CC0493600FBE120 /* Common */,
7707A94B2CAD93AC006E0313 /* PaywallButtonComponent.swift */,
03E1325C2E5007F70028D9FD /* PaywallSlotComponent.swift */,
03E132D82E510B7B0028D9FD /* PaywallSlotLottieComponent.swift */,
88AD01032C740CF400AA1F2B /* PaywallImageComponent.swift */,
03C72FBD2D34949600297FEC /* PaywallIconComponent.swift */,
88E679462C7503C1007E69D5 /* PaywallStackComponent.swift */,
Expand All @@ -5474,6 +5518,7 @@
88AD01352C74196600AA1F2B /* V2 */ = {
isa = PBXGroup;
children = (
03E133D92E5343390028D9FD /* ViewRegistry.swift */,
88B1BAE32C813A3C001B7EE5 /* PaywallsV2View.swift */,
2C7457492CEA6B06004ACE52 /* EnvironmentObjects */,
030F91882D55C0FF0085103F /* Localizations */,
Expand Down Expand Up @@ -6557,6 +6602,7 @@
FD3A85FC2DDE7532005F3C79 /* VirtualCurrencies.swift in Sources */,
4F6BEDE22A26B69500CD9322 /* DebugContentViews.swift in Sources */,
B3B5FBBC269D121B00104A0C /* Offerings.swift in Sources */,
03E1325D2E5007F70028D9FD /* PaywallSlotComponent.swift in Sources */,
9A65E03B25918B0900DE00B0 /* CustomerInfoStrings.swift in Sources */,
5721360F28B4602C006C46BE /* Purchases+nonasync.swift in Sources */,
57DE806D28074976008D6C6F /* Storefront.swift in Sources */,
Expand Down Expand Up @@ -6758,6 +6804,7 @@
F5BE424226965F9F00254A30 /* ProductRequestData+Initialization.swift in Sources */,
2DDF41AD24F6F37C005BC22D /* ASN1ObjectIdentifier.swift in Sources */,
75B6DFFB2E30EC86009F0A99 /* GetWebOfferingProductsOperation.swift in Sources */,
03E132D92E510B7B0028D9FD /* PaywallSlotLottieComponent.swift in Sources */,
35549323269E298B005F9AE9 /* OfferingsFactory.swift in Sources */,
57536A28278522B400E2AE7F /* SK2StoreTransaction.swift in Sources */,
2D9C7BB326D838FC006838BE /* UIApplication+RCExtensions.swift in Sources */,
Expand Down Expand Up @@ -7390,6 +7437,7 @@
778360792CCA85E4000785B8 /* StickyFooterComponentViewModel.swift in Sources */,
2C7457482CEA66AB004ACE52 /* ComponentsView.swift in Sources */,
03C06FCA2D479C7400600693 /* CarouselComponentView.swift in Sources */,
03E132602E500A570028D9FD /* SlotComponentView.swift in Sources */,
353FDC0F2CA446FA0055F328 /* StoreProductDiscount+Extensions.swift in Sources */,
03A98CF12D222F5F009BCA61 /* FallbackComponentPreview.swift in Sources */,
887A60862C1D037000E1A461 /* FooterHidingModifier.swift in Sources */,
Expand Down Expand Up @@ -7430,6 +7478,7 @@
FD9BCEBC2DC946C400408A5D /* BottomSheetView.swift in Sources */,
03F0B6512DD5700D00E82199 /* LocalizationDictionaryExtensions.swift in Sources */,
7783607B2CCA88E4000785B8 /* StickyFooterComponentView.swift in Sources */,
03E132622E500A600028D9FD /* SlotComponentViewModel.swift in Sources */,
FD15AF5B2DF9A8F30062467E /* VirtualCurrencyBalanceListRow.swift in Sources */,
FD15AF5C2DF9A8F30062467E /* VirtualCurrencyBalancesScreen.swift in Sources */,
FD15AF5D2DF9A8F30062467E /* VirtualCurrenciesScrollViewWithOSBackgroundSection.swift in Sources */,
Expand Down Expand Up @@ -7539,6 +7588,7 @@
5798C96F2DF1985700F44400 /* PurchaseDetailView.swift in Sources */,
5798C9702DF1985700F44400 /* SubscriptionDetailViewModel.swift in Sources */,
5798C9712DF1985700F44400 /* PurchaseInformation+History.swift in Sources */,
03E133DA2E5343390028D9FD /* ViewRegistry.swift in Sources */,
5798C9722DF1985700F44400 /* DiscountsHandler.swift in Sources */,
75D7048B2DFC33A900F02803 /* Purchases+RevenueCatUI.swift in Sources */,
5798C9732DF1985700F44400 /* PurchaseHistoryViewModel.swift in Sources */,
Expand All @@ -7558,6 +7608,8 @@
887A60BF2C1D037000E1A461 /* PaywallViewController.swift in Sources */,
2CC791552CC0452100FBE120 /* PurchaseButtonComponentViewModel.swift in Sources */,
2CC791562CC0452100FBE120 /* PackageComponentView.swift in Sources */,
03E132E02E510C220028D9FD /* SlotLottieComponentView.swift in Sources */,
03E132E12E510C220028D9FD /* SlotLottieComponentViewModel.swift in Sources */,
2CC791592CC0452100FBE120 /* PurchaseButtonComponentView.swift in Sources */,
2CC7915A2CC0452100FBE120 /* PackageComponentViewModel.swift in Sources */,
887A60772C1D037000E1A461 /* TemplateViewConfiguration+Images.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions RevenueCatUI/Templates/V2/Components/ComponentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ struct ComponentsView: View {
TabControlToggleComponentView(viewModel: viewModel, onDismiss: onDismiss)
case .carousel(let viewModel):
CarouselComponentView(viewModel: viewModel, onDismiss: onDismiss)
case .slot(let viewModel):
SlotComponentView(viewModel: viewModel)
case .slotLottie(let viewModel):
SlotLottieComponentView(viewModel: viewModel)
}
}
// Applies a top padding to mimmic safe area insets
Expand Down
106 changes: 106 additions & 0 deletions RevenueCatUI/Templates/V2/Components/Slot/SlotComponentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// 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
//
// SlotComponentView.swift
//
// Created by Josh Holtz on 8/15/25.

import Foundation
import RevenueCat
import SwiftUI

#if !os(macOS) && !os(tvOS) // For Paywalls V2

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct SlotComponentView: View {

@EnvironmentObject
private var packageContext: PackageContext

@EnvironmentObject
private var introOfferEligibilityContext: IntroOfferEligibilityContext

@EnvironmentObject
private var paywallPromoOfferCache: PaywallPromoOfferCache

@Environment(\.componentViewState)
private var componentViewState

@Environment(\.screenCondition)
private var screenCondition

@EnvironmentObject
private var viewRegistry: ViewRegistry

let viewModel: SlotComponentViewModel

var body: some View {
self.viewModel.styles(
state: self.componentViewState,
condition: self.screenCondition,
isEligibleForIntroOffer: self.introOfferEligibilityContext.isEligible(
package: self.packageContext.package
),
isEligibleForPromoOffer: self.paywallPromoOfferCache.isMostLikelyEligible(
for: self.packageContext.package
)
) { style in
self.viewRegistry.makeView(identifier: viewModel.identifier)
// Style the carousel
.size(style.size)
.padding(style.padding)
.padding(style.margin)
}
}

}

#if DEBUG

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct SlotComponentView_Previews: PreviewProvider {

static let viewRegistry: ViewRegistry = {
let viewRegistry = ViewRegistry()
viewRegistry.register { identifier in
Text("Preview Slot \(identifier)")
}
viewRegistry.register(type: .slotLottie) { _ in
Text("Lottie goes here")
}
return viewRegistry
}()

// Need to wrap in VStack otherwise preview rerenders and images won't show
static var previews: some View {

// Default
VStack {
SlotComponentView(
// swiftlint:disable:next force_try
viewModel: try! .init(
localizationProvider: .init(
locale: Locale.current,
localizedStrings: [:]
),
component: .init(identifier: "test_slot_1")
)
)
}
.environmentObject(viewRegistry)
.previewRequiredPaywallsV2Properties()
.previewLayout(.fixed(width: 100, height: 100))
.previewDisplayName("Default")

}
}

#endif

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// 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
//
// SlotComponentViewModel.swift
//
// Created by Josh Holtz on 8/15/25.

import RevenueCat
import SwiftUI

#if !os(macOS) && !os(tvOS) // For Paywalls V2

typealias PresentedSlotPartial = PaywallComponent.PartialSlotComponent

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
class SlotComponentViewModel {

private let localizationProvider: LocalizationProvider
private let component: PaywallComponent.SlotComponent

private let presentedOverrides: PresentedOverrides<PresentedSlotPartial>?

init(
localizationProvider: LocalizationProvider,
component: PaywallComponent.SlotComponent
) throws {
self.localizationProvider = localizationProvider
self.component = component

self.presentedOverrides = try self.component.overrides?.toPresentedOverrides { $0 }
}

var identifier: String {
return component.identifier
}

@ViewBuilder
func styles(
state: ComponentViewState,
condition: ScreenCondition,
isEligibleForIntroOffer: Bool,
isEligibleForPromoOffer: Bool,
@ViewBuilder apply: @escaping (SlotComponentStyle) -> some View
) -> some View {
let partial = PresentedSlotPartial.buildPartial(
state: state,
condition: condition,
isEligibleForIntroOffer: isEligibleForIntroOffer,
isEligibleForPromoOffer: isEligibleForPromoOffer,
with: self.presentedOverrides
)

let style = SlotComponentStyle(
visible: partial?.visible ?? self.component.visible ?? true,
size: partial?.size ?? self.component.size,
padding: partial?.padding ?? self.component.padding,
margin: partial?.margin ?? self.component.margin
)

apply(style)
}

}

extension PresentedSlotPartial: PresentedPartial {

static func combine(
_ base: PaywallComponent.PartialSlotComponent?,
with other: PaywallComponent.PartialSlotComponent?
) -> Self {

let visible = other?.visible ?? base?.visible
let size = other?.size ?? base?.size
let padding = other?.padding ?? base?.padding
let margin = other?.margin ?? base?.margin

return .init(
visible: visible,
size: size,
padding: padding,
margin: margin
)
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct SlotComponentStyle {

let visible: Bool
let size: PaywallComponent.Size
let padding: EdgeInsets
let margin: EdgeInsets

init(
visible: Bool,
size: PaywallComponent.Size?,
padding: PaywallComponent.Padding?,
margin: PaywallComponent.Padding?
) {
self.visible = visible
self.size = size ?? .init(width: .fit, height: .fit)
self.padding = (padding ?? .zero).edgeInsets
self.margin = (margin ?? .zero).edgeInsets
}

}

#endif
Loading