Fix weird C crash on snaping scroll.
This commit is contained in:
parent
b9d14d12ff
commit
9dbfb9c3a0
1 changed files with 14 additions and 10 deletions
|
|
@ -73,7 +73,6 @@ import com.skydoves.landscapist.ImageOptions
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlin.math.max
|
||||
|
||||
@Stable
|
||||
|
|
@ -459,21 +458,26 @@ private fun rememberSnapConnection(
|
|||
@Composable
|
||||
@Stable
|
||||
private fun rememberScrollConnection(
|
||||
scope: CoroutineScope = rememberCoroutineScope(),
|
||||
scrollState: ScrollState,
|
||||
): NestedScrollConnection {
|
||||
return remember(scrollState) {
|
||||
object : NestedScrollConnection {
|
||||
override fun onPreScroll(
|
||||
available: Offset,
|
||||
source: NestedScrollSource
|
||||
): Offset = runBlocking {
|
||||
Offset(
|
||||
x = 0f,
|
||||
y = when (scrollState.canScrollForward) {
|
||||
true -> -scrollState.scrollBy(-available.y)
|
||||
else -> 0f
|
||||
},
|
||||
)
|
||||
source: NestedScrollSource,
|
||||
): Offset {
|
||||
val delta = when {
|
||||
scrollState.value == 0 && available.y > 0f -> 0f
|
||||
|
||||
scrollState.value == scrollState.maxValue -> 0f
|
||||
|
||||
else -> {
|
||||
scope.launch { scrollState.scrollBy(-available.y) }
|
||||
available.y
|
||||
}
|
||||
}
|
||||
return Offset(x = 0f, y = delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue