Skip to content

Instantly share code, notes, and snippets.

@mdb1
Created March 24, 2023 15:48
Show Gist options
  • Save mdb1/b0a08fb08b95d7086945c68dd574c5e0 to your computer and use it in GitHub Desktop.
Save mdb1/b0a08fb08b95d7086945c68dd574c5e0 to your computer and use it in GitHub Desktop.
Dynamic stack container
extension View {
func embedInStack() -> some View {
modifier(EmbedInStack())
}
}
struct EmbedInStack: ViewModifier {
@Environment(\.sizeCategory) var sizeCategory
func body(content: Content) -> some View {
Group {
if sizeCategory > ContentSizeCategory.medium {
VStack { content }
} else {
HStack { content }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment