Skip to content

Commit 892d5f5

Browse files
authored
Fix reporting the current locator when submitting new preferences (#474)
1 parent a014d59 commit 892d5f5

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ All notable changes to this project will be documented in this file. Take a look
4444

4545
* Optimized scrolling to an EPUB text-based locator if it contains a CSS selector.
4646
* 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.
47+
* [#471](https://github.com/readium/swift-toolkit/issues/471) EPUB: Fixed reporting the current location when submitting new preferences.
4748

4849

4950
## [3.0.0-alpha.1]

Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Navigator/EPUB/Assets/Static/scripts/readium-reflowable.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Navigator/EPUB/EPUBReflowableSpreadView.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ final class EPUBReflowableSpreadView: EPUBSpreadView {
336336
previousProgression = progression
337337
}
338338
progression = newProgression
339+
340+
setNeedsNotifyPagesDidChange()
341+
}
342+
343+
private func setNeedsNotifyPagesDidChange() {
344+
// Makes sure we always receive the "ending scroll" event.
345+
// ie. https://stackoverflow.com/a/1857162/1474476
346+
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(notifyPagesDidChange), object: nil)
347+
perform(#selector(notifyPagesDidChange), with: nil, afterDelay: 0.3)
339348
}
340349

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

371380
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
372381
super.scrollViewDidScroll(scrollView)
373-
374-
// Makes sure we always receive the "ending scroll" event.
375-
// ie. https://stackoverflow.com/a/1857162/1474476
376-
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(notifyPagesDidChange), object: nil)
377-
perform(#selector(notifyPagesDidChange), with: nil, afterDelay: 0.3)
382+
setNeedsNotifyPagesDidChange()
378383
}
379384
}

Sources/Navigator/EPUB/Scripts/src/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ window.addEventListener(
2727
function () {
2828
const observer = new ResizeObserver(() => {
2929
appendVirtualColumnIfNeeded();
30+
onScroll();
3031
});
3132
observer.observe(document.body);
3233

@@ -79,7 +80,9 @@ function update(position) {
7980
webkit.messageHandlers.progressionChanged.postMessage(positionString);
8081
}
8182

82-
window.addEventListener("scroll", function () {
83+
window.addEventListener("scroll", onScroll);
84+
85+
function onScroll() {
8386
last_known_scrollY_position =
8487
window.scrollY / document.scrollingElement.scrollHeight;
8588
// Using Math.abs because for RTL books, the value will be negative.
@@ -106,7 +109,7 @@ window.addEventListener("scroll", function () {
106109
});
107110
}
108111
ticking = true;
109-
});
112+
}
110113

111114
document.addEventListener(
112115
"selectionchange",

TestApp/Sources/App/AppModule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final class AppModule {
5454
opds = OPDSModule(delegate: self)
5555

5656
// Set Readium 2's logging minimum level.
57-
ReadiumEnableLog(withMinimumSeverityLevel: .trace)
57+
ReadiumEnableLog(withMinimumSeverityLevel: .warning)
5858
}
5959

6060
private(set) lazy var aboutViewController: UIViewController = {

0 commit comments

Comments
 (0)