Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
var resourceUrl: AbsoluteUrl? = null

internal val scrollModeFlow = MutableStateFlow(false)
internal val scrollModeDisableSwipePaginationFlow = MutableStateFlow(false)

/** Indicates that a user text selection is active. */
internal var isSelecting = false

val scrollMode: Boolean get() = scrollModeFlow.value
private val scrollModeDisableSwipePagination: Boolean get() = this.scrollModeDisableSwipePaginationFlow.value

var callback: OnOverScrolledCallback? = null

Expand Down Expand Up @@ -213,6 +215,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 +249,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 +400,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 while using scroll mode (above).
*/
var scrollModeDisableSwipePagination: 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(),
scrollModeDisableSwipePagination: Boolean = false,
selectionActionModeCallback: ActionMode.Callback? = null,
shouldApplyInsetsPadding: Boolean? = true,
) : this(
servedAssets = servedAssets,
readiumCssRsProperties = readiumCssRsProperties,
decorationTemplates = decorationTemplates,
scrollModeDisableSwipePagination = scrollModeDisableSwipePagination,
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 Expand Up @@ -148,6 +147,8 @@ internal class EpubNavigatorViewModel(
}

fun onResourceLoaded(webView: R2BasicWebView, link: Link): RunScriptCommand {
webView.scrollModeDisableSwipePaginationFlow.value = config.scrollModeDisableSwipePagination

val templates = decorationTemplates.toJSON().toString()
.replace("\\n", " ")
var script = "readium.registerDecorationTemplates($templates);\n"
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