commonMain.app.cash.redwood.layout.testing.RedwoodLayoutTester.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redwood-layout-testing Show documentation
Show all versions of redwood-layout-testing Show documentation
Multiplatform reactive UI using Kotlin and Jetpack Compose
@file:Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
package app.cash.redwood.layout.testing
import app.cash.redwood.RedwoodCodegenApi
import app.cash.redwood.layout.widget.RedwoodLayoutWidgetSystem
import app.cash.redwood.testing.NoOpOnBackPressedDispatcher
import app.cash.redwood.testing.TestRedwoodComposition
import app.cash.redwood.testing.TestSavedState
import app.cash.redwood.testing.WidgetValue
import app.cash.redwood.ui.OnBackPressedDispatcher
import app.cash.redwood.ui.UiConfiguration
import app.cash.redwood.widget.MutableListChildren
import kotlin.OptIn
import kotlin.Suppress
import kotlin.collections.List
import kotlinx.coroutines.coroutineScope
@OptIn(RedwoodCodegenApi::class)
public suspend fun RedwoodLayoutTester(
onBackPressedDispatcher: OnBackPressedDispatcher = NoOpOnBackPressedDispatcher,
savedState: TestSavedState? = null,
uiConfiguration: UiConfiguration = UiConfiguration(),
body: suspend TestRedwoodComposition>.() -> R,
): R = coroutineScope {
val widgetSystem = RedwoodLayoutWidgetSystem(
RedwoodLayout = RedwoodLayoutTestingWidgetFactory(),
)
val container = MutableListChildren()
val tester = TestRedwoodComposition(this, widgetSystem, container, onBackPressedDispatcher,
savedState, uiConfiguration) {
container.map { it.value }
}
try {
tester.body()
} finally {
tester.cancel()
}
}