Skip to content

Commit 9ab29c1

Browse files
authored
Merge pull request #17 from SDWebImage/bugfix_view_wrapper_mac
Using the frame layout for view wrapper instead of Autolayout. Solve the issue when running on AppKit (not Catalyst)
2 parents c052f22 + 4bdec6c commit 9ab29c1

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

SDWebImageSwiftUI/Classes/ImageViewWrapper.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,26 @@ public class AnimatedImageViewWrapper : PlatformView {
3131
ctx.setShouldAntialias(shouldAntialias)
3232
}
3333

34+
#if os(macOS)
35+
public override func layout() {
36+
super.layout()
37+
wrapped.frame = self.bounds
38+
}
39+
#else
40+
public override func layoutSubviews() {
41+
super.layoutSubviews()
42+
wrapped.frame = self.bounds
43+
}
44+
#endif
45+
3446
public override init(frame frameRect: CGRect) {
3547
super.init(frame: frameRect)
3648
addSubview(wrapped)
37-
wrapped.bindFrameToSuperviewBounds()
3849
}
3950

4051
public required init?(coder: NSCoder) {
4152
super.init(coder: coder)
4253
addSubview(wrapped)
43-
wrapped.bindFrameToSuperviewBounds()
44-
}
45-
}
46-
47-
extension PlatformView {
48-
/// Adds constraints to this `UIView` instances `superview` object to make sure this always has the same size as the superview.
49-
/// Please note that this has no effect if its `superview` is `nil` – add this `UIView` instance as a subview before calling this.
50-
func bindFrameToSuperviewBounds() {
51-
guard let superview = self.superview else {
52-
print("Error! `superview` was nil – call `addSubview(view: UIView)` before calling `bindFrameToSuperviewBounds()` to fix this.")
53-
return
54-
}
55-
56-
self.translatesAutoresizingMaskIntoConstraints = false
57-
self.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0).isActive = true
58-
self.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0).isActive = true
59-
self.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0).isActive = true
60-
self.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0).isActive = true
61-
6254
}
6355
}
6456

0 commit comments

Comments
 (0)