Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/AliAdam/ImageWithActivityIndicator
SwiftUI view that download and display image from URL and displaying Activity Indicator while loading .
https://github.com/AliAdam/ImageWithActivityIndicator
Last synced: 3 months ago
JSON representation
SwiftUI view that download and display image from URL and displaying Activity Indicator while loading .
- Host: GitHub
- URL: https://github.com/AliAdam/ImageWithActivityIndicator
- Owner: AliAdam
- Created: 2019-06-14T14:47:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-21T22:01:38.000Z (almost 5 years ago)
- Last Synced: 2024-07-15T00:44:41.658Z (4 months ago)
- Language: Swift
- Homepage:
- Size: 22.5 KB
- Stars: 27
- Watchers: 2
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- fucking-about-SwiftUI - ImageWithActivityIndicator
README
# ViewWithActivityIndicator
`ViewWithActivityIndicator` is a SwiftUI view that download and display image from URL and displaying Activity Indicator while loading .
# ScreenShots
![N|Solid](https://github.com/AliAdam/ViewWithActivityIndicatorDemo/blob/master/preview.gif?raw=true)
Demo app [ViewWithActivityIndicatorDemo](https://github.com/blackwiz4rd/ViewWithActivityIndicatorDemo).
## Installation
`ViewWithActivityIndicator` is a Swift Package and you can install it with Xcode 11:
- Copy SSH `[email protected]:blackwiz4rd/ViewWithActivityIndicator.git` or HTTPS `https://github.com/blackwiz4rd/ViewWithActivityIndicator.git` URL from github;
- Open **File/Swift Packages/Add Package Dependency...** in Xcode 11;
- Paste the URL and follow steps.## Usage
`ViewWithActivityIndicator` must be initialized with a URL and optional placeholder image.
```swift
let url = ""ViewWithActivityIndicator(imageURL: url)
ViewWithActivityIndicator(imageURL: url,placeHolder: "icon")
```Using in a view:
```swift
import SwiftUI
import ViewWithActivityIndicatorstruct ContentView : View {
let loader: ViewLoader = ViewLoader(url: "https://picsum.photos/300")
var body: some View {
ViewWithActivityIndicator(placeHolder: "", showActivityIndicator: true, viewLoader: loader) {
Image(uiImage: UIImage(data:self.loader.getData()) ?? UIImage())
}
}
}
```Using in a list:
```swift
import SwiftUI
import ViewWithActivityIndicatorstruct ContentView : View {
let urls: [String]
let loader: ViewLoader = ViewLoader(url: "https://picsum.photos/300")var body: some View {
List(urls, id: \.self) { url in
HStack {
ViewWithActivityIndicator(imageURL: url)
.frame(width: 100.0, height: 100.0)
Text("\(url)")
}
}
}
}
```ViewLoaders allows to create multiple loaders given a String array:
```swift
@available(iOS 13.0, *)
public struct ViewLoaders {
var loaders: [ViewLoader] = []
init(urls: [String]) {
for url in urls {
loaders.append(ViewLoader(url: url))
}
}
}
```