Created
July 20, 2020 15:21
-
-
Save azamsharp/80042694678d4748cbf2a87ca819529d 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 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