dmytro-anokhin / url-image

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.
MIT License
1.1k stars 96 forks source link

Usage as TabView tabItem image breaks scaling #45

Closed roben closed 4 years ago

roben commented 4 years ago

Summary and/or background

When using URLImage within a tab view, the images are shown larger than the tab bar itself.

OS and what device you are using

Version of URLImage library

What you expected would happen A clear and concise description of what you expected to happen.

What actually happens When using URLImage within a tab view, the images are shown larger than the tab bar itself. Setting a frame does not have any effect: image

Using the resize processor with 20px size and scale = 1 is a workaround for now but it is ugly and platform dependant.

Sample code

TabView {
    ForEach (self.backends) { (backend: Backend) in
        WebViewControllerWrapper(baseUrl: backend.baseUrl)
            .tabItem {
                URLImage(
                    backend.appIconUrl,
//                          processors: [ Resize(size: CGSize(width: self.navBarImageSize, height: self.navBarImageSize), scale: 1) ],
                    content:  {
                        $0.image
                        .resizable()
                        .frame(width: self.navBarImageSize, height: self.navBarImageSize)

                }).frame(width: self.navBarImageSize, height: self.navBarImageSize)
        }
    }
    BackendListView().tabItem {
        Image(systemName: "list.dash")
    }
    BackendRegistrationView().tabItem {
        Image(systemName: "plus.app")
    }
}

Test data

Additional information:

dmytro-anokhin commented 4 years ago

Hey,

SwiftUI allows only text and image tab items. Here's a quote from documentation: "Tab views only support tab items of type Text, Image, or an image followed by text. Passing any other type of view results in a visible but empty tab item." https://developer.apple.com/documentation/swiftui/tabview