Skip to content

Commit

Permalink
Paywalls: added ability to preview templates in a .sheet (#2938)
Browse files Browse the repository at this point in the history
This is necessary to get the proper size / aspect-ratio when previewing
on iPad.
  • Loading branch information
NachoSoto committed Aug 28, 2023
1 parent d38a870 commit 0e18d7a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion RevenueCatUI/Helpers/PreviewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ struct PreviewableTemplate<T: TemplateViewType>: View {

typealias Creator = @Sendable @MainActor (TemplateViewConfiguration) -> T

private let creator: Creator
private let configuration: Result<TemplateViewConfiguration, Error>
private let presentInSheet: Bool
private let creator: Creator

@StateObject
private var introEligibilityViewModel = IntroEligibilityViewModel(
Expand All @@ -51,17 +52,32 @@ struct PreviewableTemplate<T: TemplateViewType>: View {

init(
offering: Offering,
presentInSheet: Bool = false,
creator: @escaping Creator
) {
self.configuration = offering.paywall!.configuration(
for: offering,
mode: .fullScreen,
locale: .current
)
self.presentInSheet = presentInSheet
self.creator = creator
}

var body: some View {
if self.presentInSheet {
Rectangle()
.hidden()
.sheet(isPresented: .constant(true)) {
self.content
}
} else {
self.content
}
}

@ViewBuilder
private var content: some View {
switch self.configuration {
case let .success(configuration):
self.creator(configuration)
Expand Down

0 comments on commit 0e18d7a

Please sign in to comment.