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
@propertyWrapper | |
final class ThreadSafe<T> { | |
private let queue = DispatchQueue(label: "ThreadSafeTypeQueue", | |
attributes: .concurrent) | |
private var content: T | |
var wrappedValue: T { | |
get { | |
queue.sync { |
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 displaySheet = false | |
@State var shake = false | |
var body: some View { | |
Text("Shake Me") | |
.font(.title) | |
.onTapGesture { | |
shake = true | |
} |
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 Shake<Content: View>: View { | |
/// Set to true in order to animate | |
@Binding var shake: Bool | |
/// How many times the content will animate back and forth | |
var repeatCount = 3 | |
/// Duration in seconds | |
var duration = 0.8 | |
/// Range in pixels to go back and forth | |
var offsetRange = 10.0 |
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) { |
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
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() | |
} |
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
Text("Testing") | |
.scaleEffect(firstAnimation ? 2 : 1) | |
.foregroundColor(secondAnimation ? .red : .green) | |
.onTapGesture { | |
Task { | |
let animationTime = 0.5 | |
await animate(duration: animationTime) { | |
firstAnimation = true | |
} |
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
Text("Testing") | |
.scaleEffect(firstAnimation ? 2 : 1) | |
.foregroundColor(secondAnimation ? .red : .green) | |
.onTapGesture { | |
let animationTime = 0.5 | |
withAnimation(.linear(duration: animationTime)) { | |
firstAnimation = true | |
} |
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 firstAnimation = false | |
@State var secondAnimation = false | |
@State var displaySheet = false | |
var body: some View { | |
Text("Testing") | |
.scaleEffect(firstAnimation ? 2 : 1) | |
.foregroundColor(secondAnimation ? .red : .green) | |
.onTapGesture { |
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 isAnimating = false | |
var body: some View { | |
Text("Testing") | |
.scaleEffect(isAnimating ? 2 : 1) | |
.foregroundColor(isAnimating ? .red : .green) | |
.onTapGesture { | |
withAnimation { | |
isAnimating = true |
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 firstAnimation = false | |
@State var secondAnimation = false | |
var body: some View { | |
Text("Testing") | |
.scaleEffect(firstAnimation ? 2 : 1) | |
.foregroundColor(secondAnimation ? .red : .green) | |
.onTapGesture { | |
withAnimation(.linear(duration: 0.5)) { |
NewerOlder