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

Dialogs are not rendered as expected when used inside a ImageComposeScene #4875

Closed
alexstyl opened this issue May 26, 2024 · 1 comment · Fixed by JetBrains/compose-multiplatform-core#1375
Assignees
Labels
bug Something isn't working layers: popup/dialog

Comments

@alexstyl
Copy link

Describe the bug
Dialogs are normally rendered on the center of the screen on Android. On Compose Desktop they are rendered in the center of a Window. However, when used within a ImageComposeScene the dialog is placed on the top left corner of the scene instead.

Composable content:

@Composable
fun Content() {
    Box(Modifier.fillMaxSize().background(Color.White), contentAlignment = Alignment.Center) {
        BasicText("Content")
        Dialog(onDismissRequest = { /* TODO */ }) {
            Box(Modifier.fillMaxSize().border(1.dp, Color.Red), contentAlignment = Alignment.BottomEnd) {
                Box(Modifier.background(Color.White).padding(8.dp)) {
                    BasicText("Dialog Content")
                }
            }
        }
    }
}

Using it in a window like this:

fun main() = singleWindowApplication {
    Content()
}

renders the following:

window

However, when used inside of a ImageComposeScene using this code:

fun main() = application {
    ImageComposeScene(width = 1200, height = 800) {
        Content()
    }.use { scene ->
        scene.render()
        val directory = File(".")
        directory.mkdirs()
        val fileName = "test.png"

        val file = File(directory, fileName)

        val image = scene.render(1000)
        val data = image.encodeToData()!!

        Files.write(file.toPath(), data.bytes)
        Desktop.getDesktop().open(File(file.absolutePath))
    }
}

the output image has the dialog on the top left corner like this:
test

Affected platforms

  • Desktop: macOS

Versions
kotlin = "2.0.0-RC1"
compose = "1.6.10"

@alexstyl alexstyl added bug Something isn't working submitted labels May 26, 2024
@MatkovIvan MatkovIvan self-assigned this May 27, 2024
MatkovIvan added a commit to JetBrains/compose-multiplatform-core that referenced this issue May 27, 2024
Fixes JetBrains/compose-multiplatform#4875

## Testing

`:compose:ui:ui:desktopTest --tests
"androidx.compose.ui.ImageComposeSceneTest"`

## Release Notes

### Fixes - Multiple Platforms
- Fix container size for `Dialog` centering inside `ImageComposeScene`
MatkovIvan added a commit to JetBrains/compose-multiplatform-core that referenced this issue May 29, 2024
Fixes JetBrains/compose-multiplatform#4875

## Testing

`:compose:ui:ui:desktopTest --tests
"androidx.compose.ui.ImageComposeSceneTest"`

## Release Notes

### Fixes - Multiple Platforms
- Fix container size for `Dialog` centering inside `ImageComposeScene`
@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working layers: popup/dialog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants