-
Notifications
You must be signed in to change notification settings - Fork 316
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
New DebugViewController
: UIKit counterpart for SwiftUI's debugRevenueCatOverlay
#2631
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4fcecfb
New `DebugViewController`: UIKit counterpart for SwiftUI's `debugReve…
NachoSoto 8f972f2
Fixed import and docs
NachoSoto 72e9859
Fixed API testers
NachoSoto 5c3a841
Added log
NachoSoto a8a0833
Fixed API Tester
NachoSoto 4b04dae
Fixed api testers
NachoSoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this brings back some memories
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.
I know I had to remind myself the proper order for this 😅