Skip to content

Commit

Permalink
Added preview device. Added layout margins padding.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Jan 5, 2024
1 parent 689135b commit 065d27e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/SwiftUIExtension/Extensions/PreviewDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import SwiftUI

extension PreviewDevice {

public static var visionPro: PreviewDevice {
PreviewDevice(rawValue: "Apple Vision Pro")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import SwiftUI

extension View {

public func horizontalSystemPadding() -> some View {
modifier(HorizontalSystemPadding())
}
}

struct HorizontalSystemPadding: ViewModifier {

var value: CGFloat {
switch horizontalSizeClass {
case .compact:
return 16
case .regular:
#if os(visionOS)
return 24
#else
return 20
#endif
default:
return 16
}
}

//var withCompensation: Bool = false

@Environment(\.horizontalSizeClass) var horizontalSizeClass

public func body(content: Content) -> some View {
/*let compensation: CGFloat = {
#if os(visionOS)
return -14
#else
return .zero
#endif
}()*/
if #available(iOS 17.0, macOS 14.0, *) {
content
.contentMargins(.horizontal, value, for: .scrollContent)
} else {
content
}
}
}

0 comments on commit 065d27e

Please sign in to comment.