RevenueCat / purchases-ios

In-app purchases and subscriptions made easy. Support for iOS, watchOS, tvOS, macOS, and visionOS.
https://www.revenuecat.com/
MIT License
2.22k stars 295 forks source link

`showManageSubscriptions` and `beginRefundRequest`: swiftUI view modifiers #1073

Open aboedo opened 2 years ago

aboedo commented 2 years ago

For SwiftUI apps, we should provide view modifiers to make it easy to use showManageSubscriptions and beginRefundRequest.

We can use #if canImport(SwiftUI) to only declare these when SwiftUI types are available.

For reference, here are the view modifiers declared by StoreKit.

// Available when SwiftUI is imported with StoreKit
@available(iOS 15.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension View {

    public func manageSubscriptionsSheet(isPresented: Binding<Bool>) -> some View

}

// Available when SwiftUI is imported with StoreKit
@available(iOS 15.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension View {

    public func refundRequestSheet(for transactionID: UInt64, isPresented: Binding<Bool>, onDismiss: ((Result<Transaction.RefundRequestStatus, Transaction.RefundRequestError>) -> ())? = nil) -> some View

}

https://app.shortcut.com/revenuecat/story/11882/showmanagesubscriptions-and-beginrefundrequest-swiftui-view-modifiers

Juanpe commented 2 years ago

Love it! I'd like to do it if it's still available :)

NachoSoto commented 2 years ago

I imagine we will grow SwiftUI extensions a lot over time. We might want to offer them separately eventually, or maybe now? There's something to be said about thin frameworks, and if a user doesn't need SwiftUI it doesn't make sense to include it for everyone IMO.

Juanpe commented 2 years ago

🤔 Good point.

My two cents. Maybe not now, but as you said, there could be another UI related framework to isolate the Core layer from the UI.

aboedo commented 2 years ago

Yeah, I think it'd be nice and easy to set up as a separate pod and swift package. It'd also allow us to provide other extensions for SwiftUI to make life a lot easier for devs

Zaprogramiacz commented 1 year ago

Hey 👋

I spotted the thread when I was looking here and there. It has the you can do this tag, so is it something that I can contribute to or the topic is on hold?

aboedo commented 1 year ago

Hey @Zaprogramiacz! 👋

You are absolutely welcome to contribute to this! We're more than happy to review and to assist with any questions you have along the way 💪

Zaprogramiacz commented 1 year ago

Oh great 💪🏻

Do you have any documentation, task with AC or desired dreamed solution? I don't have an access to the link from the first post and I bet that I might find there useful info.

In the thread I saw that last idea was to setup a separate pod and swift package with SwiftUI extensions. Is it still the main idea that should be followed?

aboedo commented 1 year ago

Hey, sorry for the late reply. Yeah, that's still the main idea, to have a separate SPM package and maybe also a pod, with just the SwiftUI extensions

suprie commented 4 weeks ago

I think this issue already resolved in https://github.com/RevenueCat/purchases-ios/blame/main/Sources/Support/ManageSubscriptionsHelper.swift#L34