Skip to content

Commit c6cc245

Browse files
committed
Add functionality to use vertical mouse scroll to travel through row of frames
1 parent 0f3a375 commit c6cc245

File tree

1 file changed

+25
-5
lines changed
  • workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui

1 file changed

+25
-5
lines changed

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui/FrameSelectTab.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package com.squareup.workflow1.traceviewer.ui
22

3+
import androidx.compose.foundation.MutatePriority
34
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.gestures.awaitEachGesture
6+
import androidx.compose.foundation.gestures.scrollBy
47
import androidx.compose.foundation.layout.padding
58
import androidx.compose.foundation.lazy.LazyRow
69
import androidx.compose.foundation.lazy.rememberLazyListState
710
import androidx.compose.foundation.shape.RoundedCornerShape
811
import androidx.compose.material.Surface
912
import androidx.compose.material.Text
1013
import androidx.compose.runtime.Composable
14+
import androidx.compose.runtime.rememberCoroutineScope
1115
import androidx.compose.ui.Modifier
1216
import androidx.compose.ui.draw.clip
1317
import androidx.compose.ui.graphics.Color
18+
import androidx.compose.ui.input.pointer.PointerEventType
19+
import androidx.compose.ui.input.pointer.pointerInput
1420
import androidx.compose.ui.unit.dp
1521
import com.squareup.workflow1.traceviewer.model.Node
22+
import kotlinx.coroutines.launch
1623

1724
/**
1825
* A trace tab selector that allows devs to switch between different states within the provided trace.
@@ -24,17 +31,30 @@ internal fun FrameSelectTab(
2431
onIndexChange: (Int) -> Unit,
2532
modifier: Modifier = Modifier
2633
) {
27-
val state = rememberLazyListState()
34+
val lazyListState = rememberLazyListState()
35+
val coroutineScope = rememberCoroutineScope()
2836

2937
Surface(
30-
modifier = modifier
31-
.padding(4.dp),
38+
modifier = modifier,
3239
color = Color.White,
3340
) {
3441
LazyRow(
42+
state = lazyListState,
3543
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+
},
3858
) {
3959
items(frames.size) { index ->
4060
Text(

0 commit comments

Comments
 (0)