Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Using the frame layout for view wrapper instead of Autolayout. Solve …
…the issue when running on AppKit (not Catalyst)
  • Loading branch information
dreampiggy committed Oct 5, 2019
commit 4bdec6c958168712ef058d5cec36b033437b224b
32 changes: 12 additions & 20 deletions SDWebImageSwiftUI/Classes/ImageViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,26 @@ public class AnimatedImageViewWrapper : PlatformView {
ctx.setShouldAntialias(shouldAntialias)
}

#if os(macOS)
public override func layout() {
super.layout()
wrapped.frame = self.bounds
}
#else
public override func layoutSubviews() {
super.layoutSubviews()
wrapped.frame = self.bounds
}
#endif

public override init(frame frameRect: CGRect) {
super.init(frame: frameRect)
addSubview(wrapped)
wrapped.bindFrameToSuperviewBounds()
}

public required init?(coder: NSCoder) {
super.init(coder: coder)
addSubview(wrapped)
wrapped.bindFrameToSuperviewBounds()
}
}

extension PlatformView {
/// Adds constraints to this `UIView` instances `superview` object to make sure this always has the same size as the superview.
/// Please note that this has no effect if its `superview` is `nil` – add this `UIView` instance as a subview before calling this.
func bindFrameToSuperviewBounds() {
guard let superview = self.superview else {
print("Error! `superview` was nil – call `addSubview(view: UIView)` before calling `bindFrameToSuperviewBounds()` to fix this.")
return
}

self.translatesAutoresizingMaskIntoConstraints = false
self.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0).isActive = true
self.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0).isActive = true
self.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0).isActive = true
self.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0).isActive = true

}
}

Expand Down