Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created July 20, 2020 15:21
Show Gist options
  • Save azamsharp/80042694678d4748cbf2a87ca819529d to your computer and use it in GitHub Desktop.
Save azamsharp/80042694678d4748cbf2a87ca819529d to your computer and use it in GitHub Desktop.
import SwiftUI
struct FooView: View {
@State private var isSwitched: Bool = false
@Namespace private var ns
var body: some View {
HStack {
if !isSwitched {
Circle()
.fill(Color.red)
.frame(width: 50, height: 50)
.matchedGeometryEffect(id: "animation", in: ns)
}
Spacer()
Button("Switch") {
withAnimation {
isSwitched.toggle()
}
}
Spacer()
VStack {
Circle()
.fill(Color.red)
.frame(width: 50, height: 50)
if isSwitched {
Circle()
.fill(Color.green)
.matchedGeometryEffect(id: "animation", in: ns)
}
Circle()
.fill(Color.red)
.frame(width: 50, height: 50)
}
}
}
}
struct Foo_Previews: PreviewProvider {
static var previews: some View {
FooView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment