@@ -17,6 +17,7 @@ import androidx.compose.ui.geometry.Offset
17
17
import androidx.compose.ui.graphics.graphicsLayer
18
18
import androidx.compose.ui.input.pointer.PointerEventType
19
19
import androidx.compose.ui.input.pointer.pointerInput
20
+ import com.squareup.workflow1.traceviewer.SandboxState
20
21
21
22
/* *
22
23
* This is the backdrop for the whole app. Since there can be hundreds of modules at a time, there
@@ -27,19 +28,17 @@ import androidx.compose.ui.input.pointer.pointerInput
27
28
*/
28
29
@Composable
29
30
public fun SandboxBackground (
31
+ sandboxState : SandboxState ,
30
32
modifier : Modifier = Modifier ,
31
33
content : @Composable () -> Unit ,
32
34
) {
33
- var scale by remember { mutableFloatStateOf(1f ) }
34
- var offset by remember { mutableStateOf(Offset .Zero ) }
35
-
36
35
Box (
37
36
modifier
38
37
.fillMaxSize()
39
38
.pointerInput(Unit ) {
40
39
// Panning capabilities: watches for drag gestures and applies the translation
41
40
detectDragGestures { _, translation ->
42
- offset + = translation
41
+ sandboxState. offset + = translation
43
42
}
44
43
}
45
44
.pointerInput(Unit ) {
@@ -49,8 +48,8 @@ public fun SandboxBackground(
49
48
val event = awaitPointerEvent()
50
49
if (event.type == PointerEventType .Scroll ) {
51
50
val scrollDelta = event.changes.first().scrollDelta.y
52
- scale * = if (scrollDelta < 0 ) 1.1f else 0.9f
53
- scale = scale .coerceIn(0.1f , 10f )
51
+ sandboxState. scale = (sandboxState.scale * if (scrollDelta < 0 ) 1.1f else 0.9f )
52
+ .coerceIn(0.1f , 10f )
54
53
event.changes.forEach { it.consume() }
55
54
}
56
55
}
@@ -60,10 +59,10 @@ public fun SandboxBackground(
60
59
modifier = Modifier
61
60
.wrapContentSize(unbounded = true , align = Alignment .Center )
62
61
.graphicsLayer {
63
- translationX = offset.x
64
- translationY = offset.y
65
- scaleX = scale
66
- scaleY = scale
62
+ translationX = sandboxState. offset.x
63
+ translationY = sandboxState. offset.y
64
+ scaleX = sandboxState. scale
65
+ scaleY = sandboxState. scale
67
66
}
68
67
) {
69
68
content()
0 commit comments