From 8f332a724e4dfb1067a2f030b0283ae17bf7aa71 Mon Sep 17 00:00:00 2001 From: LiYanan2004 <37542129+LiYanan2004@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:35:40 +0800 Subject: [PATCH] Adds margins to InfoPannel for older OS --- Xcodes/Frontend/InfoPane/InfoPane.swift | 12 ++----- Xcodes/Frontend/View+ContentPadding.swift | 44 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 Xcodes/Frontend/View+ContentPadding.swift diff --git a/Xcodes/Frontend/InfoPane/InfoPane.swift b/Xcodes/Frontend/InfoPane/InfoPane.swift index 7afdea3c..77892393 100644 --- a/Xcodes/Frontend/InfoPane/InfoPane.swift +++ b/Xcodes/Frontend/InfoPane/InfoPane.swift @@ -8,17 +8,8 @@ import struct XCModel.SDKs struct InfoPane: View { let xcode: Xcode - var body: some View { - if #available(macOS 14.0, *) { - mainContent - .contentMargins(10, for: .scrollContent) - } else { - mainContent - .padding() - } - } - private var mainContent: some View { + var body: some View { ScrollView(.vertical) { HStack(alignment: .top) { VStack { @@ -55,6 +46,7 @@ struct InfoPane: View { } } + .contentPadding(10) } @ViewBuilder diff --git a/Xcodes/Frontend/View+ContentPadding.swift b/Xcodes/Frontend/View+ContentPadding.swift new file mode 100644 index 00000000..fa7f64d5 --- /dev/null +++ b/Xcodes/Frontend/View+ContentPadding.swift @@ -0,0 +1,44 @@ +import SwiftUI + +extension View { + @ViewBuilder + /// Adds an equal padding amount to specific edges of this view without clipping scrollable views. + /// - parameters: + /// - edges: Edges to add paddings + /// - length: The amount of padding to be added to edges. + /// - Returns: A view that’s padded by the specified amount on specified edges. + /// + /// This modifier uses safe area as paddings, making both non-scrollable and scrollable content looks great in any context. + public func contentPadding(_ edges: Edge.Set = .all, _ length: CGFloat? = nil) -> some View { + if #available(macOS 14.0, *) { + safeAreaPadding(edges, length) + } else { + safeAreaInset(edge: .top) { + EmptyView().frame(width: 0, height: 0) + .padding(.top, edges.contains(.top) ? length : 0) + } + .safeAreaInset(edge: .bottom) { + EmptyView().frame(width: 0, height: 0) + .padding(.bottom, edges.contains(.bottom) ? length : 0) + } + .safeAreaInset(edge: .leading) { + EmptyView().frame(width: 0, height: 0) + .padding(.leading, edges.contains(.leading) ? length : 0) + } + .safeAreaInset(edge: .trailing) { + EmptyView().frame(width: 0, height: 0) + .padding(.trailing, edges.contains(.trailing) ? length : 0) + } + } + } + + /// Adds an equal padding amount to all edges of this view without clipping scrollable views. + /// - parameters: + /// - length: The amount of padding to be added to edges. + /// - Returns: A view that’s padded by the specified amount on all edges. + /// + /// This modifier uses safe area as paddings, making both non-scrollable and scrollable content looks great in any context. + public func contentPadding(_ length: CGFloat) -> some View { + contentPadding(.all, length) + } +}