Skip to content

Instantly share code, notes, and snippets.

@ole
Created November 28, 2021 13:18
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ole/8f96116dcd624b55a652e3918c7afc1c to your computer and use it in GitHub Desktop.
Save ole/8f96116dcd624b55a652e3918c7afc1c to your computer and use it in GitHub Desktop.
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()
}
}
@ole
Copy link
Author

ole commented Nov 28, 2021

This is the code accompanying this tweet: https://twitter.com/olebegemann/status/1464946888768208900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment