Skip to content

Commit 3768bb5

Browse files
authored
Fix scroll inertia when scrolling an EPUB (#304)
1 parent 3b7869a commit 3768bb5

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ All notable changes to this project will be documented in this file. Take a look
5555
* `paragraphSpacing` - Vertical margins for paragraphs.
5656
* `hyphens` - Enable hyphenation.
5757
* `ligatures` - Enable ligatures in Arabic.
58+
* Fixed scroll inertia when scrolling an EPUB.
5859

5960
### Changed
6061

readium/navigator/src/main/java/org/readium/r2/navigator/R2WebView.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView(context,
186186

187187
private var mScrollState = SCROLL_STATE_IDLE
188188

189+
internal var useLegacySettings = false
190+
189191
private fun initWebPager() {
190192
setWillNotDraw(false)
191193
descendantFocusability = ViewGroup.FOCUS_AFTER_DESCENDANTS
@@ -550,6 +552,10 @@ class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView(context,
550552
}
551553

552554
override fun computeScroll() {
555+
if (!useLegacySettings && scrollMode) {
556+
return super.computeScroll()
557+
}
558+
553559
mIsScrollStarted = true
554560
if (!mScroller!!.isFinished && mScroller!!.computeScrollOffset()) {
555561
val oldX = scrollX

readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubNavigatorViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ internal class EpubNavigatorViewModel(
234234
oldSettings.readingProgression != newSettings.readingProgression ||
235235
oldSettings.language != newSettings.language ||
236236
oldSettings.verticalText != newSettings.verticalText ||
237-
oldSettings.spread != newSettings.spread
237+
oldSettings.spread != newSettings.spread ||
238+
// We need to invalidate the resource pager when changing from scroll mode to
239+
// paginated, otherwise the horizontal scroll will be broken.
240+
// See https://github.com/readium/kotlin-toolkit/pull/304
241+
oldSettings.scroll != newSettings.scroll
238242
)
239243

240244
if (needsInvalidation) {

readium/navigator/src/main/java/org/readium/r2/navigator/pager/R2EpubPageFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class R2EpubPageFragment : Fragment() {
139139
@Suppress("DEPRECATION")
140140
webView.setScrollMode(preferences.getBoolean(SCROLL_REF, false))
141141
}
142+
webView.useLegacySettings = viewModel.useLegacySettings
142143
webView.settings.javaScriptEnabled = true
143144
webView.isVerticalScrollBarEnabled = false
144145
webView.isHorizontalScrollBarEnabled = false

0 commit comments

Comments
 (0)