-
Notifications
You must be signed in to change notification settings - Fork 328
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
Expose Customer Center to UIKit #4560
Changes from 2 commits
bf4f1e8
fa9eef6
d1044e9
1464d9b
ae847fc
e8a2b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||
// | ||||||
// Copyright RevenueCat Inc. All Rights Reserved. | ||||||
// | ||||||
// Licensed under the MIT License (the "License"); | ||||||
// you may not use this file except in compliance with the License. | ||||||
// You may obtain a copy of the License at | ||||||
// | ||||||
// https://opensource.org/licenses/MIT | ||||||
// | ||||||
// CustomerCenterViewController.swift | ||||||
// | ||||||
// Created by Will Taylor on 12/6/24. | ||||||
|
||||||
import RevenueCat | ||||||
import SwiftUI | ||||||
|
||||||
#if canImport(UIKit) && os(iOS) | ||||||
|
||||||
/// Warning: This is currently in beta and subject to change. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 let's not even have this. We really shouldn't be changing the UI, and we're going GA very soon in any case. |
||||||
/// | ||||||
/// A SwiftUI view for displaying a customer support common tasks | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also that docstring's copy could generally be improved, "displaying a customer support common tasks" sounds broken. I realize that this is likely copy-pasted from SwiftUI, maybe we do a follow-up PR improving both sides |
||||||
@available(iOS 15.0, *) | ||||||
@available(macOS, unavailable) | ||||||
@available(tvOS, unavailable) | ||||||
@available(watchOS, unavailable) | ||||||
public class CustomerCenterViewController: UIHostingController<CustomerCenterView> { | ||||||
|
||||||
/// Create a view controller to handle common customer support tasks | ||||||
/// - Parameters: | ||||||
/// - customerCenterActionHandler: An optional `CustomerCenterActionHandler` to handle actions | ||||||
/// from the customer center. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like we should brand this and go always |
||||||
/// - mode: The presentation mode for the customer center. Defaults to `.default` | ||||||
public init( | ||||||
customerCenterActionHandler: CustomerCenterActionHandler? = nil, | ||||||
mode: CustomerCenterPresentationMode = .default | ||||||
) { | ||||||
let view = CustomerCenterView( | ||||||
customerCenterActionHandler: customerCenterActionHandler, | ||||||
mode: mode | ||||||
) | ||||||
super.init(rootView: view) | ||||||
} | ||||||
|
||||||
@available(*, unavailable, message: "Use init(customerCenterActionHandler:mode:) instead.") | ||||||
required dynamic init?(coder aDecoder: NSCoder) { | ||||||
fatalError("init(coder:) has not been implemented") | ||||||
fire-at-will marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
|
||||||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// CustomerCenterViewAPI.swift | ||
// AllAPITests | ||
// | ||
// Created by Will Taylor on 12/6/24. | ||
// | ||
|
||
import RevenueCat | ||
import RevenueCatUI | ||
|
||
|
||
#if canImport(UIKit) && os(iOS) | ||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) | ||
func checkCustomerCenterViewControllerAPI( | ||
customerCenterActionHandler: CustomerCenterActionHandler? = nil, | ||
mode: CustomerCenterPresentationMode = .default | ||
) { | ||
let _ = CustomerCenterViewController() | ||
let _ = CustomerCenterViewController(customerCenterActionHandler: customerCenterActionHandler) | ||
let _ = CustomerCenterViewController(mode: mode) | ||
let _ = CustomerCenterViewController( | ||
customerCenterActionHandler: customerCenterActionHandler, | ||
mode: mode | ||
) | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// CustomerCenterUIKitView.swift | ||
// PaywallsTester | ||
// | ||
// Created by Will Taylor on 12/6/24. | ||
// | ||
|
||
|
||
import SwiftUI | ||
import RevenueCat | ||
import RevenueCatUI | ||
|
||
/// Allows us to display the CustomerCenterViewController in a SwiftUI app | ||
struct CustomerCenterUIKitView: UIViewControllerRepresentable { | ||
|
||
let customerCenterActionHandler: (CustomerCenterAction) -> Void | ||
let presentationMode: CustomerCenterPresentationMode | ||
|
||
func makeUIViewController(context: Context) -> CustomerCenterViewController { | ||
CustomerCenterViewController( | ||
customerCenterActionHandler: self.customerCenterActionHandler, | ||
mode: self.presentationMode | ||
) | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: CustomerCenterViewController, context: Context) { | ||
// No updates needed | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️