Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private fun ActivityScenario<out ComponentActivity>.captureRoboImage(
doBeforeCapture: () -> Unit = {},
content: @Composable () -> Unit,
) {

onActivity { activity ->
activity.setContent(content = { content() })
captureScreenIfMultipleWindows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.dropbox.differ.ImageComparator
import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.hamcrest.core.IsEqual
import org.robolectric.shadows.ShadowLooper
import java.io.File
import java.util.Locale

Expand Down Expand Up @@ -179,6 +180,17 @@ fun captureScreenIfMultipleWindows(
roborazziOptions: RoborazziOptions,
captureSingleComponent: () -> Unit
) {
// We need to wait for the main looper to be idle because the dialogs will be added to the window
// https://github.com/takahirom/roborazzi/issues/694
try {
ShadowLooper.shadowMainLooper().idle()
} catch (e: NoClassDefFoundError) {
// This should not happen if you are using Robolectric.
// If you have a use case where you need to capture the screen without Robolectric,
// let us know.
e.printStackTrace()
}

if (fetchRobolectricWindowRoots().size > 1) {
roborazziReportLog(
"It seems that there are multiple windows." +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.takahirom.preview.tests

import android.annotation.SuppressLint
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
Expand All @@ -28,6 +30,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.SubcomposeLayout
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.Wallpapers
Expand Down Expand Up @@ -314,3 +317,37 @@ fun PreviewDelayed() {
CircularProgressIndicator()
}
}

// https://github.com/takahirom/roborazzi/issues/694
@Preview
@Composable
fun PreviewDialogSubcompose() {
SubcomposeLayout { _ ->
subcompose(Unit) {
MaterialTheme {
AlertDialog(
onDismissRequest = {},
confirmButton = @Composable { Text("Confirm") },
text = @Composable { Text("Dialog wrapped by Subcompose") }
)
}
}

layout(0, 0) {}
}
}

@SuppressLint("UnusedBoxWithConstraintsScope")
@Preview
@Composable
fun PreviewDialogBoxWithConstraints() {
BoxWithConstraints {
MaterialTheme {
AlertDialog(
onDismissRequest = {},
confirmButton = @Composable { Text("Confirm") },
text = @Composable { Text("Dialog wrapped by BoxWithConstraints") }
)
}
}
}
Loading