Skip to content

Commit

Permalink
fixing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmaccallum committed Nov 20, 2024
1 parent 3383bb2 commit f17185d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Mick MacCallum on 11/12/24.
//

import StoreKit
import SwiftUI

public final class ParraPaywallConfig: ParraContainerConfig {
Expand All @@ -13,10 +14,12 @@ public final class ParraPaywallConfig: ParraContainerConfig {
public init(
defaultTitle: String = "Premium Membership",
defaultSubtitle: String =
"Start a subscription to our premium membership to access this premium content."
"Start a subscription to our premium membership to access this premium content.",
visibleRelationships: Product.SubscriptionRelationship = .all
) {
self.defaultTitle = defaultTitle
self.defaultSubtitle = defaultSubtitle
self.visibleRelationships = visibleRelationships
}

// MARK: - Public
Expand All @@ -25,4 +28,10 @@ public final class ParraPaywallConfig: ParraContainerConfig {

public let defaultTitle: String
public let defaultSubtitle: String

/// The kinds of subscription option relationships the view makes visible
/// when someone is already subscribed to the subscription. This option is
/// only relevant when your paywall is configured in the Parra dashboard
/// to use a subscription Group ID and not a list of products.
public let visibleRelationships: Product.SubscriptionRelationship
}
68 changes: 42 additions & 26 deletions ios/Sources/Parra/Containers/Widgets/Paywall/PaywallWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,48 @@ struct PaywallWidget: ParraContainer {

@Environment(\.parraComponentFactory) private var componentFactory

@ViewBuilder private var marketingContent: some View {
@ViewBuilder
@MainActor private var subscriptionStoreView: some View {
// capture before passing to Apple's subscription store view to avoid
// rendering crash.
let marketing = marketingContent()

if ParraAppEnvironment.isDebugParraDevApp {
// Hard-coded to match the group id in the Configuration.storekit file.
SubscriptionStoreView(groupID: "4EEAFE70") {
marketing
}
} else {
switch contentObserver.initialParams.paywallProducts {
case .groupId(let groupId):
SubscriptionStoreView(
groupID: groupId,
visibleRelationships: config.visibleRelationships,
marketingContent: {
marketing
}
)
case .productIds(let productIds):
SubscriptionStoreView(
productIDs: productIds,
marketingContent: {
marketing
}
)
case .products(let products):
SubscriptionStoreView(
subscriptions: products,
marketingContent: {
marketing
}
)
}
}
}

@ViewBuilder
@MainActor
private func marketingContent() -> some View {
VStack(alignment: .center) {
withContent(content: contentObserver.content.image) { content in
componentFactory.buildAsyncImage(
Expand All @@ -78,31 +119,6 @@ struct PaywallWidget: ParraContainer {
}
.padding(.top, 34)
}

@ViewBuilder
@MainActor private var subscriptionStoreView: some View {
if ParraAppEnvironment.isDebugParraDevApp {
// Hard-coded to match the group id in the Configuration.storekit file.
SubscriptionStoreView(groupID: "4EEAFE70") {
marketingContent
}
} else {
switch contentObserver.initialParams.paywallProducts {
case .groupId(let groupId):
SubscriptionStoreView(
groupID: groupId
)
case .productIds(let productIds):
SubscriptionStoreView(
productIDs: productIds
)
case .products(let products):
SubscriptionStoreView(
subscriptions: products
)
}
}
}
}

private extension View {
Expand Down

0 comments on commit f17185d

Please sign in to comment.