-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added preview device. Added layout margins padding.
- Loading branch information
1 parent
689135b
commit 065d27e
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Sources/SwiftUIExtension/Extensions/ViewExtension+LayoutMargins.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |