Skip to content

stateman92/AnimationObserver

Repository files navigation

AnimationObserver

Observe SwiftUI animation progress with ease! 🔬

Setup

Add the following to Package.swift:

.package(url: "https://github.com/stateman92/AnimationObserver", exact: .init(0, 0, 1))

Or add the package in Xcode.

Usage

public struct CustomView {
    @Binding private var playing: Bool
    @State private var progress: Double

    public init(playing: Binding<Bool>) {
        self._playing = playing
        self.progress = playing.wrappedValue ? .zero : 1
    }

    public var body: some View {
        // ...
        .animationObserver(for: progress) {
            playing = true
        } onComplete: {
            playing = false
        }
    }
}

For details see the Example app.

Example

Example

About

Observe SwiftUI animation progress with ease! 🔬

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages