Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions Sources/_UIKit_AnimatedImage/AnimatableCGImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ open class AnimatableCGImageView: CGImageView {

public override init(frame: CGRect) {
super.init(frame: frame)
if #available(iOS 18.0, visionOS 2.0, *) {
// workaround: Designed for iPad doesn't have UIUpdateLink.
if ProcessInfo.processInfo.isiOSAppOnMac {
updateLink = BackportUpdateLink(view: self)
} else {
updateLink = UIUpdateLink(view: self)
}
if #available(iOS 18.0, visionOS 2.0, *), Self.isSupportedUIUpdateLink {
updateLink = UIUpdateLink(view: self)
} else {
updateLink = BackportUpdateLink(view: self)
}
updateLink.isEnabled = true
updateLink.preferredFrameRateRange = CAFrameRateRange(
minimum: 1,
maximum: 60
Expand All @@ -25,20 +19,38 @@ open class AnimatableCGImageView: CGImageView {
updateContents(for: info.modelTime)
})
updateLink.requiresContinuousUpdates = true
updateLink.isEnabled = true
}

public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

static var isSupportedUIUpdateLink: Bool {
if #available(iOS 18.0, visionOS 2.0, *) {
// workaround: Designed for iPad doesn't have UIUpdateLink.
if ProcessInfo.processInfo.isiOSAppOnMac {
false
} else {
true
}
} else {
false
}
}

open override func didMoveToSuperview() {
super.didMoveToSuperview()
updateLink.isEnabled = true
if !Self.isSupportedUIUpdateLink {
updateLink.isEnabled = true
}
}

open override func removeFromSuperview() {
super.removeFromSuperview()
updateLink.isEnabled = false
if !Self.isSupportedUIUpdateLink {
updateLink.isEnabled = false
}
}

open func updateContents(for targetTimestamp: TimeInterval) {
Expand Down