2023-01-13 12:04:10 +01:00
|
|
|
//
|
|
|
|
|
// AppScreenshot.swift
|
|
|
|
|
// SideStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Fabian Thies on 20.12.22.
|
|
|
|
|
// Copyright © 2022 SideStore. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import UIKit
|
|
|
|
|
import AsyncImage
|
|
|
|
|
|
|
|
|
|
struct AppScreenshot: View {
|
|
|
|
|
let url: URL
|
2023-01-16 18:59:39 +01:00
|
|
|
var aspectRatio: CGFloat = 9/16
|
2023-01-13 12:04:10 +01:00
|
|
|
|
|
|
|
|
static let processor = Self.ScreenshotProcessor()
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
2023-01-16 18:59:39 +01:00
|
|
|
AsyncImage(url: self.url, processor: Self.processor) { image in
|
|
|
|
|
image
|
|
|
|
|
.resizable()
|
|
|
|
|
} placeholder: {
|
|
|
|
|
Rectangle()
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
}
|
|
|
|
|
.aspectRatio(self.aspectRatio, contentMode: .fit)
|
|
|
|
|
.cornerRadius(8)
|
2023-01-13 12:04:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension AppScreenshot {
|
|
|
|
|
class ScreenshotProcessor: ImageProcessor {
|
|
|
|
|
func process(image: UIImage) -> UIImage {
|
|
|
|
|
guard let cgImage = image.cgImage, image.size.width > image.size.height else { return image }
|
|
|
|
|
|
|
|
|
|
let rotatedImage = UIImage(cgImage: cgImage, scale: image.scale, orientation: .right)
|
|
|
|
|
return rotatedImage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-16 18:59:39 +01:00
|
|
|
|
|
|
|
|
|
2023-02-19 14:30:21 +01:00
|
|
|
import AltStoreCore
|
|
|
|
|
|
2023-01-16 18:59:39 +01:00
|
|
|
struct AppScreenshot_Previews: PreviewProvider {
|
|
|
|
|
|
2023-02-19 14:30:21 +01:00
|
|
|
static let context = DatabaseManager.shared.viewContext
|
|
|
|
|
static let app = StoreApp.makeAltStoreApp(in: context)
|
|
|
|
|
|
2023-01-16 18:59:39 +01:00
|
|
|
static var previews: some View {
|
2023-02-19 14:30:21 +01:00
|
|
|
AppScreenshot(url: app.screenshotURLs[0])
|
|
|
|
|
.padding()
|
2023-01-16 18:59:39 +01:00
|
|
|
}
|
|
|
|
|
}
|