Skip to content

Commit 065d27e

Browse files
committed
Added preview device. Added layout margins padding.
1 parent 689135b commit 065d27e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import SwiftUI
2+
3+
extension PreviewDevice {
4+
5+
public static var visionPro: PreviewDevice {
6+
PreviewDevice(rawValue: "Apple Vision Pro")
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import SwiftUI
2+
3+
extension View {
4+
5+
public func horizontalSystemPadding() -> some View {
6+
modifier(HorizontalSystemPadding())
7+
}
8+
}
9+
10+
struct HorizontalSystemPadding: ViewModifier {
11+
12+
var value: CGFloat {
13+
switch horizontalSizeClass {
14+
case .compact:
15+
return 16
16+
case .regular:
17+
#if os(visionOS)
18+
return 24
19+
#else
20+
return 20
21+
#endif
22+
default:
23+
return 16
24+
}
25+
}
26+
27+
//var withCompensation: Bool = false
28+
29+
@Environment(\.horizontalSizeClass) var horizontalSizeClass
30+
31+
public func body(content: Content) -> some View {
32+
/*let compensation: CGFloat = {
33+
#if os(visionOS)
34+
return -14
35+
#else
36+
return .zero
37+
#endif
38+
}()*/
39+
if #available(iOS 17.0, macOS 14.0, *) {
40+
content
41+
.contentMargins(.horizontal, value, for: .scrollContent)
42+
} else {
43+
content
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)