Skip to content

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

@robmaceachern

Description

@robmaceachern

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementNon-functional change that improves existing functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions