From 1cf1b34e7f32d71e3508f81e8348ff522d389109 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:03:33 +0700 Subject: [PATCH] Fix regular scrollbar (#8139) At some point the scrollbar stops responding to scroll changes. Not too confident with this fix but it works. --- .../eu/kanade/presentation/util/Scrollbar.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/util/Scrollbar.kt b/app/src/main/java/eu/kanade/presentation/util/Scrollbar.kt index 3b1644f016..38b9f6886d 100644 --- a/app/src/main/java/eu/kanade/presentation/util/Scrollbar.kt +++ b/app/src/main/java/eu/kanade/presentation/util/Scrollbar.kt @@ -48,12 +48,11 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.composed -import androidx.compose.ui.draw.CacheDrawScope -import androidx.compose.ui.draw.DrawResult -import androidx.compose.ui.draw.drawWithCache +import androidx.compose.ui.draw.drawWithContent import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.drawscope.ContentDrawScope import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.NestedScrollSource @@ -117,13 +116,11 @@ private fun Modifier.drawScrollbar( orientation, reverseDirection, atEnd, showScrollbar, thickness, color, alpha, thumbSize, startOffset, positionOffset, ) - onDrawWithContent { - drawContent() - drawScrollbar() - } + drawContent() + drawScrollbar() } -private fun CacheDrawScope.onDrawScrollbar( +private fun ContentDrawScope.onDrawScrollbar( orientation: Orientation, reverseDirection: Boolean, atEnd: Boolean, @@ -167,13 +164,13 @@ private fun CacheDrawScope.onDrawScrollbar( private fun Modifier.drawScrollbar( orientation: Orientation, reverseScrolling: Boolean, - onBuildDrawCache: CacheDrawScope.( + onDraw: ContentDrawScope.( reverseDirection: Boolean, atEnd: Boolean, thickness: Float, color: Color, alpha: () -> Float, - ) -> DrawResult, + ) -> Unit, ): Modifier = composed { val scrolled = remember { MutableSharedFlow( @@ -216,8 +213,8 @@ private fun Modifier.drawScrollbar( val color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.364f) Modifier .nestedScroll(nestedScrollConnection) - .drawWithCache { - onBuildDrawCache(reverseDirection, atEnd, thickness, color, alpha::value) + .drawWithContent { + onDraw(reverseDirection, atEnd, thickness, color, alpha::value) } }