Skip to content

Commit

Permalink
Fix reporting the current locator when submitting new preferences (re…
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Aug 27, 2024
1 parent a014d59 commit 892d5f5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ All notable changes to this project will be documented in this file. Take a look

* Optimized scrolling to an EPUB text-based locator if it contains a CSS selector.
* The first resource of a fixed-layout EPUB is now displayed on its own when spreads are enabled and the author has not set a `page-spread-*` property. This is the default behavior in major reading apps like Apple Books.
* [#471](https://github.com/readium/swift-toolkit/issues/471) EPUB: Fixed reporting the current location when submitting new preferences.


## [3.0.0-alpha.1]
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions Sources/Navigator/EPUB/EPUBReflowableSpreadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ final class EPUBReflowableSpreadView: EPUBSpreadView {
previousProgression = progression
}
progression = newProgression

setNeedsNotifyPagesDidChange()
}

private func setNeedsNotifyPagesDidChange() {
// Makes sure we always receive the "ending scroll" event.
// ie. https://stackoverflow.com/a/1857162/1474476
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(notifyPagesDidChange), object: nil)
perform(#selector(notifyPagesDidChange), with: nil, afterDelay: 0.3)
}

@objc private func notifyPagesDidChange() {
Expand Down Expand Up @@ -370,10 +379,6 @@ final class EPUBReflowableSpreadView: EPUBSpreadView {

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
super.scrollViewDidScroll(scrollView)

// Makes sure we always receive the "ending scroll" event.
// ie. https://stackoverflow.com/a/1857162/1474476
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(notifyPagesDidChange), object: nil)
perform(#selector(notifyPagesDidChange), with: nil, afterDelay: 0.3)
setNeedsNotifyPagesDidChange()
}
}
7 changes: 5 additions & 2 deletions Sources/Navigator/EPUB/Scripts/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ window.addEventListener(
function () {
const observer = new ResizeObserver(() => {
appendVirtualColumnIfNeeded();
onScroll();
});
observer.observe(document.body);

Expand Down Expand Up @@ -79,7 +80,9 @@ function update(position) {
webkit.messageHandlers.progressionChanged.postMessage(positionString);
}

window.addEventListener("scroll", function () {
window.addEventListener("scroll", onScroll);

function onScroll() {
last_known_scrollY_position =
window.scrollY / document.scrollingElement.scrollHeight;
// Using Math.abs because for RTL books, the value will be negative.
Expand All @@ -106,7 +109,7 @@ window.addEventListener("scroll", function () {
});
}
ticking = true;
});
}

document.addEventListener(
"selectionchange",
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Sources/App/AppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class AppModule {
opds = OPDSModule(delegate: self)

// Set Readium 2's logging minimum level.
ReadiumEnableLog(withMinimumSeverityLevel: .trace)
ReadiumEnableLog(withMinimumSeverityLevel: .warning)
}

private(set) lazy var aboutViewController: UIViewController = {
Expand Down

0 comments on commit 892d5f5

Please sign in to comment.