Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart SwiftUI rewrite #460

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TestApp/Integrations/Carthage/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
sources:
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
- Resources/Fonts
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/CocoaPods/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '14.0'
platform :ios, '16.0'

target 'TestApp' do
# Comment the next line if you don't want to use dynamic frameworks
Expand All @@ -23,7 +23,7 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/CocoaPods/Podfile+lcp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '14.0'
platform :ios, '16.0'

target 'TestApp' do
# Comment the next line if you don't want to use dynamic frameworks
Expand Down Expand Up @@ -26,7 +26,7 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Local/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/Local/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
sources:
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
- Resources/Fonts
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/SPM/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/SPM/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
sources:
deploymentTarget: "16.0"
sources:
- path: Sources
excludes:
- Resources/Fonts
Expand Down
2 changes: 1 addition & 1 deletion TestApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This sample application demonstrates how to integrate the Readium Swift toolkit in your own reading app. Stable versions are [published on TestFlight](https://testflight.apple.com/join/lYEMEfBr).

:warning: The Readium toolkit itself supports down to iOS 11, but the Test App requires iOS 14 and Xcode 13.2.
:warning: The Readium toolkit itself supports down to iOS 13, but the Test App requires iOS 16 and Xcode 13.2.

## Features

Expand Down
40 changes: 40 additions & 0 deletions TestApp/Sources/About/Views/About.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// 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 About: View {
var body: some View {
VStack(alignment: .leading, spacing: 20) {
Text("Version")
.font(.title2)
HStack(spacing: 10) {
Text("Version").frame(width: 170.0, alignment: .leading)
Text("2.3.0")
}
HStack(spacing: 10) {
Text("Build").frame(width: 170.0, alignment: .leading)
Text("1")
}
Text("Copyright").font(.title2)
Link("© 2022 European Digital Reading Lab",
destination: URL(string: "https://www.edrlab.org/")!)
Link("[BSD-3 License]",
destination: URL(string: "https://opensource.org/licenses/BSD-3-Clause")!)
Text("Acknowledgements").font(.title2)
Text("R2 Reader wouldn't have been developed without the financial help of the French State.")
Image("rf")
}
.padding()
.navigationTitle("About")
}
}

struct About_Previews: PreviewProvider {
static var previews: some View {
About()
}
}
2 changes: 1 addition & 1 deletion TestApp/Sources/App/AppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class AppModule {

init() throws {
let file = Paths.library.appendingPath("database.db", isDirectory: false)
let db = try Database(file: file.url)
let db = try Database(file: file.url, migrations: [InitialMigration()])
print("Created database at \(file.path)")

let books = BookRepository(db: db)
Expand Down
48 changes: 48 additions & 0 deletions TestApp/Sources/Bookshelf/Views/AddBookSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// 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 AddBookSheet: View {
@Environment(\.dismiss) private var dismiss
var action: (String) -> Void

@State var url: String = ""

var body: some View {
NavigationStack {
Form {
TextField("URL", text: $url)
.keyboardType(.URL)
.autocapitalization(.none)
}
.navigationTitle("Add a Book")
.toolbar(content: toolbarContent)
}
}

@ToolbarContentBuilder
private func toolbarContent() -> some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Button(.cancel) {
dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(.save) {
action(url)
dismiss()
}
.disabled(url.isEmpty)
}
}
}

// struct AddBookSheet_Previews: PreviewProvider {
// static var previews: some View {
// AddBookSheet(showingSheet: true)
// }
// }
62 changes: 62 additions & 0 deletions TestApp/Sources/Bookshelf/Views/Bookshelf.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// 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 ReadiumShared
import SwiftUI

struct Bookshelf: View {
let bookRepository: BookRepository
let reader: (Book) -> Reader

@State private var showingSheet = false
@State private var books: [Book] = []

var body: some View {
NavigationStack {
VStack {
// TODO: figure out what the best column layout is for phones and tablets
let columns: [GridItem] = [GridItem(.adaptive(minimum: Constant.bookCoverWidth + Constant.adaptiveGridDelta))]
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(books, id: \.self) { book in
NavigationLink(value: book) {
BookCover(title: book.title, authors: book.authors, url: book.cover?.url)
}
.buttonStyle(.plain)
}
}
// TODO: handle error
.onReceive(bookRepository.all()
.replaceError(with: [])
) { books in
self.books = books
}
}
}
.navigationTitle("Bookshelf")
.navigationDestination(for: Book.self) { book in
reader(book)
}
.toolbar(content: toolbarContent)
}
.sheet(isPresented: $showingSheet) {
AddBookSheet { url in
// TODO: validate the URL and import the book
}
}
}
}

extension Bookshelf {
@ToolbarContentBuilder
private func toolbarContent() -> some ToolbarContent {
ToolbarItem(placement: .navigationBarTrailing) {
Button(.add, action: {
showingSheet = true
})
}
}
}
55 changes: 55 additions & 0 deletions TestApp/Sources/Catalogs/Views/AddFeedSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// 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

/// Sheet to add a new OPDS catalog via a URL
struct AddFeedSheet: View {
typealias ActionCallback = ((title: String, url: String)) -> Void

@Environment(\.dismiss) private var dismiss
var action: ActionCallback

@State var title: String = ""
@State var url: String = ""

var body: some View {
NavigationStack {
Form {
Section {
TextField("Feed Title", text: $title)
TextField("URL", text: $url)
.keyboardType(.URL)
.autocapitalization(.none)
}
}
.navigationBarTitle("Add an OPDS Feed")
.toolbar(content: toolbarContent)
}
}

@ToolbarContentBuilder
private func toolbarContent() -> some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Button(.cancel) {
dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(.save) {
action((title: title, url: url))
dismiss()
}
.disabled(title.isEmpty || url.isEmpty)
}
}
}

// struct AddFeedSheet_Previews: PreviewProvider {
// static var previews: some View {
// AddFeedSheet()
// }
// }
Loading