Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Created November 16, 2022 18:17
Show Gist options
  • Save davidbalbert/aa46418d45c1bae5ab1e86cd51b7e0a0 to your computer and use it in GitHub Desktop.
Save davidbalbert/aa46418d45c1bae5ab1e86cd51b7e0a0 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State var atTop = true
@Namespace var ns
var body: some View {
VStack {
VStack {
Text("Top")
.border(.green)
.opacity(atTop ? 1 : 0)
.matchedGeometryEffect(id: "text", in: ns, properties: .position, isSource: atTop ? true : false)
Spacer()
Text("Bottom")
.border(.blue)
.opacity(atTop ? 0 : 1)
.matchedGeometryEffect(id: "text", in: ns, properties: .position, isSource: atTop ? false : true)
}
.frame(width: 64)
.frame(maxHeight: .infinity)
.border(.red)
Button("Move") {
withAnimation(.default) {
atTop = !atTop
}
}
}
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment