Forked from ole/HStack-VStack-dynamic-switching.swift
Created
November 29, 2021 20:17
-
-
Save codeactual/8dd061552164300285aaf7fcefc6500b 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
| import SwiftUI | |
| struct ContentView: View { | |
| @State var horizontal: Bool = true | |
| @Namespace var namespace | |
| var body: some View { | |
| VStack(spacing: 40) { | |
| if horizontal { | |
| HStack { items } | |
| } else { | |
| VStack { items } | |
| } | |
| Button("Toggle") { | |
| withAnimation { horizontal.toggle() } | |
| } | |
| } | |
| .padding() | |
| } | |
| @ViewBuilder var items: some View { | |
| Ellipse().fill(Color.red) | |
| .matchedGeometryEffect(id: "circle", in: namespace) | |
| Capsule().fill(Color.green) | |
| .matchedGeometryEffect(id: "capsule", in: namespace) | |
| Rectangle().fill(Color.blue) | |
| .matchedGeometryEffect(id: "rectangle", in: namespace) | |
| } | |
| } | |
| struct ContentView_Previews: PreviewProvider { | |
| static var previews: some View { | |
| ContentView() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment