1
1
package com.squareup.workflow1.traceviewer.ui
2
2
3
+ import androidx.compose.foundation.MutatePriority
3
4
import androidx.compose.foundation.clickable
5
+ import androidx.compose.foundation.gestures.awaitEachGesture
6
+ import androidx.compose.foundation.gestures.scrollBy
4
7
import androidx.compose.foundation.layout.padding
5
8
import androidx.compose.foundation.lazy.LazyRow
6
9
import androidx.compose.foundation.lazy.rememberLazyListState
7
10
import androidx.compose.foundation.shape.RoundedCornerShape
8
11
import androidx.compose.material.Surface
9
12
import androidx.compose.material.Text
10
13
import androidx.compose.runtime.Composable
14
+ import androidx.compose.runtime.rememberCoroutineScope
11
15
import androidx.compose.ui.Modifier
12
16
import androidx.compose.ui.draw.clip
13
17
import androidx.compose.ui.graphics.Color
18
+ import androidx.compose.ui.input.pointer.PointerEventType
19
+ import androidx.compose.ui.input.pointer.pointerInput
14
20
import androidx.compose.ui.unit.dp
15
21
import com.squareup.workflow1.traceviewer.model.Node
22
+ import kotlinx.coroutines.launch
16
23
17
24
/* *
18
25
* A trace tab selector that allows devs to switch between different states within the provided trace.
@@ -24,17 +31,30 @@ internal fun FrameSelectTab(
24
31
onIndexChange : (Int ) -> Unit ,
25
32
modifier : Modifier = Modifier
26
33
) {
27
- val state = rememberLazyListState()
34
+ val lazyListState = rememberLazyListState()
35
+ val coroutineScope = rememberCoroutineScope()
28
36
29
37
Surface (
30
- modifier = modifier
31
- .padding(4 .dp),
38
+ modifier = modifier,
32
39
color = Color .White ,
33
40
) {
34
41
LazyRow (
42
+ state = lazyListState,
35
43
modifier = Modifier
36
- .padding(8 .dp),
37
- state = state
44
+ .padding(8 .dp)
45
+ .pointerInput(Unit ) {
46
+ awaitEachGesture {
47
+ val event = awaitPointerEvent()
48
+ if (event.type == PointerEventType .Scroll ) {
49
+ val scrollDeltaY = event.changes.first().scrollDelta.y
50
+ coroutineScope.launch {
51
+ lazyListState.scroll(MutatePriority .Default ) {
52
+ scrollBy(scrollDeltaY * 10f )
53
+ }
54
+ }
55
+ }
56
+ }
57
+ },
38
58
) {
39
59
items(frames.size) { index ->
40
60
Text (
0 commit comments