Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
28 changes: 28 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,11 @@
7783606D2CCA7E14000785B8 /* PaywallStickyFooterComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7783606C2CCA7E14000785B8 /* PaywallStickyFooterComponent.swift */; };
778360792CCA85E4000785B8 /* StickyFooterComponentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 778360782CCA85E4000785B8 /* StickyFooterComponentViewModel.swift */; };
7783607B2CCA88E4000785B8 /* StickyFooterComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7783607A2CCA88E4000785B8 /* StickyFooterComponentView.swift */; };
E1C0A001BEEF0001CCDD0001 /* PaywallHeaderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1C0A006BEEF0001CCDD0001 /* PaywallHeaderComponent.swift */; };
E1C0A002BEEF0001CCDD0001 /* HeaderComponentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1C0A007BEEF0001CCDD0001 /* HeaderComponentViewModel.swift */; };
E1C0A003BEEF0001CCDD0001 /* HeaderComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1C0A008BEEF0001CCDD0001 /* HeaderComponentView.swift */; };
E1C0A004BEEF0001CCDD0001 /* HeaderComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1C0A009BEEF0001CCDD0001 /* HeaderComponentTests.swift */; };
E1C0A005BEEF0001CCDD0001 /* PaywallComponentsConfigHeaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1C0A00ABEEF0001CCDD0001 /* PaywallComponentsConfigHeaderTests.swift */; };
77AABEA32F02B3340018C1D3 /* CustomerCenterViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AABEA22F02B3340018C1D3 /* CustomerCenterViewControllerDelegate.swift */; };
77AABEB82F0C23450018C1D3 /* PurchasesStoreMessagesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AABEB72F0C23450018C1D3 /* PurchasesStoreMessagesTests.swift */; };
77BA1AB12CCBAB80009BF0EA /* RootViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77BA1AB02CCBAB80009BF0EA /* RootViewModel.swift */; };
Expand Down Expand Up @@ -2551,6 +2556,11 @@
7783606C2CCA7E14000785B8 /* PaywallStickyFooterComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallStickyFooterComponent.swift; sourceTree = "<group>"; };
778360782CCA85E4000785B8 /* StickyFooterComponentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickyFooterComponentViewModel.swift; sourceTree = "<group>"; };
7783607A2CCA88E4000785B8 /* StickyFooterComponentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickyFooterComponentView.swift; sourceTree = "<group>"; };
E1C0A006BEEF0001CCDD0001 /* PaywallHeaderComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallHeaderComponent.swift; sourceTree = "<group>"; };
E1C0A007BEEF0001CCDD0001 /* HeaderComponentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderComponentViewModel.swift; sourceTree = "<group>"; };
E1C0A008BEEF0001CCDD0001 /* HeaderComponentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderComponentView.swift; sourceTree = "<group>"; };
E1C0A009BEEF0001CCDD0001 /* HeaderComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderComponentTests.swift; sourceTree = "<group>"; };
E1C0A00ABEEF0001CCDD0001 /* PaywallComponentsConfigHeaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallComponentsConfigHeaderTests.swift; sourceTree = "<group>"; };
77AABEA22F02B3340018C1D3 /* CustomerCenterViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterViewControllerDelegate.swift; sourceTree = "<group>"; };
77AABEB72F0C23450018C1D3 /* PurchasesStoreMessagesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurchasesStoreMessagesTests.swift; sourceTree = "<group>"; };
77BA1AB02CCBAB80009BF0EA /* RootViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3281,6 +3291,7 @@
isa = PBXGroup;
children = (
0387D4AD2EC58AA5008E4A6B /* Countdown */,
E1C0A00BBEEF0001CCDD0001 /* Header */,
164681CD2E6B577600854AA5 /* Video */,
2C7457472CEA66AB004ACE52 /* ComponentsView.swift */,
7707A94A2CAD936A006E0313 /* Button */,
Expand Down Expand Up @@ -3353,6 +3364,7 @@
16DA8EC82E4EE24100283940 /* JsonLoader.swift */,
16DA8EC72E4EE22A00283940 /* Helpers */,
03F446222D2FE0B90046129A /* Properties */,
E1C0A009BEEF0001CCDD0001 /* HeaderComponentTests.swift */,
03F446202D2F73210046129A /* StackComponentTests.swift */,
03C7305A2D35985500297FEC /* TextComponentTests.swift */,
03A98CEE2D1EE040009BCA61 /* FallbackComponentTests.swift */,
Expand Down Expand Up @@ -4950,6 +4962,7 @@
574A2F3E282D75E300150D40 /* OfferingsDecodingTests.swift */,
03A98D312D2441B2009BCA61 /* PaywallDataDecodingTests.swift */,
75425E0E2D5DFA9F00E25F60 /* PaywallComponentsDataTests.swift */,
E1C0A00ABEEF0001CCDD0001 /* PaywallComponentsConfigHeaderTests.swift */,
03A98D352D244321009BCA61 /* UIConfigDecodingTests.swift */,
574A2F4E282D7B9E00150D40 /* PostOfferDecodingTests.swift */,
5766C61F282DA3D50067D886 /* GetIntroEligibilityDecodingTests.swift */,
Expand Down Expand Up @@ -5326,6 +5339,15 @@
path = Button;
sourceTree = "<group>";
};
E1C0A00BBEEF0001CCDD0001 /* Header */ = {
isa = PBXGroup;
children = (
E1C0A007BEEF0001CCDD0001 /* HeaderComponentViewModel.swift */,
E1C0A008BEEF0001CCDD0001 /* HeaderComponentView.swift */,
);
path = Header;
sourceTree = "<group>";
};
778360742CCA84FA000785B8 /* Root */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -5732,6 +5754,7 @@
03C730F22D35F13F00297FEC /* PaywallV2CacheWarming.swift */,
2CC791612CC0493600FBE120 /* Common */,
7707A94B2CAD93AC006E0313 /* PaywallButtonComponent.swift */,
E1C0A006BEEF0001CCDD0001 /* PaywallHeaderComponent.swift */,
88AD01032C740CF400AA1F2B /* PaywallImageComponent.swift */,
03C72FBD2D34949600297FEC /* PaywallIconComponent.swift */,
88E679462C7503C1007E69D5 /* PaywallStackComponent.swift */,
Expand Down Expand Up @@ -7238,6 +7261,7 @@
B35042C626CDD3B100905B95 /* PurchasesDelegate.swift in Sources */,
0313FD41268A506400168386 /* DateProvider.swift in Sources */,
2C8EC6E12CCD7BA700D6CCF8 /* ComponentOverrides.swift in Sources */,
E1C0A001BEEF0001CCDD0001 /* PaywallHeaderComponent.swift in Sources */,
7783606D2CCA7E14000785B8 /* PaywallStickyFooterComponent.swift in Sources */,
57FDAABA284937A0009A48F1 /* SandboxEnvironmentDetector.swift in Sources */,
353DE0072CCA506100A8F632 /* EventsRequest+Paywall.swift in Sources */,
Expand Down Expand Up @@ -7530,7 +7554,9 @@
351B51C126D450E800BD2BD7 /* OfferingsManagerTests.swift in Sources */,
5796A39927D6C1E000653165 /* BackendPostSubscriberAttributesTests.swift in Sources */,
35D8330A262FBA9A00E60AC5 /* MockUserDefaults.swift in Sources */,
E1C0A004BEEF0001CCDD0001 /* HeaderComponentTests.swift in Sources */,
75425E0F2D5DFA9F00E25F60 /* PaywallComponentsDataTests.swift in Sources */,
E1C0A005BEEF0001CCDD0001 /* PaywallComponentsConfigHeaderTests.swift in Sources */,
2DDF41DF24F6F527005BC22D /* MockProductsManager.swift in Sources */,
FD18BF492DF0D9C100140FD6 /* VirtualCurrencyManagerTests.swift in Sources */,
351B514F26D44ACE00BD2BD7 /* PurchasesSubscriberAttributesTests.swift in Sources */,
Expand Down Expand Up @@ -7832,6 +7858,8 @@
2C8EC6DD2CCC7C5B00D6CCF8 /* PackageValidator.swift in Sources */,
4DEB9BC52D08CA1700D33E36 /* BadgeModifier.swift in Sources */,
358DECA32D9BEF85003B1CC0 /* EmergeRenderingMode.swift in Sources */,
E1C0A002BEEF0001CCDD0001 /* HeaderComponentViewModel.swift in Sources */,
E1C0A003BEEF0001CCDD0001 /* HeaderComponentView.swift in Sources */,
778360792CCA85E4000785B8 /* StickyFooterComponentViewModel.swift in Sources */,
2C7457482CEA66AB004ACE52 /* ComponentsView.swift in Sources */,
03C06FCA2D479C7400600693 /* CarouselComponentView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// 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
//
// HeaderComponentView.swift
//
// Created by Facundo Menzella on 02/04/2026.

import SwiftUI

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

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

private let viewModel: HeaderComponentViewModel
private let onDismiss: () -> Void

init(
viewModel: HeaderComponentViewModel,
onDismiss: @escaping () -> Void
) {
self.viewModel = viewModel
self.onDismiss = onDismiss
}

var body: some View {
StackComponentView(
viewModel: self.viewModel.stackViewModel,
onDismiss: self.onDismiss
)
}

}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// 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
//
// HeaderComponentViewModel.swift
//
// Created by Facundo Menzella on 02/04/2026.

@_spi(Internal) import RevenueCat
import SwiftUI

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

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

let component: PaywallComponent.HeaderComponent
let stackViewModel: StackComponentViewModel

init(
component: PaywallComponent.HeaderComponent,
stackViewModel: StackComponentViewModel
) {
self.component = component
self.stackViewModel = stackViewModel
}

}

#endif
26 changes: 21 additions & 5 deletions RevenueCatUI/Templates/V2/Components/Root/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,27 @@ struct RootView: View {

var body: some View {
VStack(alignment: .center, spacing: 0) {
StackComponentView(
viewModel: viewModel.stackViewModel,
isScrollableByDefault: true,
onDismiss: onDismiss
)
ZStack(alignment: .top) {
StackComponentView(
viewModel: viewModel.stackViewModel,
isScrollableByDefault: true,
onDismiss: onDismiss,
additionalPadding: EdgeInsets(
top: 0,
leading: 0,
bottom: viewModel.stickyFooterViewModel == nil ? safeAreaInsets.bottom : 0,
trailing: 0
)
)

if let headerViewModel = viewModel.headerViewModel {
HeaderComponentView(
viewModel: headerViewModel,
onDismiss: onDismiss
)
.fixedSize(horizontal: false, vertical: true)
}
}

if let stickyFooterViewModel = viewModel.stickyFooterViewModel {
StackComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ class RootViewModel {
let parentZStack: PaywallComponent.StackComponent?
}

let headerViewModel: HeaderComponentViewModel?
let stackViewModel: StackComponentViewModel
let stickyFooterViewModel: StickyFooterComponentViewModel?
let firstItemIgnoresSafeAreaInfo: FirstItemShouldIgnoreSafeAreaInfo?
let localizationProvider: LocalizationProvider

init(
headerViewModel: HeaderComponentViewModel?,
stackViewModel: StackComponentViewModel,
stickyFooterViewModel: StickyFooterComponentViewModel?,
firstItemIgnoresSafeAreaInfo: FirstItemShouldIgnoreSafeAreaInfo?,
localizationProvider: LocalizationProvider
) {
self.headerViewModel = headerViewModel
self.stackViewModel = stackViewModel
self.stickyFooterViewModel = stickyFooterViewModel
self.firstItemIgnoresSafeAreaInfo = firstItemIgnoresSafeAreaInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,37 @@ struct ViewModelFactory {
) throws -> RootViewModel {
// Compute global flag: if ANY component has unsupported conditions, discard all rule overrides
self.discardRules = componentsConfig.stack.containsUnsupportedConditions() ||
componentsConfig.header?.stack.containsUnsupportedConditions() == true ||
componentsConfig.stickyFooter?.stack.containsUnsupportedConditions() == true

let firstItemIgnoresSafeAreaInfo = self.findFullWidthImageViewIfItsTheFirst(.stack(componentsConfig.stack))
let firstItemSafeAreaInfo = self.findFirstItemIgnoresSafeAreaInfo(in: componentsConfig)

let headerViewModel = try componentsConfig.header.flatMap {
let stackViewModel = try toStackViewModel(
component: $0.stack,
packageValidator: self.packageValidator,
firstItemIgnoresSafeAreaInfo: firstItemSafeAreaInfo.appliesToHeader
? firstItemSafeAreaInfo.info
: nil,
purchaseButtonCollector: nil,
localizationProvider: localizationProvider,
uiConfigProvider: uiConfigProvider,
offering: offering,
colorScheme: colorScheme
)

return HeaderComponentViewModel(
component: $0,
stackViewModel: stackViewModel
)
}

let rootStackViewModel = try toStackViewModel(
component: componentsConfig.stack,
packageValidator: self.packageValidator,
firstItemIgnoresSafeAreaInfo: firstItemIgnoresSafeAreaInfo,
firstItemIgnoresSafeAreaInfo: firstItemSafeAreaInfo.appliesToHeader
? nil
: firstItemSafeAreaInfo.info,
purchaseButtonCollector: nil,
localizationProvider: localizationProvider,
uiConfigProvider: uiConfigProvider,
Expand All @@ -77,9 +100,10 @@ struct ViewModelFactory {
}

return RootViewModel(
headerViewModel: headerViewModel,
stackViewModel: rootStackViewModel,
stickyFooterViewModel: stickyFooterViewModel,
firstItemIgnoresSafeAreaInfo: firstItemIgnoresSafeAreaInfo,
firstItemIgnoresSafeAreaInfo: firstItemSafeAreaInfo.info,
localizationProvider: localizationProvider
)
}
Expand Down Expand Up @@ -641,6 +665,26 @@ struct ViewModelFactory {
}
}

private func findFirstItemIgnoresSafeAreaInfo(
in componentsConfig: PaywallComponentsData.PaywallComponentsConfig
) -> (
info: RootViewModel.FirstItemShouldIgnoreSafeAreaInfo?,
appliesToHeader: Bool
) {
if let header = componentsConfig.header,
!header.stack.components.isEmpty {
return (
info: self.findFullWidthImageViewIfItsTheFirst(.stack(header.stack)),
appliesToHeader: true
)
}

return (
info: self.findFullWidthImageViewIfItsTheFirst(.stack(componentsConfig.stack)),
appliesToHeader: false
)
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Foundation
public struct PaywallComponentsConfig: Codable, Equatable, Sendable {

public var stack: PaywallComponent.StackComponent
@_spi(Internal) public let header: PaywallComponent.HeaderComponent?
public let stickyFooter: PaywallComponent.StickyFooterComponent?
public var background: PaywallComponent.Background

Expand All @@ -37,11 +38,24 @@ import Foundation
stickyFooter: PaywallComponent.StickyFooterComponent?,
background: PaywallComponent.Background
) {
self.header = nil
self.stack = stack
self.stickyFooter = stickyFooter
self.background = background
}

@_spi(Internal) public init(
stack: PaywallComponent.StackComponent,
header: PaywallComponent.HeaderComponent?,
stickyFooter: PaywallComponent.StickyFooterComponent?,
background: PaywallComponent.Background
) {
self.stack = stack
self.header = header
self.stickyFooter = stickyFooter
self.background = background
}

}

public enum LocalizationData: Codable, Equatable, Sendable {
Expand Down
Loading