Skip to content

Commit

Permalink
debugRevenueCatOverlay: added ability to display new `SubscriptionS…
Browse files Browse the repository at this point in the history
…toreView` (#2595)

See #2593

![Simulator Screenshot - iPhone 14 Pro Max - 2023-06-07 at 13 07
58](https://github.com/RevenueCat/purchases-ios/assets/685609/551dd3e0-80f8-4b68-b79f-abcf078fb56f)
  • Loading branch information
NachoSoto authored Jun 9, 2023
1 parent 3032007 commit 5186595
Showing 1 changed file with 113 additions and 3 deletions.
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

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."))
.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

0 comments on commit 5186595

Please sign in to comment.