ChapterNavigator: Fix haptic feedback (#9458)

This commit is contained in:
Ivan Iskandar 2023-05-06 09:15:56 +07:00 committed by GitHub
parent 08e4863d94
commit fce9cb820c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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())