The missing DisplayLink driver for Apple platforms. Use CADisplayLink on UIKit and CVDisplayLink on AppKit.
Battle tested in ColorfulX
Called MS but it has nothing to do with Microsoft. :P
.package(url: "https://github.com/Lakr233/MSDisplayLink.git", from: "2.0.8")Never thought about it.
Follow the steps to get called. The DisplayLinkDelegate is friendly to confirm for a UIView or NSView.
- Hold reference to
DisplayLinkobject. - Confirm to
DisplayLinkDelegateprotocol to get called withinsynchronization(). - Call
displayLink.delegatingObjectwith aDisplayLinkDelegateobject.
Tech Tips:
- Call to
synchronization()is performed at a background thread. - Scheduler is a serial queue unique to each
DisplayLinkDriverholds byDisplayLink.- Queue inherits the quality of service from the where you created the
DisplayLink. - Does not make scene to use concurrent queue.
- Does not share the queue across different
DisplayLinkobjects. - Queue names are same.
- Queue inherits the quality of service from the where you created the
import MSDisplayLink
import SwiftUI
struct ContentView: View {
@State var frame: Int = 0
var body: some View {
VStack {
Text("MSDisplayLink Trigger: \(frame)")
.monospacedDigit()
.contentTransition(.numericText())
}
.animation(.interactiveSpring, value: frame)
.modifier(DisplayLinkModifier(scheduleToMainThread: true) {
frame += 1
})
.padding()
}
}
2024.08.14
