Hi everyone! I'm currently integrating <Roborazzi>...
# compose
j
Hi everyone! I'm currently integrating Roborazzi in my app to start having a golden for our design system. I'm facing an issue where I'm not being able to capture a screenshot for the "Pressed" mode. Has anyone done this? I'll leave more details on the šŸ§µ
Test:
Copy code
@Test
    fun primaryButtonPressed() {
        composeTestRule.setTestContent {
            TextButton(
                onClick = { },
                modifier = Modifier.testTag("tag")
            ) {
                Text(text = "Button")
            }
        }

        composeTestRule
            .onNodeWithTag("tag")
            .performTouchInput {
                down(Offset.Zero)
            }
            .captureRoboImage()
    }
Expected image is the first, what I actually get from roborazzi is the second.
Is this possible to achieve? I was hoping to be able to screenshot the pressed state. We have our custom behaviour, but the example uses the default material components
d
The best way to do this is to use a MutableInteraction source and emit a Press event via a LaunchedEffect on the screenshot test. Roborazzi should wait for idle so this will update before the screenshot is taken
Copy code
val interactionSource = remember { MutableInteractionSource() }
        
        Button(onClick = {}, interactionSource = interactionSource) {
            Text(text = "Label")
        }
        
        LaunchedEffect(Unit) {
            interactionSource.emit(PressInteraction.Press(Offset(0f, 0f)))
        }
j
This works perfectly. Thank you so much for the input!
t
It seems that this topic is included in I/O.

https://youtu.be/JvbyGcqdWBA?t=1102ā–¾

šŸ™Œ 1