From fce9cb820cdcba79f568e79ecb4005b512cf1d78 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 6 May 2023 09:15:56 +0700 Subject: [PATCH] ChapterNavigator: Fix haptic feedback (#9458) --- .../kanade/presentation/reader/ChapterNavigator.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt b/app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt index 3814fc30d2..a6b0f6f079 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt @@ -1,6 +1,8 @@ package eu.kanade.presentation.reader import androidx.compose.foundation.background +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsDraggedAsState import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -19,6 +21,9 @@ import androidx.compose.material3.Text import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -87,6 +92,13 @@ fun ChapterNavigator( ) { Text(text = currentPage.toString()) + val interactionSource = remember { MutableInteractionSource() } + val sliderDragged by interactionSource.collectIsDraggedAsState() + LaunchedEffect(currentPage) { + if (sliderDragged) { + haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove) + } + } Slider( modifier = Modifier .weight(1f) @@ -96,8 +108,8 @@ fun ChapterNavigator( steps = totalPages, onValueChange = { onSliderValueChange(it.toInt() - 1) - haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove) }, + interactionSource = interactionSource, ) Text(text = totalPages.toString())