Last active
June 2, 2024 10:52
-
-
Save kylebshr/6896bf23e73bdb48460ace1093795f86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// StandByMargins.swift | |
// | |
// Created by Kyle Bashour on 8/29/23. | |
// | |
import SwiftUI | |
extension View { | |
func standByMargins() -> some View { | |
modifier(StandByMargins()) | |
} | |
} | |
private struct StandByMargins: ViewModifier { | |
@Environment(\.widgetContentMargins) private var margins | |
private var isInStandby: Bool { | |
margins.leading > 0 && margins.leading < 5 | |
} | |
func body(content: Content) -> some View { | |
content.padding(isInStandby ? margins : EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have full-bleed content in StandBy, it currently gets clipped. Applying the margins again seems to perfectly fit the content within the rounded rect. This modifier should only apply the margins in StandBy - every other location has margins that are zero (iPhone / iPad Lock Screen) or greater than 5 (e.g., rectangular on watchOS is 7 pts).
Example:
.standByMargins()
.standByMargins()