Created
March 24, 2023 15:48
-
-
Save mdb1/b0a08fb08b95d7086945c68dd574c5e0 to your computer and use it in GitHub Desktop.
Dynamic stack container
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
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