mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-14 17:23:25 +01:00
[ADD] iOS 13 compatible AsyncImage implementation with cache
This commit is contained in:
49
AltStore/Views/App Detail/AppScreenshotsScrollView.swift
Normal file
49
AltStore/Views/App Detail/AppScreenshotsScrollView.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// AppScreenshotsScrollView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 27.11.22.
|
||||
// Copyright © 2022 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AsyncImage
|
||||
|
||||
|
||||
/// Horizontal ScrollView with an asynchronously loaded image for each screenshot URL
|
||||
///
|
||||
/// The struct inherits the `Equatable` protocol and implements the respective comparisation function to prevent the view from being constantly re-rendered when a `@State` change in the parent view occurs.
|
||||
/// This way, the `AppScreenshotsScrollView` will only be reloaded when the parameters change.
|
||||
struct AppScreenshotsScrollView: View {
|
||||
let urls: [URL]
|
||||
var aspectRatio: CGFloat = 9/16
|
||||
var height: CGFloat = 400
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack {
|
||||
ForEach(urls) { url in
|
||||
AsyncImage(url: url) { image in
|
||||
image
|
||||
.resizable()
|
||||
} placeholder: {
|
||||
Rectangle()
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.aspectRatio(aspectRatio, contentMode: .fit)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.frame(height: height)
|
||||
.shadow(radius: 12)
|
||||
}
|
||||
}
|
||||
|
||||
extension AppScreenshotsScrollView: Equatable {
|
||||
/// Prevent re-rendering of the view if the parameters didn't change
|
||||
static func == (lhs: AppScreenshotsScrollView, rhs: AppScreenshotsScrollView) -> Bool {
|
||||
lhs.urls == rhs.urls && lhs.aspectRatio == rhs.aspectRatio && lhs.height == rhs.height
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user