Skip to content

Commit

Permalink
Paywalls: move size configuration to TemplateViewType (#3352)
Browse files Browse the repository at this point in the history
This simplifies the implementation in `PaywallView` and reuses this code
so `PreviewableTemplate` can use it too.
  • Loading branch information
NachoSoto authored Oct 26, 2023
1 parent 7f5512b commit 0fc9f30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 1 addition & 11 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct LoadedOfferingPaywallView: View {
}

var body: some View {
let view = self.paywall
self.paywall
.createView(for: self.offering,
activelySubscribedProductIdentifiers: self.activelySubscribedProductIdentifiers,
template: self.template,
Expand All @@ -271,16 +271,6 @@ struct LoadedOfferingPaywallView: View {
.disabled(self.purchaseHandler.actionInProgress)
.onAppear { self.purchaseHandler.trackPaywallImpression(self.createEventData()) }
.onDisappear { self.purchaseHandler.trackPaywallClose() }

switch self.mode {
case .fullScreen:
view

case .footer, .condensedFooter:
view
.fixedSize(horizontal: false, vertical: true)
.edgesIgnoringSafeArea(.bottom)
}
}

private func createEventData() -> PaywallEvent.Data {
Expand Down
14 changes: 14 additions & 0 deletions RevenueCatUI/Templates/TemplateViewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ extension View {
self
.background(configuration.backgroundView)
.adjustColorScheme(with: configuration)
.adjustSize(with: configuration.mode)
}

@ViewBuilder
Expand All @@ -167,6 +168,19 @@ extension View {
}
}

@ViewBuilder
private func adjustSize(with mode: PaywallViewMode) -> some View {
switch mode {
case .fullScreen:
self

case .footer, .condensedFooter:
self
.fixedSize(horizontal: false, vertical: true)
.edgesIgnoringSafeArea(.bottom)
}
}

}

// MARK: - Private
Expand Down

0 comments on commit 0fc9f30

Please sign in to comment.