From de6932b10e4c5cc5f15ae2b90a64f365cf4e313a Mon Sep 17 00:00:00 2001 From: Alexander Romanov Date: Sat, 17 Jun 2023 00:25:28 +0300 Subject: [PATCH] Add default instets in surface --- .../Controls/SectionView/SectionView.swift | 18 ++++---- .../OversizeUI/Controls/Surface/Surface.swift | 10 +++++ .../SectionTitleInsetsEnvironment.swift | 5 +++ .../Extensions/View/View+Available.swift | 41 ++++++++++++++++++- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/Sources/OversizeUI/Controls/SectionView/SectionView.swift b/Sources/OversizeUI/Controls/SectionView/SectionView.swift index e141526..008ed42 100644 --- a/Sources/OversizeUI/Controls/SectionView/SectionView.swift +++ b/Sources/OversizeUI/Controls/SectionView/SectionView.swift @@ -73,7 +73,7 @@ public struct SectionView: View { } .padding(.horizontal, surfaceHorizontalPadding) } - // .padding(.vertical, surfaceVerticalPaddingSize) + .padding(.vertical, surfaceVerticalPaddingSize) } private var titleView: some View { @@ -190,14 +190,14 @@ public struct SectionView: View { } } -// private var surfaceVerticalPaddingSize: CGFloat { -// switch style { -// case .default: -// return Space.small.rawValue -// case .smallIndent, .edgeToEdge: -// return 2 -// } -// } + private var surfaceVerticalPaddingSize: CGFloat { + switch style { + case .default: + return Space.small.rawValue + case .smallIndent, .edgeToEdge: + return 2 + } + } } public extension SectionView { diff --git a/Sources/OversizeUI/Controls/Surface/Surface.swift b/Sources/OversizeUI/Controls/Surface/Surface.swift index 6babfa4..5f17f63 100644 --- a/Sources/OversizeUI/Controls/Surface/Surface.swift +++ b/Sources/OversizeUI/Controls/Surface/Surface.swift @@ -217,6 +217,16 @@ public extension Surface where Label == Row { } } +public extension Surface where Label == Row { + init(action: (() -> Void)? = nil, + @ViewBuilder label: () -> Label) + { + self.label = label() + self.action = action + forceContentInsets = .init(horizontal: .zero, vertical: .small) + } +} + struct Surface_Previews: PreviewProvider { static var previews: some View { VStack { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/SectionTitleInsetsEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/SectionTitleInsetsEnvironment.swift index 1cdc83f..1622c11 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/SectionTitleInsetsEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/SectionTitleInsetsEnvironment.swift @@ -25,4 +25,9 @@ public extension View { environment(\.sectionTitleInsets, .init(top: .zero, leading: .medium, bottom: .zero, trailing: .medium)) .environment(\.surfaceContentInsets, .init(top: .medium, leading: .zero, bottom: .medium, trailing: .zero)) } + + func sectionContentCompactRowInsets() -> some View { + environment(\.sectionTitleInsets, .init(top: .zero, leading: .medium, bottom: .zero, trailing: .medium)) + .environment(\.surfaceContentInsets, .init(top: .xxSmall, leading: .zero, bottom: .xxSmall, trailing: .zero)) + } } diff --git a/Sources/OversizeUI/Extensions/View/View+Available.swift b/Sources/OversizeUI/Extensions/View/View+Available.swift index 7aec189..abbacbe 100644 --- a/Sources/OversizeUI/Extensions/View/View+Available.swift +++ b/Sources/OversizeUI/Extensions/View/View+Available.swift @@ -5,6 +5,14 @@ import SwiftUI +public enum PresentationContentInteraction { + case automatic, resizes, scrolls +} + +public enum PresentationAdaptation { + case automatic, none, popover, sheet, fullScreenCover +} + public extension View { @available(tvOS, unavailable) @_disfavoredOverload @@ -16,7 +24,7 @@ public extension View { self } } - + @_disfavoredOverload @ViewBuilder func presentationDragIndicator(_ visibility: Visibility) -> some View { @@ -26,4 +34,35 @@ public extension View { self } } + + @_disfavoredOverload + @ViewBuilder + func presentationContentInteraction(_ behavior: PresentationContentInteraction) -> some View { + if #available(iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4, *) { + self.presentationContentInteraction(behavior == .automatic ? .automatic : behavior == .resizes ? .resizes : .scrolls) + } else { + self + } + } + + @_disfavoredOverload + @ViewBuilder + func presentationCompactAdaptation(_ adaptation: PresentationAdaptation) -> some View { + if #available(iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4, *) { + self.presentationCompactAdaptation( + adaptation == .automatic ? .automatic : adaptation == .none ? .none : adaptation == .popover ? .popover : adaptation == .sheet ? .sheet : .fullScreenCover) + } else { + self + } + } + + @_disfavoredOverload + @ViewBuilder + func scrollDisabled(_ disabled: Bool) -> some View { + if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) { + self.scrollDisabled(disabled) + } else { + self + } + } }