From a2627d70afabecc95b7be824dd027e8d9d530e57 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 15 Apr 2023 08:58:57 +0700 Subject: [PATCH] WheelPicker: Add haptic feedback (#9322) --- .../tachiyomi/presentation/core/components/WheelPicker.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt index 093a4a8dd..2bb7d6d22 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt @@ -25,10 +25,13 @@ import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.map import tachiyomi.presentation.core.components.material.padding import java.text.DateFormatSymbols @@ -48,12 +51,15 @@ fun WheelPicker( itemContent: @Composable LazyItemScope.(index: Int) -> Unit, ) { val lazyListState = rememberLazyListState(startIndex) + val haptic = LocalHapticFeedback.current LaunchedEffect(lazyListState, onSelectionChanged) { snapshotFlow { lazyListState.firstVisibleItemScrollOffset } .map { calculateSnappedItemIndex(lazyListState) } .distinctUntilChanged() + .drop(1) .collectLatest { + haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove) onSelectionChanged(it) } }