Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugRevenueCatOverlay: added ability to display new SubscriptionStoreView #2595

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 113 additions & 3 deletions Sources/Support/DebugUI/DebugContentViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#if DEBUG && os(iOS) && swift(>=5.8)

import StoreKit
import SwiftUI

@available(iOS 16.0, *)
Expand Down Expand Up @@ -166,9 +167,26 @@ private struct DebugSummaryView: View {
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
private struct DebugOfferingView: View {

@State private var showingSubscriptionSheet = false
@State private var showingStoreSheet = false
tonidero marked this conversation as resolved.
Show resolved Hide resolved

var offering: Offering

var body: some View {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
content
#if swift(>=5.9)
.onInAppPurchaseCompletion { _, _ in
self.showingSubscriptionSheet = false
self.showingStoreSheet = false
}
#endif
} else {
content
}
}

private var content: some View {
List {
Section("Data") {
LabeledContent("Identifier", value: self.offering.id)
Expand All @@ -182,10 +200,70 @@ private struct DebugOfferingView: View {
}
}
}

if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
Section("Paywalls") {
Button {
self.showingSubscriptionSheet = true
} label: {
Text("Display SubscriptionStoreView")
}

Button {
self.showingStoreSheet = true
} label: {
Text("Display StoreView")
}
}
}
}
.navigationTitle("Offering")
#if swift(>=5.9)
.sheet(isPresented: self.$showingSubscriptionSheet) {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
self.subscriptionStoreView
}
}
.navigationTitle("Offering")
.sheet(isPresented: self.$showingStoreSheet) {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
StoreView(offering: self.offering)
}
}
#endif
}

#if swift(>=5.9)
@available(iOS 17.0, macOS 14.0, tvOS 17.0, *)
private var subscriptionStoreView: some View {
SubscriptionStoreView(offering: self.offering) {
VStack {
VStack {
Text("🐈")
Text("RevenueCat Demo Paywall")
}
.font(.title)

Text(self.offering.getMetadataValue(for: "title", default: "Premium Access"))
.font(.title2)
.foregroundStyle(.primary)

Text(self.offering.getMetadataValue(for: "subtitle",
default: "Unlimited access to premium content."))
Comment on lines +246 to +251
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

.foregroundStyle(.secondary)
.font(.subheadline)
}
.containerBackground(for: .subscriptionStoreFullHeight) {
Rectangle()
.edgesIgnoringSafeArea(.all)
.foregroundStyle(Color.blue.gradient.quaternary)
}
}
.backgroundStyle(.clear)
.subscriptionStoreButtonLabel(.multiline)
.subscriptionStorePickerItemBackground(.thickMaterial)
}
#endif

}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
Expand Down Expand Up @@ -226,10 +304,17 @@ private struct DebugPackageView: View {
self.purchasing = false
}
} label: {
Text("Purchase")
Text("Purchase with RevenueCat")
}

#if swift(>=5.9)
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
ProductView(id: self.package.storeProduct.productIdentifier)
.productViewStyle(ProductStyle())
}
.disabled(self.purchasing)
#endif
}
.disabled(self.purchasing)
}
.navigationTitle("Package")
.alert(
Expand Down Expand Up @@ -261,4 +346,29 @@ extension DebugViewModel.Configuration: Transferable {

}

#if swift(>=5.9)
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
private struct ProductStyle: ProductViewStyle {

func makeBody(configuration: ProductViewStyleConfiguration) -> some View {
switch configuration.state {
case .loading:
ProgressView()
.progressViewStyle(.circular)

case .success:
Button {
configuration.purchase()
} label: {
Text("Purchase with StoreKit")
}

default:
ProductView(configuration)
}
}

}
#endif

#endif