AuthAsyncImage
The AuthenticatedAsyncImage struct allows you to load images asynchronously with authentication support. It provides a customizable progress view and a default image in case of errors or when the image is not available.
Features
- Load images asynchronously with autethication support based on iOS 15 or later
- Customizable appearance and behavior
Requirements
- iOS 15 or later
- Swift 5.5 or later
Installation
Swift Package Manager
To install the AuthAsyncImage library using Swift Package Manager, follow these steps:
- In Xcode, open your project.
- Go to File > Swift Packages > Add Package Dependency.
- Enter the repository URL:
https://github.com/Bereyziat-Development/AuthAsyncImage.git
. - Click Next and follow the remaining steps to add the package to your project.
Usage
- Import the necessary modules:
import SwiftUI
import AuthAsyncImage
- Create an instance of ImageData with the required parameters:
let imageData = ImageData(token: token, url: imageURL)
- Use AuthenticatedAsyncImage in your SwiftUI view:
AuthenticatedAsyncImage(imageData: imageData, defaultImage: defaultImage, progressView: progressView)
- Customization
The SwiftUIAdaptiveActionSheet you can customize the defaultImage and progressView properties to match your app’s design.
Example Here’s an example of customizing the component:
import SwiftUI
import AuthAsyncImage
struct ContentView: View {
let myURL = URL(string: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTps49CxS3mpmPzrFA4aY6cSRtxjz6BYfdqj00WSqB83urjS-HsMbs3eiXg30iw4tF8BIU&usqp=CAU")
var body: some View {
HStack {
AuthenticatedAsyncImage(imageData: ImageData(token: nil, url: myURL!), progressView: AnyView(ProgressView()))
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 12))
.scaledToFill()
.clipped()
.frame(maxWidth: 100, maxHeight: 100)
.cornerRadius(12)
Text("Hello, world!")
}
.padding()
}
}
License
This library is available under the MIT license. See the LICENSE file for more information.