Skip to content

Commit

Permalink
Fix current offering and sticky footer (#4617)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdholtz authored Dec 20, 2024
1 parent 215b659 commit 774fc1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 57 deletions.
73 changes: 16 additions & 57 deletions RevenueCatUI/Templates/V2/Components/Root/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions Sources/Purchasing/Offerings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 774fc1f

Please sign in to comment.