Skip to content
Merged
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
36 changes: 34 additions & 2 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 @@ -1353,6 +1358,7 @@
FA6ABC7C2A81673F00353AF7 /* SystemFontRegistryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6ABC7B2A81673F00353AF8 /* SystemFontRegistryTests.swift */; };
FACD00022F61A1230073D2DE /* TextComponentLocalizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACD00012F61A1230073D2DE /* TextComponentLocalizationTests.swift */; };
FACD00042F61A1230073D2DE /* ViewModelFactoryBadgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACD00032F61A1230073D2DE /* ViewModelFactoryBadgeTests.swift */; };
FB5A72022F65F5B9005C64A1 /* ViewModelFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB5A72012F65F5B9005C64A1 /* ViewModelFactoryTests.swift */; };
FACD00082F61A1230073D2DE /* PackageComponentViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACD00072F61A1230073D2DE /* PackageComponentViewTests.swift */; };
FACD000A2F61A1230073D2DE /* PackageValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACD00092F61A1230073D2DE /* PackageValidatorTests.swift */; };
FD05A71A2EE2430E00FE671F /* StoreKit2PromotionalOfferPurchaseOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD05A7192EE2430E00FE671F /* StoreKit2PromotionalOfferPurchaseOptions.swift */; };
Expand Down Expand Up @@ -2551,6 +2557,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 @@ -2884,6 +2895,7 @@
FA6ABC7B2A81673F00353AF8 /* SystemFontRegistryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemFontRegistryTests.swift; sourceTree = "<group>"; };
FACD00012F61A1230073D2DE /* TextComponentLocalizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextComponentLocalizationTests.swift; sourceTree = "<group>"; };
FACD00032F61A1230073D2DE /* ViewModelFactoryBadgeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelFactoryBadgeTests.swift; sourceTree = "<group>"; };
FB5A72012F65F5B9005C64A1 /* ViewModelFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelFactoryTests.swift; sourceTree = "<group>"; };
FACD00072F61A1230073D2DE /* PackageComponentViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageComponentViewTests.swift; sourceTree = "<group>"; };
FACD00092F61A1230073D2DE /* PackageValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageValidatorTests.swift; sourceTree = "<group>"; };
FD05A7192EE2430E00FE671F /* StoreKit2PromotionalOfferPurchaseOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2PromotionalOfferPurchaseOptions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3075,7 +3087,8 @@
children = (
FACD00012F61A1230073D2DE /* TextComponentLocalizationTests.swift */,
FACD00032F61A1230073D2DE /* ViewModelFactoryBadgeTests.swift */,
FACD00072F61A1230073D2DE /* PackageComponentViewTests.swift */,
FB5A72012F65F5B9005C64A1 /* ViewModelFactoryTests.swift */,
FACD00072F61A1230073D2DE /* PackageComponentViewTests.swift */,
FACD00092F61A1230073D2DE /* PackageValidatorTests.swift */,
FD4253DD2F1DBD7E0073D2DE /* FileImageLoaderTests.swift */,
57BFCD0F2EEB1234009E5844 /* TabsPackageSelectionResolverTests.swift */,
Expand Down Expand Up @@ -3281,6 +3294,7 @@
isa = PBXGroup;
children = (
0387D4AD2EC58AA5008E4A6B /* Countdown */,
E1C0A00BBEEF0001CCDD0001 /* Header */,
164681CD2E6B577600854AA5 /* Video */,
2C7457472CEA66AB004ACE52 /* ComponentsView.swift */,
7707A94A2CAD936A006E0313 /* Button */,
Expand Down Expand Up @@ -3353,6 +3367,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 +4965,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 +5342,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 +5757,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 +7264,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 +7557,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 +7861,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 Expand Up @@ -8113,7 +8144,8 @@
030890842D2B77E70069677B /* VariableHandlerV2Tests.swift in Sources */,
FACD00022F61A1230073D2DE /* TextComponentLocalizationTests.swift in Sources */,
FACD00042F61A1230073D2DE /* ViewModelFactoryBadgeTests.swift in Sources */,
FACD00082F61A1230073D2DE /* PackageComponentViewTests.swift in Sources */,
FB5A72022F65F5B9005C64A1 /* ViewModelFactoryTests.swift in Sources */,
FACD00082F61A1230073D2DE /* PackageComponentViewTests.swift in Sources */,
FACD000A2F61A1230073D2DE /* PackageValidatorTests.swift in Sources */,
DBD2432F2EBDF4BC0066AC6F /* PromotionalOfferViewTests.swift in Sources */,
577782B52D9182A200F97EB4 /* CustomerCenterActionWrapperTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// 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 {

@Environment(\.safeAreaInsets)
private var safeAreaInsets

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,
additionalPadding: .init(
top: self.viewModel.firstItemIgnoresSafeArea ? 0 : self.safeAreaInsets.top,
leading: 0,
bottom: 0,
trailing: 0
)
)
}

}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// 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
let firstItemIgnoresSafeArea: Bool

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

}

#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
5 changes: 4 additions & 1 deletion RevenueCatUI/Templates/V2/PaywallsV2View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ private struct LoadedPaywallsV2View: View {
// we will ignore safe area pass the safe area insets in to environment
// If the image is in a ZStack, the ZStack will push non-images
// down with the inset
.applyIf(paywallState.rootViewModel.firstItemIgnoresSafeAreaInfo != nil, apply: { view in
.applyIf(
paywallState.rootViewModel.headerViewModel != nil
|| paywallState.rootViewModel.firstItemIgnoresSafeAreaInfo != nil,
apply: { view in
view
.edgesIgnoringSafeArea(.top)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,41 @@ 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 headerFirstItemSafeAreaInfo: RootViewModel.FirstItemShouldIgnoreSafeAreaInfo?
if let header = componentsConfig.header,
!header.stack.components.isEmpty {
headerFirstItemSafeAreaInfo = self.findFullWidthImageViewIfItsTheFirst(.stack(header.stack))
} else {
headerFirstItemSafeAreaInfo = nil
}
let rootFirstItemSafeAreaInfo = self.findFullWidthImageViewIfItsTheFirst(.stack(componentsConfig.stack))

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

return HeaderComponentViewModel(
component: $0,
stackViewModel: stackViewModel,
firstItemIgnoresSafeArea: headerFirstItemSafeAreaInfo != nil
)
}

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

return RootViewModel(
headerViewModel: headerViewModel,
stackViewModel: rootStackViewModel,
stickyFooterViewModel: stickyFooterViewModel,
firstItemIgnoresSafeAreaInfo: firstItemIgnoresSafeAreaInfo,
firstItemIgnoresSafeAreaInfo: rootFirstItemSafeAreaInfo,
localizationProvider: localizationProvider
)
}
Expand Down
Loading