Skip to content

Commit

Permalink
Paywall Tester: fixed paywall presentation (#3339)
Browse files Browse the repository at this point in the history
Having the `.sheet` deep inside a `List` + `Section` + `if` was making
`SwiftUI` re-evaluate it over and over.
This cleans up `PaywallPresenter` and moves it to the top level of the
view to avoid that.
  • Loading branch information
NachoSoto authored Oct 24, 2023
1 parent 32dc5ed commit 50bd457
Showing 1 changed file with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ struct OfferingsList: View {
.contextMenu {
self.contextMenu(for: offering)
}
.sheet(item: self.$selectedOffering) { offering in
PaywallPresenter(selectedMode: self.$selectedMode,
selectedOffering: self.$selectedOffering)
}
#endif
} else {
Text(offering.serverDescription)
Expand All @@ -122,6 +118,9 @@ struct OfferingsList: View {
}
}
}
.sheet(item: self.$selectedOffering) { offering in
PaywallPresenter(offering: offering, mode: self.selectedMode)
}
}

@ViewBuilder
Expand Down Expand Up @@ -166,29 +165,26 @@ struct OfferingsList: View {

private struct PaywallPresenter: View {

@Binding var selectedMode: PaywallViewMode
@Binding var selectedOffering: Offering?
var offering: Offering
var mode: PaywallViewMode

var body: some View {
Group {
if let offering = self.selectedOffering {
switch self.selectedMode {
case .fullScreen:
PaywallView(offering: offering)

case .footer:
VStack {
Spacer()
Text("This Paywall is being presented as a Footer")
.paywallFooter(offering: offering)
}
case .condensedFooter:
VStack {
Spacer()
Text("This Paywall is being presented as a Condensed Footer")
.paywallFooter(offering: offering, condensed: true)
}
}
switch self.mode {
case .fullScreen:
PaywallView(offering: self.offering)

case .footer:
VStack {
Spacer()
Text("This Paywall is being presented as a Footer")
.paywallFooter(offering: self.offering)
}

case .condensedFooter:
VStack {
Spacer()
Text("This Paywall is being presented as a Condensed Footer")
.paywallFooter(offering: self.offering, condensed: true)
}
}
}
Expand Down

0 comments on commit 50bd457

Please sign in to comment.