From 774fc1f4d0f30b7825e7d2740fbd805d7a44e1be Mon Sep 17 00:00:00 2001 From: Josh Holtz Date: Fri, 20 Dec 2024 12:30:47 -0600 Subject: [PATCH] Fix current offering and sticky footer (#4617) --- .../V2/Components/Root/RootView.swift | 73 ++++--------------- Sources/Purchasing/Offerings.swift | 10 +++ 2 files changed, 26 insertions(+), 57 deletions(-) diff --git a/RevenueCatUI/Templates/V2/Components/Root/RootView.swift b/RevenueCatUI/Templates/V2/Components/Root/RootView.swift index c8e0a8cdd7..281b2b4cfe 100644 --- a/RevenueCatUI/Templates/V2/Components/Root/RootView.swift +++ b/RevenueCatUI/Templates/V2/Components/Root/RootView.swift @@ -30,68 +30,27 @@ struct RootView: View { } var body: some View { - ScrollView { - StackComponentView(viewModel: viewModel.stackViewModel, onDismiss: onDismiss) - }.applyIfLet(viewModel.stickyFooterViewModel) { stackView, stickyFooterViewModel in - stackView - // Using overlay because safeAreaInsert with fixedSize - .overlay( - StackComponentView( - viewModel: stickyFooterViewModel.stackViewModel, - onDismiss: onDismiss, - additionalPadding: EdgeInsets( - top: 0, - leading: 0, - bottom: additionalFooterPaddingBottom, - trailing: 0 - ) + VStack(alignment: .center, spacing: 0) { + ScrollView { + StackComponentView(viewModel: viewModel.stackViewModel, onDismiss: onDismiss) + } + + if let stickyFooterViewModel = viewModel.stickyFooterViewModel { + StackComponentView( + viewModel: stickyFooterViewModel.stackViewModel, + onDismiss: onDismiss, + additionalPadding: EdgeInsets( + top: 0, + leading: 0, + bottom: additionalFooterPaddingBottom, + trailing: 0 ) - .fixedSize(horizontal: false, vertical: true) - .edgesIgnoringSafeArea(.bottom), - alignment: .bottom ) - // First we ensure our footer draws in the bottom safe area. Then we add additional padding, so its - // background shows in that same bottom safe area. - .ignoresSafeArea(edges: .bottom) - .onBottomSafeAreaPaddingChange { bottomPadding in - self.additionalFooterPaddingBottom = bottomPadding - } - + .fixedSize(horizontal: false, vertical: true) + } } } } -@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) -private struct OnBottomSafeAreaPaddingChangeModifier: ViewModifier { - private let callback: (CGFloat) -> Void - - init(_ callback: @escaping (CGFloat) -> Void) { - self.callback = callback - } - - func body(content: Content) -> some View { - content - .background( - GeometryReader { geometry in - Color.clear - .onAppear { - callback(geometry.safeAreaInsets.bottom) - } - .onChange(of: geometry.safeAreaInsets.bottom) { newValue in - callback(newValue) - } - } - ) - } -} - -@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) -fileprivate extension View { - /// Sort-of backported safeAreaPadding (iOS 17+), for as much as we need. - func onBottomSafeAreaPaddingChange(_ callback: @escaping (CGFloat) -> Void) -> some View { - self.modifier(OnBottomSafeAreaPaddingChangeModifier(callback)) - } -} - #endif diff --git a/Sources/Purchasing/Offerings.swift b/Sources/Purchasing/Offerings.swift index ae86e3b814..c5ee377987 100644 --- a/Sources/Purchasing/Offerings.swift +++ b/Sources/Purchasing/Offerings.swift @@ -162,11 +162,21 @@ private extension Offering { ) } + #if PAYWALL_COMPONENTS return Offering(identifier: self.identifier, serverDescription: self.serverDescription, metadata: self.metadata, paywall: self.paywall, + paywallComponentsData: self.paywallComponentsData, availablePackages: updatedPackages ) + #else + return Offering(identifier: self.identifier, + serverDescription: self.serverDescription, + metadata: self.metadata, + paywall: self.paywall, + availablePackages: updatedPackages + ) + #endif } }