@@ -4,11 +4,12 @@ import androidx.compose.animation.AnimatedContent
44import androidx.compose.animation.SizeTransform
55import androidx.compose.animation.fadeIn
66import androidx.compose.animation.fadeOut
7- import androidx.compose.animation.slideInVertically
8- import androidx.compose.animation.slideOutVertically
7+ import androidx.compose.animation.slideInHorizontally
8+ import androidx.compose.animation.slideOutHorizontally
99import androidx.compose.animation.togetherWith
1010import androidx.compose.foundation.background
1111import androidx.compose.foundation.clickable
12+ import androidx.compose.foundation.gestures.detectHorizontalDragGestures
1213import androidx.compose.foundation.layout.Arrangement
1314import androidx.compose.foundation.layout.Box
1415import androidx.compose.foundation.layout.Row
@@ -24,11 +25,13 @@ import androidx.compose.runtime.Composable
2425import androidx.compose.ui.Alignment
2526import androidx.compose.ui.Modifier
2627import androidx.compose.ui.draw.clip
28+ import androidx.compose.ui.input.pointer.pointerInput
2729import androidx.compose.ui.text.font.FontWeight
2830import androidx.compose.ui.text.style.TextAlign
2931import androidx.compose.ui.text.style.TextOverflow
3032import androidx.compose.ui.unit.dp
3133import dev.vivvvek.seeker.Segment
34+ import `is`.xyz.mpv.MPVLib
3235import `is`.xyz.mpv.Utils
3336import live.mehiz.mpvkt.ui.theme.spacing
3437
@@ -43,17 +46,41 @@ fun CurrentChapter(
4346 .clip(RoundedCornerShape (25 ))
4447 .background(MaterialTheme .colorScheme.background.copy(alpha = 0.6F ))
4548 .clickable(onClick = onClick)
49+ .pointerInput(Unit ) {
50+ var totalDrag = 0f
51+ val swipeThreshold = 100f
52+ detectHorizontalDragGestures(
53+ onHorizontalDrag = { change, dragAmount ->
54+ change.consume()
55+ totalDrag + = dragAmount
56+ },
57+ onDragEnd = {
58+ val current = MPVLib .getPropertyInt(" chapter" ) ? : 0
59+ when {
60+ totalDrag > swipeThreshold -> {
61+ // Previous chapter
62+ MPVLib .setPropertyInt(" chapter" , (current - 1 ).coerceAtLeast(0 ))
63+ }
64+ totalDrag < - swipeThreshold -> {
65+ // Next chapter
66+ MPVLib .setPropertyInt(" chapter" , (current + 1 ))
67+ }
68+ }
69+ totalDrag = 0f
70+ }
71+ )
72+ }
4673 .padding(horizontal = MaterialTheme .spacing.small, vertical = MaterialTheme .spacing.smaller),
4774 ) {
4875 AnimatedContent (
4976 targetState = chapter,
5077 transitionSpec = {
5178 if (targetState.start > initialState.start) {
52- (slideInVertically { height -> height } + fadeIn())
53- .togetherWith(slideOutVertically { height -> - height } + fadeOut())
79+ (slideInHorizontally { width -> width } + fadeIn())
80+ .togetherWith(slideOutHorizontally { width -> - width } + fadeOut())
5481 } else {
55- (slideInVertically { height -> - height } + fadeIn())
56- .togetherWith(slideOutVertically { height -> height } + fadeOut())
82+ (slideInHorizontally { width -> - width } + fadeIn())
83+ .togetherWith(slideOutHorizontally { width -> width } + fadeOut())
5784 }.using(
5885 SizeTransform (clip = false ),
5986 )
0 commit comments