mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 08:37:48 +01:00
WheelPicker: Add haptic feedback (#9322)
This commit is contained in:
parent
6662a97b2f
commit
a2627d70af
1 changed files with 6 additions and 0 deletions
|
@ -25,10 +25,13 @@ import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
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.DpSize
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.drop
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import tachiyomi.presentation.core.components.material.padding
|
import tachiyomi.presentation.core.components.material.padding
|
||||||
import java.text.DateFormatSymbols
|
import java.text.DateFormatSymbols
|
||||||
|
@ -48,12 +51,15 @@ fun WheelPicker(
|
||||||
itemContent: @Composable LazyItemScope.(index: Int) -> Unit,
|
itemContent: @Composable LazyItemScope.(index: Int) -> Unit,
|
||||||
) {
|
) {
|
||||||
val lazyListState = rememberLazyListState(startIndex)
|
val lazyListState = rememberLazyListState(startIndex)
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
|
||||||
LaunchedEffect(lazyListState, onSelectionChanged) {
|
LaunchedEffect(lazyListState, onSelectionChanged) {
|
||||||
snapshotFlow { lazyListState.firstVisibleItemScrollOffset }
|
snapshotFlow { lazyListState.firstVisibleItemScrollOffset }
|
||||||
.map { calculateSnappedItemIndex(lazyListState) }
|
.map { calculateSnappedItemIndex(lazyListState) }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
.drop(1)
|
||||||
.collectLatest {
|
.collectLatest {
|
||||||
|
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)
|
||||||
onSelectionChanged(it)
|
onSelectionChanged(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue