Skip to content

feat: add option to disable horizontal swiping when scroll is true. #624

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

Merged
merged 5 commits into from
Mar 24, 2025
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file. Take a look

### Added

#### Navigator

* The `EpubNavigatorFragment.Configuration.disablePageTurnsWhileScrolling` property disables horizontal swipes for navigating to previous or next resources when scroll mode is enabled. When set to `true`, you must implement your own mechanism to move to the next resource (contributed by [@tm-bookshop](https://github.com/readium/kotlin-toolkit/pull/624)).

#### Streamer

* The EPUB 2 `<guide>` element is now parsed into the RWPM `landmarks` subcollection when no EPUB 3 `landmarks` navigation document is declared (contributed by [@erkasraim](https://github.com/readium/kotlin-toolkit/pull/628)).

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
internal var isSelecting = false

val scrollMode: Boolean get() = scrollModeFlow.value
var disablePageTurnsWhileScrolling: Boolean = false

var callback: OnOverScrolledCallback? = null

Expand Down Expand Up @@ -213,6 +214,9 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
}

when {
// If the user is in scrollMode and has disabled swipe pagination, do nothing.
scrollMode && [email protected] -> {}

scrollMode ->
goRight(jump = true)

Expand Down Expand Up @@ -244,6 +248,9 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
}

when {
// If the user is in scrollMode and has disabled swipe pagination, do nothing.
scrollMode && [email protected] -> {}

scrollMode ->
goLeft(jump = true)

Expand Down Expand Up @@ -392,7 +399,6 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
fun onDragEnd(eventJson: String): Boolean {
val event = DragEvent.fromJSON(eventJson)?.takeIf { it.isValid }
?: return false

return runBlocking(uiScope.coroutineContext) { listener?.onDragEnd(event) ?: false }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public class EpubNavigatorFragment internal constructor(
*/
var decorationTemplates: HtmlDecorationTemplates,

/**
* Indicates if a user can swipe to change resources when scroll is enabled.
*/
var disablePageTurnsWhileScrolling: Boolean,

/**
* Custom [ActionMode.Callback] to be used when the user selects content.
*
Expand Down Expand Up @@ -210,12 +215,14 @@ public class EpubNavigatorFragment internal constructor(
servedAssets: List<String> = emptyList(),
readiumCssRsProperties: RsProperties = RsProperties(),
decorationTemplates: HtmlDecorationTemplates = HtmlDecorationTemplates.defaultTemplates(),
disablePageTurnsWhileScrolling: Boolean = false,
selectionActionModeCallback: ActionMode.Callback? = null,
shouldApplyInsetsPadding: Boolean? = true,
) : this(
servedAssets = servedAssets,
readiumCssRsProperties = readiumCssRsProperties,
decorationTemplates = decorationTemplates,
disablePageTurnsWhileScrolling = disablePageTurnsWhileScrolling,
selectionActionModeCallback = selectionActionModeCallback,
shouldApplyInsetsPadding = shouldApplyInsetsPadding,
disableSelectionWhenProtected = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ internal class EpubNavigatorViewModel(

private val _settings: MutableStateFlow<EpubSettings> =
MutableStateFlow(settingsPolicy.settings(initialPreferences))

val settings: StateFlow<EpubSettings> = _settings.asStateFlow()

val overflow: StateFlow<OverflowableNavigator.Overflow> = _settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ internal class R2EpubPageFragment : Fragment() {
}
}

webView.disablePageTurnsWhileScrolling =
navigator?.config?.disablePageTurnsWhileScrolling ?: false
webView.settings.javaScriptEnabled = true
webView.isVerticalScrollBarEnabled = false
webView.isHorizontalScrollBarEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import androidx.viewpager.widget.ViewPager;

import org.readium.r2.navigator.preferences.ReadingProgression;
import org.readium.r2.shared.ExperimentalReadiumApi;

import java.util.HashMap;

Expand Down