Nuke icon indicating copy to clipboard operation
Nuke copied to clipboard

Align NukeUI.Image self-sizing behavior with SwiftUI.Image

Open robmaceachern opened this issue 3 years ago • 1 comments

I've noticed that there are some layout differences between SwiftUI.Image and NukeUI.Image when using maxWidth/maxHeight in a List. I'm not sure if it's intentional or not, but it definitely caught me by surprise when I was comparing AsyncImage and LazyImage behaviour.

I've also noticed that the NukeUI.Image can cause sibling Text to truncate after a containing HStack appears after being scrolled offscreen. Sample code and screenshots below. The image used was downloaded from https://picsum.photos/id/0/5616/3744

Xcode: 13.4.1 iOS 15.5

import SwiftUI
import NukeUI

struct ContentView: View {
    var body: some View {
        List {
            HStack {
                NukeUI.Image(UIImage(named: "laptop")!)
                    .resizingMode(.fill)
                    .frame(width: 100, height: 100)
                Text("Nuke - frame(width: 100, height: 100):")
            }

            HStack {
                SwiftUI.Image(uiImage: UIImage(named: "laptop")!)
                    .resizable()
                    .frame(width: 100, height: 100)
                Text("SwiftUI - frame(width: 100, height: 100):")
            }

            HStack {
                NukeUI.Image(UIImage(named: "laptop")!)
                    .resizingMode(.fill)
                    .frame(maxWidth: 100, maxHeight: 100)
                Text("Nuke - frame(maxWidth: 100, maxHeight: 100):")
            }

            HStack {
                SwiftUI.Image(uiImage: UIImage(named: "laptop")!)
                    .resizable()
                    .frame(maxWidth: 100, maxHeight: 100)
                Text("SwiftUI - frame(maxWidth: 100, maxHeight: 100)")
            }

            HStack {
                Rectangle()
                    .frame(width: 100, height: 800)
                Text("A long rectangle")
            }
        }
    }
}
CleanShot 2022-07-27 at 11 01 21@2x

CleanShot 2022-07-27 at 11 08 26@2x

robmaceachern avatar Jul 27 '22 16:07 robmaceachern

Hi, @robmaceachern. It wasn't designed to work the same way as SwiftUI.Image in terms of layout, and it's most likely impossible given the limitations of the API. The only supported use case is when both dimensions are set explicitly.

There is a new sizeThatFits API (iOS 16) on UIViewRepresentable that could probably be used to align the behavior with SwiftUI.Image.

kean avatar Aug 20 '22 13:08 kean

Addressed in Nuke 12.0 (Beta 1)

kean avatar Feb 09 '23 23:02 kean

Please test it in Nuke 12 (RC1).

kean avatar Feb 25 '23 03:02 kean