diff --git a/TestApp/Sources/About/AboutSectionView.swift b/TestApp/Sources/About/AboutSectionView.swift new file mode 100644 index 000000000..a825dd652 --- /dev/null +++ b/TestApp/Sources/About/AboutSectionView.swift @@ -0,0 +1,67 @@ +// +// Copyright 2024 Readium Foundation. All rights reserved. +// Use of this source code is governed by the BSD-style license +// available in the top-level LICENSE file of the project. +// + +import SwiftUI + +struct AboutSectionView: View { + enum Icon: String { + case app = "app.badge" + case circle = "c.circle" + case hands = "hands.sparkles" + } + + private let title: String + private let icon: Icon + private var content: () -> Content + + init( + title: String, + icon: Icon, + content: @escaping () -> Content + ) { + self.title = title + self.icon = icon + self.content = content + } + + var body: some View { + GroupBox { + content() + .padding(.top, 4) + } label: { + Label { + Text(title) + .bold() + } icon: { + Image(systemName: icon.rawValue) + } + .font(.title2) + } + } +} + +#Preview { + AboutSectionView(title: "Version", icon: .app) { + VStack { + HStack { + Text("App Version:") + .foregroundColor(.gray) + Spacer() + Text("alpha-3.0") + .foregroundColor(.primary) + } + + HStack(spacing: 10) { + Text("Build Version:") + .foregroundColor(.gray) + Spacer() + Text("alpha-3.0") + .foregroundColor(.primary) + } + } + } + .padding() +} diff --git a/TestApp/Sources/About/AboutView.swift b/TestApp/Sources/About/AboutView.swift new file mode 100644 index 000000000..c907dc255 --- /dev/null +++ b/TestApp/Sources/About/AboutView.swift @@ -0,0 +1,100 @@ +// +// Copyright 2024 Readium Foundation. All rights reserved. +// Use of this source code is governed by the BSD-style license +// available in the top-level LICENSE file of the project. +// + +import SwiftUI + +struct AboutView: View { + var body: some View { + ScrollView(showsIndicators: false) { + VStack(alignment: .center, spacing: 20) { + versionSection + copyrightSection + acknowledgementsSection + } + .padding(.horizontal, 16) + } + } + + private var versionSection: some View { + AboutSectionView( + title: "Version", + icon: .app + ) { + VStack { + HStack { + Text("App Version:") + .foregroundColor(.secondary) + Spacer() + Text(.appVersion ?? "") + .foregroundColor(.primary) + } + + HStack(spacing: 10) { + Text("Build Version:") + .foregroundColor(.secondary) + Spacer() + Text(.buildVersion ?? "") + .foregroundColor(.primary) + } + } + } + } + + private var copyrightSection: some View { + AboutSectionView( + title: "Copyright", + icon: .circle + ) { + VStack(alignment: .leading) { + Link(destination: .edrlab) { + Text("© 2022 European Digital Reading Lab") + .multilineTextAlignment(.leading) + } + + Link(destination: .license) { + Text("[BSD-3 License]") + .multilineTextAlignment(.leading) + } + } + .frame(maxWidth: .infinity, alignment: .leading) + } + } + + private var acknowledgementsSection: some View { + AboutSectionView( + title: "Acknowledgements", + icon: .hands + ) { + VStack(alignment: .center) { + Text("R2 Reader wouldn't have been developed without the financial help of the French State.") + .multilineTextAlignment(.center) + .foregroundColor(.primary) + Image("rf") + .resizable() + .scaledToFit() + .frame(width: 200) + .clipShape(RoundedRectangle(cornerRadius: 10)) + } + } + } +} + +struct About_Previews: PreviewProvider { + static var previews: some View { + AboutView() + } +} + +private extension String { + static let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String + + static let buildVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String +} + +private extension URL { + static let edrlab = URL(string: "https://www.edrlab.org/")! + static let license = URL(string: "https://opensource.org/licenses/BSD-3-Clause")! +} diff --git a/TestApp/Sources/App/AppModule.swift b/TestApp/Sources/App/AppModule.swift index 5a6e0401f..7873a02d9 100644 --- a/TestApp/Sources/App/AppModule.swift +++ b/TestApp/Sources/App/AppModule.swift @@ -8,6 +8,7 @@ import Combine import Foundation import ReadiumShared import ReadiumStreamer +import SwiftUI import UIKit /// Base module delegate, that sub-modules' delegate can extend. @@ -58,9 +59,10 @@ final class AppModule { } private(set) lazy var aboutViewController: UIViewController = { - let storyboard = UIStoryboard(name: "App", bundle: nil) - let aboutViewController = storyboard.instantiateViewController(withIdentifier: "AboutTableViewController") as! AboutTableViewController - return UINavigationController(rootViewController: aboutViewController) + let hostingController = UIHostingController(rootView: AboutView()) + hostingController.navigationItem.title = "About the Readium Swift Toolkit" + hostingController.navigationItem.largeTitleDisplayMode = .never + return UINavigationController(rootViewController: hostingController) }() } @@ -88,7 +90,11 @@ extension AppModule: LibraryModuleDelegate { extension AppModule: ReaderModuleDelegate {} extension AppModule: OPDSModuleDelegate { - func opdsDownloadPublication(_ publication: Publication?, at link: Link, sender: UIViewController) async throws -> Book { + func opdsDownloadPublication( + _ publication: Publication?, + at link: ReadiumShared.Link, + sender: UIViewController + ) async throws -> Book { guard let url = link.url(relativeTo: publication?.baseURL).absoluteURL else { throw OPDSError.invalidURL(link.href) }