Skip to content

Commit

Permalink
Use Density hack to improve swipe dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Oct 20, 2024
1 parent e743cf3 commit b103bd8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.capyreader.app.common.openLinkExternally
import com.capyreader.app.ui.articles.ArticleActions
import com.capyreader.app.ui.articles.LocalArticleActions
import com.capyreader.app.ui.articles.list.ArticleRowSwipeState.SwipeAction
import com.capyreader.app.ui.components.rememberNoFlingSwipeToDismissBoxState
import com.capyreader.app.ui.settings.panels.RowSwipeOption
import com.jocmp.capy.Article
import org.koin.compose.koinInject
Expand All @@ -50,7 +51,7 @@ internal fun rememberArticleRowSwipeState(
appPreferences: AppPreferences = koinInject(),
): ArticleRowSwipeState {
val actions = LocalArticleActions.current
val state = rememberSwipeToDismissBoxState()
val state = rememberNoFlingSwipeToDismissBoxState()
val context = LocalContext.current
val swipeStart by appPreferences.articleListOptions.swipeStart.asState()
val swipeEnd by appPreferences.articleListOptions.swipeEnd.asState()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.capyreader.app.ui.components

import androidx.compose.material3.SwipeToDismissBoxDefaults
import androidx.compose.material3.SwipeToDismissBoxState
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.runtime.Composable
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.unit.Density

// https://issuetracker.google.com/issues/252334353#comment16
@Composable
fun rememberNoFlingSwipeToDismissBoxState(
initialValue: SwipeToDismissBoxValue = SwipeToDismissBoxValue.Settled,
confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true },
positionalThreshold: (totalDistance: Float) -> Float =
SwipeToDismissBoxDefaults.positionalThreshold,
): SwipeToDismissBoxState {
val density = Density(Float.POSITIVE_INFINITY) // LocalDensity.current
return rememberSaveable(
saver = SwipeToDismissBoxState.Saver(
confirmValueChange = confirmValueChange,
density = density,
positionalThreshold = positionalThreshold
)
) {
SwipeToDismissBoxState(initialValue, density, confirmValueChange, positionalThreshold)
}
}

0 comments on commit b103bd8

Please sign in to comment.