-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
DebugViewController
: UIKit counterpart for SwiftUI's `debugReve…
…nueCatOverlay` (#2631) Built on top of `DebugSwiftUIRootView`. This can be presented either manually, or using `UIViewController.presentDebugRevenueCatOverlay`. This looks exactly the same as the `SwiftUI` version: ![image](https://github.com/RevenueCat/purchases-ios/assets/685609/2ef22db4-0030-457e-a721-8daf2dcc1a49)
- Loading branch information
Showing
9 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// 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 | ||
// | ||
// DebugViewController.swift | ||
// | ||
// Created by Nacho Soto on 6/12/23. | ||
|
||
import Foundation | ||
|
||
#if DEBUG && os(iOS) && swift(>=5.8) | ||
|
||
import SwiftUI | ||
import UIKit | ||
|
||
/// A view controller which allows debugging the current SDK setup. | ||
/// | ||
/// You can present this yourself, or use `UIViewController.presentDebugRevenueCatOverlay` | ||
/// for a default presentation using `UISheetPresentationController`. | ||
/// | ||
/// - Seealso: `View.debugRevenueCatOverlay` for `SwiftUI`. | ||
@available(iOS 16.0, *) | ||
@objc(RCDebugViewController) | ||
public final class DebugViewController: UIViewController { | ||
|
||
private lazy var hostingController: UIHostingController<DebugSwiftUIRootView> = { | ||
.init(rootView: .init()) | ||
}() | ||
|
||
// swiftlint:disable:next missing_docs | ||
public init() { | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
public override func loadView() { | ||
super.loadView() | ||
|
||
self.addChild(self.hostingController) | ||
self.view.addSubview(self.hostingController.view) | ||
self.hostingController.didMove(toParent: self) | ||
} | ||
|
||
public override func viewWillLayoutSubviews() { | ||
super.viewWillLayoutSubviews() | ||
|
||
self.hostingController.view.frame = self.view.bounds | ||
} | ||
|
||
} | ||
|
||
@available(iOS 16.0, *) | ||
extension UIViewController { | ||
|
||
/// Presents a bottom sheet overlay on top of the current view controller | ||
/// which allows debugging the current SDK setup. | ||
/// | ||
/// - Seealso: `DebugViewController`. | ||
/// - Seealso: `View.debugRevenueCatOverlay` for `SwiftUI`. | ||
@objc(rc_presentDebugRevenueCatOverlayAnimated:) | ||
public func presentDebugRevenueCatOverlay(animated: Bool = true) { | ||
let controller = DebugViewController() | ||
|
||
if let sheet = controller.sheetPresentationController { | ||
sheet.detents = [ | ||
.custom(resolver: { context in context.maximumDetentValue * 0.2 }), | ||
.medium(), | ||
.large() | ||
] | ||
sheet.largestUndimmedDetentIdentifier = .medium | ||
sheet.preferredCornerRadius = DebugSwiftUIRootView.cornerRadius | ||
sheet.prefersGrabberVisible = true | ||
} | ||
|
||
self.present(controller, animated: animated) | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// RCOtherAPI.h | ||
// ObjCAPITester | ||
// | ||
// Created by Nacho Soto on 6/12/23. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RCOtherAPI : NSObject | ||
|
||
+ (void)checkAPI; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// RCOtherAPI.m | ||
// ObjCAPITester | ||
// | ||
// Created by Nacho Soto on 6/12/23. | ||
// | ||
|
||
@import RevenueCat; | ||
@import UIKit; | ||
|
||
#import "RCOtherAPI.h" | ||
|
||
@implementation RCOtherAPI | ||
|
||
+ (void)checkAPI { | ||
#if DEBUG && TARGET_OS_IPHONE && defined(__IPHONE_17_0) | ||
if (@available(iOS 16.0, *)) { | ||
RCDebugViewController *controller __unused = [RCDebugViewController new]; | ||
|
||
[UIViewController.new rc_presentDebugRevenueCatOverlayAnimated:NO]; | ||
} | ||
#endif | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters