dmytro-anokhin/url-image

Use ViewBuilder - please comment

dmytro-anokhin opened this issue · 0 comments

Is your feature request related to a problem? Please describe.
Since the initial release of URLImage package, ViewBuilder attribute gone public, and there are some benefits for using it. Using it will allow conditionally return views of different types.

In this example if the image is wider than 100px we make it resizable.

URLImage(url: url) { image, info in
    Group {
        if info.size.width > 100.0 {
            image
                .resizable()
                .aspectRatio(contentMode: .fit)
        }
        else {
            image
        }
    }
}

Using ViewBuilder attribute will allow to return different views:

URLImage(url: url) { image, info in
    if info.size.width > 100.0 {
        image
            .resizable()
            .aspectRatio(contentMode: .fit)
    }
    else {
        image
    }
}

Describe the solution you'd like
Add @ViewBuilder to URLImage initializers.

Current:

init(url: URL, content: @escaping (_ image: Image) -> Content)

New:

init(url: URL, @ViewBuilder content: @escaping (_ image: Image) -> Content)

Describe alternatives you've considered
Keep it as is.

Additional context
ViewBuilder attribute actually allows to provide multiple child views. It is unclear what should be expected behaviour when this is the case. Simply ignore it, wrap in a Group, or a ZStack, etc. Let me know what you think.