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

Paywalls: new PaywallViewControllerDelegate.paywallViewController(_:didChangeSizeTo:) #3563

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 10 additions & 7 deletions RevenueCatUI/UIKit/PaywallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public class PaywallViewController: UIViewController {
guard let self = self else { return }
self.delegate?.paywallViewController?(self, didFinishRestoringWith: customerInfo)
}
.onSizeChange { [weak self] in
guard let self = self else { return }
self.delegate?.paywallViewController?(self, didChangeSizeTo: $0)
}

return .init(rootView: view)
}()
Expand All @@ -85,18 +89,12 @@ public class PaywallViewController: UIViewController {
self.hostingController.view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
self.hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
self.hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
self.hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
self.hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])

// for footers we only want to tie to the sides and the bottom.
if self.mode == .fullScreen {
NSLayoutConstraint.activate([
self.hostingController.view.topAnchor.constraint(equalTo: view.topAnchor)
])
}

// make the background of the container clear so that if there are cutouts, they don't get
// overridden by the hostingController's view's background.
self.hostingController.view.backgroundColor = .clear
Expand Down Expand Up @@ -139,6 +137,11 @@ public protocol PaywallViewControllerDelegate: AnyObject {
@objc(paywallViewControllerWasDismissed:)
optional func paywallViewControllerWasDismissed(_ controller: PaywallViewController)

/// For internal use only.
@objc(paywallViewControlle:didChangeSizeTo:)
optional func paywallViewController(_ controller: PaywallViewController,
didChangeSizeTo size: CGSize)

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ final class Delegate: PaywallViewControllerDelegate {

func paywallViewControllerWasDismissed(_ controller: PaywallViewController) {}

func paywallViewController(_ controller: PaywallViewController,
didChangeSizeTo size: CGSize) {}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
Expand Down