Skip to content

Commit

Permalink
Add default instets in surface
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Jun 16, 2023
1 parent 72303eb commit de6932b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
18 changes: 9 additions & 9 deletions Sources/OversizeUI/Controls/SectionView/SectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public struct SectionView<Content: View>: View {
}
.padding(.horizontal, surfaceHorizontalPadding)
}
// .padding(.vertical, surfaceVerticalPaddingSize)
.padding(.vertical, surfaceVerticalPaddingSize)
}

private var titleView: some View {
Expand Down Expand Up @@ -190,14 +190,14 @@ public struct SectionView<Content: View>: 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 {
Expand Down
10 changes: 10 additions & 0 deletions Sources/OversizeUI/Controls/Surface/Surface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ public extension Surface where Label == Row<EmptyView, EmptyView> {
}
}

public extension Surface where Label == Row<Image, EmptyView> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
41 changes: 40 additions & 1 deletion Sources/OversizeUI/Extensions/View/View+Available.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +24,7 @@ public extension View {
self
}
}

@_disfavoredOverload
@ViewBuilder
func presentationDragIndicator(_ visibility: Visibility) -> some View {
Expand All @@ -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
}
}
}

0 comments on commit de6932b

Please sign in to comment.