Files
purchases-ios/Sources/Support/DebugUI/DebugView.swift
T
NachoSoto dab5035a19 visionOS: support for Xcode 15 beta 6 (#2989)
### Context:

`#if os(iOS)` no longer evaluates to `true` when compiling for
`visionOS`
Which means we need `|| os(xrOS)`.
But to support older Xcode we need `#if swift(>=5.9) && os(xrOS)`.
But, fun fact, short-circuiting doesn’t work in `Xcode 13`.
And we still need that to run iOS <15 tests (`FB12223404` /
`FB12805891`)

💩 

This works around that by defining our own `VISION_OS` flag.

### Changes:
- Added `VISION_OS` compile time flag to determine SDK
- Replaced `#if os(xrOS)` with `#if VISION_OS`
- Added flag to `Package.swift` (thanks @neonichu for helping with this)
2023-08-09 11:19:40 -07:00

86 lines
2.4 KiB
Swift

//
// 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
//
// DebugView.swift
//
// Created by Nacho Soto on 5/30/23.
#if DEBUG && swift(>=5.8) && (os(iOS) || os(macOS) || VISION_OS)
import SwiftUI
@available(iOS 16.0, macOS 13.0, *)
public extension View {
/// Adds a bottom sheet overlay to the current view which allows debugging the current SDK setup.
///
/// Usage:
/// ```swift
/// var body: some View {
/// YourViewContent()
/// .debugRevenueCatOverlay()
/// }
/// ```
///
/// - Note: This will present the overlay automatically on launch.
/// To manage the presentation manually, use `debugRevenueCatOverlay(isPresented:)`
func debugRevenueCatOverlay() -> some View {
return self.debugRevenueCatOverlay(isPresented: .constant(true))
}
/// Adds a bottom sheet overlay to the current view which allows debugging the current SDK setup.
///
/// Usage:
/// ```swift
/// @State private var debugOverlayVisible: Bool = false
///
/// var body: some View {
/// YourViewContent()
/// .debugRevenueCatOverlay(isPresented: self.debugOverlayVisible)
///
/// Button {
/// self.debugOverlayVisible.toggle()
/// } label: {
/// Text("RevenueCat Debug view")
/// }
/// }
/// ```
func debugRevenueCatOverlay(isPresented: Binding<Bool>) -> some View {
self.bottomSheet(
presentationDetents: self.detents,
isPresented: isPresented,
largestUndimmedIdentifier: .fraction(0.6),
cornerRadius: DebugSwiftUIRootView.cornerRadius,
content: {
DebugSwiftUIRootView()
#if os(macOS)
.frame(width: 500, height: 600)
#elseif VISION_OS
.frame(width: 600, height: 700)
#endif
}
)
}
private var detents: Set<PresentationDetent> {
#if VISION_OS
return [.large]
#else
return [
.fraction(0.2),
.fraction(0.6),
.large
]
#endif
}
}
#endif