From a725f3e9cc2cec550a3d084a8e0a5664b87c1eb9 Mon Sep 17 00:00:00 2001 From: Fabian Thies Date: Mon, 16 Jan 2023 18:59:39 +0100 Subject: [PATCH] [ADD] AppScreenshot view with ImageProcessor to automatically rotate landscape screenshots --- .../xcshareddata/swiftpm/Package.resolved | 2 +- AltStore/View Components/AppScreenshot.swift | 29 ++++++++++++------- .../App Detail/AppScreenshotsScrollView.swift | 10 +------ .../Views/Browse/BrowseAppPreviewView.swift | 10 +------ 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index dcd02837..6c88bf6d 100644 --- a/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,7 +24,7 @@ "location" : "https://github.com/fabianthdev/AsyncImage", "state" : { "branch" : "main", - "revision" : "04fe7c66f8362b863c926b87a6d5d9820ffc5bad" + "revision" : "018a4fffea025066d795ebb025c2769183f3fffb" } }, { diff --git a/AltStore/View Components/AppScreenshot.swift b/AltStore/View Components/AppScreenshot.swift index 74a2b1cb..459b9781 100644 --- a/AltStore/View Components/AppScreenshot.swift +++ b/AltStore/View Components/AppScreenshot.swift @@ -12,21 +12,20 @@ import AsyncImage struct AppScreenshot: View { let url: URL - var apectRatio: CGFloat = 9/16 + var aspectRatio: CGFloat = 9/16 static let processor = Self.ScreenshotProcessor() var body: some View { - Text("") -// AsyncImage(url: self.url, processor: Self.processor) { image in -// image -// .resizable() -// } placeholder: { -// Rectangle() -// .foregroundColor(.secondary) -// } -// .aspectRatio(aspectRatio, contentMode: .fit) -// .cornerRadius(8) + AsyncImage(url: self.url, processor: Self.processor) { image in + image + .resizable() + } placeholder: { + Rectangle() + .foregroundColor(.secondary) + } + .aspectRatio(self.aspectRatio, contentMode: .fit) + .cornerRadius(8) } } @@ -40,3 +39,11 @@ extension AppScreenshot { } } } + + +struct AppScreenshot_Previews: PreviewProvider { + + static var previews: some View { + AppScreenshot(url: URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-dark.png")!) + } +} diff --git a/AltStore/Views/App Detail/AppScreenshotsScrollView.swift b/AltStore/Views/App Detail/AppScreenshotsScrollView.swift index c7921ccf..705b87aa 100644 --- a/AltStore/Views/App Detail/AppScreenshotsScrollView.swift +++ b/AltStore/Views/App Detail/AppScreenshotsScrollView.swift @@ -28,15 +28,7 @@ struct AppScreenshotsScrollView: View { SwiftUI.Button { self.selectedScreenshotIndex = i } label: { - AsyncImage(url: url) { image in - image - .resizable() - } placeholder: { - Rectangle() - .foregroundColor(.secondary) - } - .aspectRatio(aspectRatio, contentMode: .fit) - .cornerRadius(8) + AppScreenshot(url: url) } } } diff --git a/AltStore/Views/Browse/BrowseAppPreviewView.swift b/AltStore/Views/Browse/BrowseAppPreviewView.swift index 8df2cd84..412216d1 100644 --- a/AltStore/Views/Browse/BrowseAppPreviewView.swift +++ b/AltStore/Views/Browse/BrowseAppPreviewView.swift @@ -24,15 +24,7 @@ struct BrowseAppPreviewView: View { if !storeApp.screenshotURLs.isEmpty { HStack { ForEach(storeApp.screenshotURLs.prefix(2)) { url in - AsyncImage(url: url) { image in - image - .resizable() - .aspectRatio(contentMode: .fit) - } placeholder: { - Color(UIColor.secondarySystemBackground) - .aspectRatio(9/16, contentMode: .fit) - } - .cornerRadius(8) + AppScreenshot(url: url) } } .frame(height: 300)