Skip to content

Commit

Permalink
Fixed some problems
Browse files Browse the repository at this point in the history
Scroll position and file loading
  • Loading branch information
g-cqd committed Mar 6, 2024
1 parent 18eebd2 commit 4a129e5
Show file tree
Hide file tree
Showing 29 changed files with 518 additions and 306 deletions.
2 changes: 1 addition & 1 deletion Bilbary for iPad/Bilbary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Bilbary: App {

init() {
do {
dataModel.container = try ModelContainer(for: Book.self, BookProgress.self)
dataModel.container = try ModelContainer(for: Book.self, BookSession.self)
} catch {
fatalError(
"Something happened when creating the model container."
Expand Down
26 changes: 26 additions & 0 deletions Bilbary for iPad/Views/Components/BlurTransition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// BlurTransition.swift
// Bilbary
//
// Created by Guillaume Coquard on 06/03/24.
//

import SwiftUI

struct BlurTransition: ViewModifier {
let blurValue: CGFloat

func body(content: Content) -> some View {
content
.blur(radius: blurValue)
}
}

extension AnyTransition {
static var blur: AnyTransition {
.modifier(
active: BlurTransition(blurValue: 20),
identity: BlurTransition(blurValue: 0)
)
}
}
83 changes: 65 additions & 18 deletions Bilbary for iPad/Views/EPUB/EPUBScrollableContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import OSLog

struct EPUBScrollableContent: View {

Expand All @@ -16,36 +17,82 @@ struct EPUBScrollableContent: View {

var book: Book

private var session: BookProgress? {
private var session: BookSession? {
read.currentSession
}

var body: some View {
VStack {
ScrollView {
VStack {
ForEach(book.content.strings.prefix(10), id: \.self) { paragraph in
VStack(alignment: .leading, spacing: 0) {
Text(
cust.style.present(
paragraph
)
)
.lineSpacing( cust.lineHeight )
.padding(.bottom, cust.paragraphSpacing)
VStack(alignment: .leading) {
if read.selectedBook != nil {
ScrollView(.vertical) {
LazyVStack(alignment: .leading, spacing: cust.paragraphSpacing) {
ForEach(book.content.formatted, id: \.id) { paragraph in
HStack {
Text(
cust.style.present(
paragraph.content
)
)
.lineSpacing( cust.lineHeight )
.multilineTextAlignment(.leading)

Spacer()
}
.padding(.horizontal, 80)
.frame(width: view.screenWidth)
.scrollTransition(axis: .vertical, transition: {
$0
.blur(radius: $1.isIdentity ? 0 : 10)
.opacity( $1.isIdentity ? 1 : 0.5 )
})
.tag(paragraph.id)
.id(paragraph.id)
}
}
.scrollTargetLayout()
}
.overlay {
ZStack {
VStack {
LinearGradient(colors: [
Color.userDefinedBackground,
Color.clear,
Color.clear,
Color.clear
], startPoint: .top, endPoint: .center)
Spacer()
}
.frame(maxWidth: .infinity)

VStack {
Spacer()
LinearGradient(colors: [
Color.userDefinedBackground,
Color.clear,
Color.clear
], startPoint: .bottom, endPoint: .center)
}
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
.padding(.vertical)
.allowsHitTesting(false)
}
.defaultScrollAnchor(.top)
.scrollPosition(id: $read.currentParagraphId, anchor: .center)
.scrollIndicators(.never)
.frame(minHeight: 200)
.padding(0)
.padding(.vertical)
} else {
Spacer()
EmptyView()
Spacer()
}
.frame(minHeight: 200)
.frame(maxWidth: .infinity)
.padding(0)
}
.padding(0)
}
.defersSystemGestures(on: .horizontal)
.padding(.vertical, 0)
.padding(.horizontal, 80)
.frame(width: view.screenWidth)
.onAppear {
if let session = self.session {
Expand Down
2 changes: 1 addition & 1 deletion Bilbary for iPad/Views/EPUB/EPUBSwipeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct EPUBSwipeView: View {
.scrollTargetLayout()
}
.scrollDisabled(view.isAnyPopoverDisplayed)
.scrollPosition(id: $readModel.selectedBookHashValue, anchor: .center)
.scrollPosition(id: $readModel.selectedBookHashValue, anchor: .trailing)
.scrollClipDisabled()
.scrollTargetBehavior(.paging)
.scrollIndicators(.never)
Expand Down
6 changes: 6 additions & 0 deletions Bilbary for iPad/Views/Library/Book/BBookInfoCardStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ struct BBookInfoCardStyle: ViewModifier {
.frame(maxWidth: .infinity)
.background(.regularMaterial)
.clipShape(.rect(cornerRadius: 12))
.overlay {
RoundedRectangle(cornerRadius: 12)
.stroke(Color.black.opacity(0.1), lineWidth: 0.1)
.foregroundStyle(.clear)
}
.shadow(color: Color.black.opacity(0.2), radius: 12, y: 4)
}
}

Expand Down
1 change: 1 addition & 0 deletions Bilbary for iPad/Views/Library/LibraryContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct LibraryContentView: View {
}
Spacer()
}
.scrollClipDisabled()
.padding(.horizontal)
.navigationTitle("Library")
.navigationBarTitleDisplayMode(.automatic)
Expand Down
2 changes: 1 addition & 1 deletion Bilbary for iPad/Views/Streak/BStreakValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct BStreakValidation: View {
if !goalModel.isStreakValidated {
DispatchQueue.main.async {
withAnimation(.linear(duration: BReadModel.timerIncrement)) {
goalModel.streakValidationProgressRemaining = goalModel.streakValidationProgressRemaining - BReadModel.timerIncrement
goalModel.streakValidationProgressRemaining -= BReadModel.timerIncrement
}
}
}
Expand Down
Loading

0 comments on commit 4a129e5

Please sign in to comment.