JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.25k stars 1.18k forks source link

Setted the background color for DropdownMenu, but the corner color is white #1355

Closed GaoXing0608 closed 2 years ago

GaoXing0608 commented 3 years ago

image

akurasov commented 3 years ago

Could you share the reproducer code, please?

GaoXing0608 commented 3 years ago

Could you share the reproducer code, please?

The debug code as the follows.

@Composable @Preview fun App() { var text by remember { mutableStateOf("Hello, World!") } var dropdownExpanded by remember { mutableStateOf(false) }

DesktopMaterialTheme{

    Box(
        modifier = Modifier.fillMaxSize()
            .background(Color(43, 43, 43))
    ) {
        Box{
            Button(onClick = {
                text = "Hello, Desktop!"
                dropdownExpanded = true
            }) {
                Text(text)
            }

            DropdownMenu(
                expanded = dropdownExpanded,
                onDismissRequest = {
                    dropdownExpanded = false
                },
                modifier = Modifier.background(Color(44, 44, 44))
            ) {
                DropdownMenuItem(
                    onClick = {
                        dropdownExpanded = false
                    }
                ) {
                    Text(
                        text = "Dropdown Item",
                        color = Color.White
                    )
                }
            }
        }
    }
}

}

image

akurasov commented 2 years ago

I think it is a material shade effect. It will be more visible if you use 192-192-192 color. And if you use 0-0-0 it will disappear at all.

Tylll3Hka commented 1 year ago

It was not possible to remove the white lines on the corners

malliaridis commented 1 year ago

@Tylll3Hka I looked into this issue and found out that it is a theme related problem. To be precise you are having white background because it is a light theme-related "effect" (actually a surface color) that applies on a dark component (dark because it is styled as such). When switching to dark theme or overriding the surface color of the theme you can fix this.

I recommend you to make use of the theme's dark and light theme feature and don't manually set the background colors for such modals (would also reduce unnecessary customizations). For customizing the theme you can look up instructions online, one of them is the Android Developer page.

For a quick and dirty fix that allows you to customize the theme locally at the place of definition you can wrap your DropdownMenu with a custom theme:

// Either use darkColorScheme() (M3) or lightColorScheme(surface = Color(44, 44, 44))
// or for Material 2 darkColors() / lightColors(surface = Color(44, 44, 44))
MaterialTheme(colorScheme = darkColorScheme()) {
  DropdownMenu(
    expanded = dropdownExpanded,
    onDismissRequest = { dropdownExpanded = false },
    modifier = Modifier.background(Color(44, 44, 44))
    ) {
      DropdownMenuItem(
      onClick = { dropdownExpanded = false },
      text = {
        Text(
          text = "Dropdown Item",
          color = Color.White // <- Text color on dark theme is automatically white and therefore this is not necessary
        )
      },
    )
  }
}
okushnikov commented 4 months ago

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