Skip to content
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

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
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 scrollModeDisableSwipePagination: 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 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
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ internal class R2EpubPageFragment : Fragment() {
}
}

webView.scrollModeDisableSwipePagination =
navigator?.config?.scrollModeDisableSwipePagination ?: 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