Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created June 8, 2022 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupamchugh/9f999153edd903f7e7d256a2e77621cf to your computer and use it in GitHub Desktop.
Save anupamchugh/9f999153edd903f7e7d256a2e77621cf to your computer and use it in GitHub Desktop.
struct SwitchLayouts : View{
@State private var switchStack: Bool = false
var body: some View{
let layout = switchStack ? AnyLayout(HStack()) : AnyLayout(VStack())
VStack{
Button {
self.switchStack.toggle()
} label: {
Text("Switch")
}
layout {
RoundedRectangle(cornerRadius: 20)
.fill(.orange)
RoundedRectangle(cornerRadius: 20)
.fill(.blue)
}
.frame(width: 200, height: 200)
}
.padding()
.animation(.default, value: self.switchStack)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment