Last active
October 24, 2022 15:59
-
-
Save Edudjr/7868167f080cd4b2c55bbde775c36911 to your computer and use it in GitHub Desktop.
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
struct AnimationSample: View { | |
@State var isAnimated = false | |
@State var displaySheet = false | |
var body: some View { | |
Text("Testing") | |
.scaleEffect(isAnimated ? 2 : 1) | |
.onTapGesture { | |
Task { | |
await animate(duration: 0.5) { | |
isAnimated = true | |
} | |
displaySheet = true | |
} | |
} | |
.sheet(isPresented: $displaySheet) { | |
Text("Another view!") | |
} | |
} | |
} | |
extension View { | |
func animate(duration: CGFloat, _ execute: @escaping () -> Void) async { | |
await withCheckedContinuation { continuation in | |
withAnimation(.linear(duration: duration)) { | |
execute() | |
} | |
DispatchQueue.main.asyncAfter(deadline: .now() + duration) { | |
continuation.resume() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment