DisplayLink

0.2.0

Per-frame actions for SwiftUI
timdonnelly/DisplayLink

What's New

2019-12-04T20:11:20Z

DisplayLink

A simplified DisplayLink abstraction for all platforms (including iOS, tvOS, watchOS, macOS, Linux).

public final class DisplayLink : Publisher {
    public typealias Output = Frame
    public typealias Failure = Never
}

extension DisplayLink {
    public struct Frame {
        public var timestamp: TimeInterval
        public var duration: TimeInterval
    }
}
Platform Implementation
iOS, tvOS CADisplayLink
macOS CVDisplayLink
watchOS, Linux Timer

Includes a Combine publisher with SwiftUI integration for CADisplayLink.

SwiftUI does not currently provide any API to perform actions on a per-frame basis. This tiny library simplifies the work of bridging between CADisplayLink and SwiftUI:

import DisplayLink

struct MyView: View {

    @State var offset: CGFloat = 0.0

    var body: some View {
        Color
            .red
            .frame(width: 40, height: 40)
            .offset(x: offset, y: offset)
            .onFrame { frame in
                self.offset += (frame.duration * 20.0)
            }
    }
}

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Nov 16 2024 16:42:27 GMT-1000 (Hawaii-Aleutian Standard Time)