Skip to content

Commit 4c85f28

Browse files
committed
Lower LayoutInspector deployment target
To make it possible to use the library in an app with a lower deployment target than iOS 16/macOS 13. All APIs are availability-gated, though, so you can only use LayoutInspector APIs in views that are @available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) or higher.
1 parent 72a7192 commit 4c85f28

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Package.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import PackageDescription
44

55
let package = Package(
66
name: "LayoutInspector",
7-
platforms: [.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9)],
7+
// LayoutInspector requires iOS 16/macOS 13. We specify a lower deployment
8+
// target here to allow integrating the library into an app with a lower
9+
// deployment target. The entire LayoutInspector API is availability-gated
10+
// to iOS 16/macOS 13, though, so you can only use it in views that are
11+
// `@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)` or higher.
12+
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
813
products: [
914
.library(name: "LayoutInspector", targets: ["LayoutInspector"]),
1015
],

Sources/LayoutInspector/DebugLayout.swift

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import SwiftUI
55

6+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
67
extension View {
78
/// Start debugging the layout algorithm for this subtree.
89
///
@@ -31,6 +32,7 @@ extension View {
3132
}
3233

3334
/// A custom layout that adds the layout proposals and responses for a view to a log for display.
35+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
3436
struct DebugLayout: Layout {
3537
var label: String
3638

@@ -49,6 +51,7 @@ struct DebugLayout: Layout {
4951

5052
/// Draws a highlight (dashed border) around the view that's selected
5153
/// in the DebugLayout log table.
54+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
5255
fileprivate struct DebugLayoutSelectionHighlight: ViewModifier {
5356
var viewID: String
5457
@Environment(\.debugLayoutSelectedViewID) private var selection: String?
@@ -66,25 +69,29 @@ fileprivate struct DebugLayoutSelectionHighlight: ViewModifier {
6669
}
6770
}
6871

72+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
6973
extension CGFloat {
7074
var pretty: String {
7175
String(format: "%.1f", self)
7276
}
7377
}
7478

79+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
7580
extension CGSize {
7681
var pretty: String {
7782
let thinSpace: Character = "\u{2009}"
7883
return "\(width.pretty)\(thinSpace)×\(thinSpace)\(height.pretty)"
7984
}
8085
}
8186

87+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
8288
extension Optional where Wrapped == CGFloat {
8389
var pretty: String {
8490
self?.pretty ?? "nil"
8591
}
8692
}
8793

94+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
8895
extension ProposedViewSize {
8996
var pretty: String {
9097
let thinSpace: Character = "\u{2009}"

Sources/LayoutInspector/DebugLayoutLog.swift

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SwiftUI
22

3+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
34
func logLayoutStep(_ label: String, step: LogEntry.Step) {
45
DispatchQueue.main.async {
56
guard let prevEntry = LogStore.shared.log.last else {
@@ -40,6 +41,7 @@ func logLayoutStep(_ label: String, step: LogEntry.Step) {
4041

4142
/// A custom layout that clears the DebugLayout log
4243
/// at the point where it's placed in the view tree.
44+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
4345
struct ClearDebugLayoutLog: Layout {
4446
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
4547
assert(subviews.count == 1)
@@ -56,6 +58,7 @@ struct ClearDebugLayoutLog: Layout {
5658
}
5759
}
5860

61+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
5962
public final class LogStore: ObservableObject {
6063
public static let shared: LogStore = .init()
6164

@@ -73,6 +76,7 @@ public final class LogStore: ObservableObject {
7376
}
7477
}
7578

79+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
7680
struct LogEntry: Identifiable {
7781
enum Step {
7882
case proposal(ProposedViewSize)
@@ -102,17 +106,20 @@ struct LogEntry: Identifiable {
102106
}
103107
}
104108

109+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
105110
struct DebugLayoutSelectedViewID: EnvironmentKey {
106111
static var defaultValue: String? { nil }
107112
}
108113

114+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
109115
extension EnvironmentValues {
110116
var debugLayoutSelectedViewID: String? {
111117
get { self[DebugLayoutSelectedViewID.self] }
112118
set { self[DebugLayoutSelectedViewID.self] = newValue }
113119
}
114120
}
115121

122+
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
116123
public struct DebugLayoutLogView: View {
117124
@Binding var selection: String?
118125
@ObservedObject var logStore: LogStore

0 commit comments

Comments
 (0)