From 6f373ad3056fb154e385daadf87036062e40347a Mon Sep 17 00:00:00 2001 From: Fabian Thies Date: Fri, 23 Dec 2022 16:02:57 +0100 Subject: [PATCH] [ADD] Full-screen app screenshot preview --- AltStore.xcodeproj/project.pbxproj | 4 ++ .../App Detail/AppScreenshotsPreview.swift | 69 +++++++++++++++++++ .../App Detail/AppScreenshotsScrollView.swift | 35 +++++++--- 3 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 AltStore/Views/App Detail/AppScreenshotsPreview.swift diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index c95499ea..ec920637 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 19B9B7452845E6DF0076EF69 /* SelectTeamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B9B7442845E6DF0076EF69 /* SelectTeamViewController.swift */; }; 1F07F5672955D16A00F7BE95 /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = 1F07F5662955D16A00F7BE95 /* SFSafeSymbols */; }; 1F07F5692955D3EC00F7BE95 /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = 1F07F5682955D3EC00F7BE95 /* SFSafeSymbols */; }; + 1F07F56B2955F11500F7BE95 /* AppScreenshotsPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F07F56A2955F11500F7BE95 /* AppScreenshotsPreview.swift */; }; 1F0DD81C2932D2FF007608A4 /* AppScreenshotsScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F0DD81B2932D2FF007608A4 /* AppScreenshotsScrollView.swift */; }; 1F0DD81F2932D84C007608A4 /* ExpandableText in Frameworks */ = {isa = PBXBuildFile; productRef = 1F0DD81E2932D84C007608A4 /* ExpandableText */; }; 1F0DD8212933B749007608A4 /* AppPermissionsGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F0DD8202933B749007608A4 /* AppPermissionsGrid.swift */; }; @@ -555,6 +556,7 @@ 191E5FD1290A651D001A3B7C /* jsmn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jsmn.h; path = Dependencies/libplist/src/jsmn.h; sourceTree = SOURCE_ROOT; }; 1920B04E2924AC8300744F60 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; 19B9B7442845E6DF0076EF69 /* SelectTeamViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectTeamViewController.swift; sourceTree = ""; }; + 1F07F56A2955F11500F7BE95 /* AppScreenshotsPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppScreenshotsPreview.swift; sourceTree = ""; }; 1F0DD81B2932D2FF007608A4 /* AppScreenshotsScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppScreenshotsScrollView.swift; sourceTree = ""; }; 1F0DD8202933B749007608A4 /* AppPermissionsGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPermissionsGrid.swift; sourceTree = ""; }; 1F0DD83E29367F6C007608A4 /* ConnectAppleIDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectAppleIDView.swift; sourceTree = ""; }; @@ -1132,6 +1134,7 @@ 1FB84BA52928DE08006A5CF4 /* AppDetailView.swift */, 1F0DD81B2932D2FF007608A4 /* AppScreenshotsScrollView.swift */, 1F0DD8202933B749007608A4 /* AppPermissionsGrid.swift */, + 1F07F56A2955F11500F7BE95 /* AppScreenshotsPreview.swift */, ); path = "App Detail"; sourceTree = ""; @@ -2772,6 +2775,7 @@ BFDB6A0B22AAEDB7007EA6D6 /* Operation.swift in Sources */, 1FB96FEC292C171D007E68D1 /* NotificationManager.swift in Sources */, BF770E6722BD57C4002A40FE /* BackgroundTaskManager.swift in Sources */, + 1F07F56B2955F11500F7BE95 /* AppScreenshotsPreview.swift in Sources */, BF44EEFC246B4550002A52F2 /* RemoveAppOperation.swift in Sources */, BF3D64B022E8D4B800E9056B /* AppContentViewControllerCells.swift in Sources */, BFC57A6E2416FC5D00EB891E /* InstalledAppsCollectionHeaderView.swift in Sources */, diff --git a/AltStore/Views/App Detail/AppScreenshotsPreview.swift b/AltStore/Views/App Detail/AppScreenshotsPreview.swift new file mode 100644 index 00000000..bba3db7e --- /dev/null +++ b/AltStore/Views/App Detail/AppScreenshotsPreview.swift @@ -0,0 +1,69 @@ +// +// AppScreenshotsPreview.swift +// SideStore +// +// Created by Fabian Thies on 23.12.22. +// Copyright © 2022 SideStore. All rights reserved. +// + +import SwiftUI +import AsyncImage +import AltStoreCore + +struct AppScreenshotsPreview: View { + + @Environment(\.dismiss) + private var dismiss + + let urls: [URL] + let aspectRatio: CGFloat + @State var index: Int + + init(urls: [URL], aspectRatio: CGFloat = 9/16, initialIndex: Int = 0) { + self.urls = urls + self.aspectRatio = aspectRatio + self._index = State(initialValue: initialIndex) + } + + var body: some View { + TabView(selection: $index) { + ForEach(Array(urls.enumerated()), id: \.offset) { (i, url) in + AsyncImage(url: url) { image in + image + .resizable() + } placeholder: { + Rectangle() + .foregroundColor(Color(.secondarySystemBackground)) + .aspectRatio(aspectRatio, contentMode: .fill) + } + .aspectRatio(aspectRatio, contentMode: .fit) + .cornerRadius(8) + .padding() + .tag(i) + } + } + .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)) + .toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + SwiftUI.Button { + self.dismiss() + } label: { + Text("Close") + } + } + } + } +} + +extension AppScreenshotsPreview: Equatable { + /// Prevent re-rendering of the view if the parameters didn't change + static func == (lhs: AppScreenshotsPreview, rhs: AppScreenshotsPreview) -> Bool { + lhs.urls == rhs.urls + } +} + +//struct AppScreenshotsPreview_Previews: PreviewProvider { +// static var previews: some View { +// AppScreenshotsPreview() +// } +//} diff --git a/AltStore/Views/App Detail/AppScreenshotsScrollView.swift b/AltStore/Views/App Detail/AppScreenshotsScrollView.swift index e0c8bce0..c7921ccf 100644 --- a/AltStore/Views/App Detail/AppScreenshotsScrollView.swift +++ b/AltStore/Views/App Detail/AppScreenshotsScrollView.swift @@ -19,25 +19,36 @@ struct AppScreenshotsScrollView: View { var aspectRatio: CGFloat = 9/16 var height: CGFloat = 400 + @State var selectedScreenshotIndex: Int? + var body: some View { ScrollView(.horizontal, showsIndicators: false) { HStack { - ForEach(urls) { url in - AsyncImage(url: url) { image in - image - .resizable() - } placeholder: { - Rectangle() - .foregroundColor(.secondary) + ForEach(Array(urls.enumerated()), id: \.offset) { i, url in + SwiftUI.Button { + self.selectedScreenshotIndex = i + } label: { + AsyncImage(url: url) { image in + image + .resizable() + } placeholder: { + Rectangle() + .foregroundColor(.secondary) + } + .aspectRatio(aspectRatio, contentMode: .fit) + .cornerRadius(8) } - .aspectRatio(aspectRatio, contentMode: .fit) - .cornerRadius(8) } } .padding(.horizontal) } .frame(height: height) .shadow(radius: 12) + .sheet(item: self.$selectedScreenshotIndex) { index in + NavigationView { + AppScreenshotsPreview(urls: urls, aspectRatio: aspectRatio, initialIndex: index) + } + } } } @@ -47,3 +58,9 @@ extension AppScreenshotsScrollView: Equatable { lhs.urls == rhs.urls && lhs.aspectRatio == rhs.aspectRatio && lhs.height == rhs.height } } + +extension Int: Identifiable { + public var id: Int { + self + } +}