Last active
July 13, 2020 15:12
-
-
Save chriseidhof/1f7d5c41e132fcf7865977289083ba73 to your computer and use it in GitHub Desktop.
matchedGeometryEffect experiments
This file contains 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
// | |
// ContentView.swift | |
// Effects | |
// | |
// Created by Chris Eidhof on 13.07.20. | |
// | |
import SwiftUI | |
struct MyModifier: AnimatableModifier { | |
var animatableData: Int = 0 | |
func body(content: Content) -> some View { | |
content.overlay(Text("\(animatableData)")) | |
} | |
} | |
struct ContentView: View { | |
@Namespace var ns | |
@State var toggle = false | |
var body: some View { | |
VStack { | |
Toggle("Toggle", isOn: $toggle.animation(.easeInOut(duration: 1))) | |
Rectangle().fill(Color.red).frame(height: 200).overlay( | |
Group { | |
if toggle { | |
Circle() | |
.fill(Color.gray) | |
.modifier(MyModifier(animatableData: 0)) | |
.matchedGeometryEffect(id: "circle", in: ns) | |
.frame(width: 100, height: 100) | |
} | |
} | |
) | |
Rectangle().fill(Color.green).frame(height: 200).overlay( | |
Group { | |
if !toggle { | |
Circle() | |
.fill(Color.white) | |
.modifier(MyModifier(animatableData: 100)) | |
.matchedGeometryEffect(id: "circle", in: ns) | |
.frame(width: 50, height: 50) | |
} | |
} | |
) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
This file contains 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
// | |
// ContentView.swift | |
// Effects | |
// | |
// Created by Chris Eidhof on 13.07.20. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@Namespace var ns | |
@State var toggle = false | |
var body: some View { | |
VStack { | |
Toggle("Toggle", isOn: $toggle.animation(.easeInOut(duration: 1))) | |
Rectangle().fill(Color.red).frame(height: 200).overlay( | |
Group { | |
if toggle { | |
Circle() | |
.fill(Color.black) | |
.matchedGeometryEffect(id: "circle", in: ns) | |
.frame(width: 100, height: 100) | |
} | |
} | |
) | |
Rectangle().fill(Color.green).frame(height: 200).overlay( | |
Group { | |
if !toggle { | |
Circle() | |
.fill(Color.white) | |
.matchedGeometryEffect(id: "circle", in: ns) | |
.frame(width: 50, height: 50) | |
} | |
} | |
) | |
} | |
} | |
} | |
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