Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix container size in case of ImageComposeScene #1375

Merged
merged 1 commit into from
May 27, 2024
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 @@ -37,6 +37,7 @@ import androidx.compose.ui.test.InternalTestApi
import androidx.compose.ui.test.junit4.DesktopScreenshotTestRule
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -94,6 +95,19 @@ class ImageComposeSceneTest {
}
}

@Test
fun `run dialog in center`() {
val image = renderComposeScene(
width = 80,
height = 40,
) {
Dialog(onDismissRequest = {}) {
Box(Modifier.size(20.dp).background(Color.Red))
}
}
screenshotRule.write(image)
}

@Test
fun `run multiple ImageComposeScene`() {
for (i in 1..300) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.PointerKeyboardModifiers
import androidx.compose.ui.input.pointer.PointerType
import androidx.compose.ui.node.RootForTest
import androidx.compose.ui.platform.PlatformContext
import androidx.compose.ui.platform.WindowInfo
import androidx.compose.ui.platform.WindowInfoImpl
import androidx.compose.ui.scene.ComposeSceneContext
import androidx.compose.ui.scene.ComposeScenePointer
import androidx.compose.ui.scene.MultiLayerComposeScene
import androidx.compose.ui.unit.Constraints
Expand Down Expand Up @@ -132,11 +136,29 @@ class ImageComposeScene @ExperimentalComposeUiApi constructor(

private val surface = Surface.makeRasterN32Premul(width, height)

private val imageSize = IntSize(width, height)

private val _windowInfo = WindowInfoImpl().apply {
isWindowFocused = true
containerSize = imageSize
}

private val _platformContext = object : PlatformContext by PlatformContext.Empty {
override val windowInfo: WindowInfo
get() = _windowInfo
}

private val _sceneContext = object : ComposeSceneContext {
override val platformContext: PlatformContext
get() = _platformContext
}

private val scene = MultiLayerComposeScene(
density = density,
layoutDirection = layoutDirection,
size = IntSize(width, height),
size = imageSize,
coroutineContext = coroutineContext,
composeSceneContext = _sceneContext
).also {
it.setContent(content = content)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading