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
15.3k stars 1.11k forks source link

Material3 button not found #1582

Open dragossusi opened 2 years ago

dragossusi commented 2 years ago

I added material 3 succesfully in my app, and most of the widgets work, but the Button widget is nowhere to be found.

Material3 Text, Icon, IconButton, Scaffold and TopAppBars work, but I can't import material3.Button, only material.Button works

YoshiRulz commented 2 years ago

Also Switch (renamed SwitchMaterial?). Per https://github.com/JetBrains/compose-jb/pull/1390#issue-1052375115 it was intentionally added without all the components.

edit: I've applied colours from my Material 3 colour scheme to the Material 2 components and it works well enough:

code within `buttonColoursFromM3Scheme`/`switchColoursFromM3Scheme` are the result of copying the default values from decomp/sources of Material 2 components and swapping out the implementations. IIRC one of the colours isn't available anymore so I just guessed. ```kotlin import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.RowScope import androidx.compose.material.ContentAlpha import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.compositeOver import androidx.compose.material.Button as M2Button import androidx.compose.material.ButtonColors as M2ButtonColors import androidx.compose.material.ButtonDefaults as M2ButtonDefaults import androidx.compose.material.ButtonElevation as M2ButtonElevation import androidx.compose.material.ContentAlpha as M2ContentAlpha import androidx.compose.material.MaterialTheme as M2MaterialTheme import androidx.compose.material.Switch as M2Switch import androidx.compose.material.SwitchColors as M2SwitchColors import androidx.compose.material.SwitchDefaults as M2SwitchDefaults @Composable public fun Button( onClick: () -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, elevation: M2ButtonElevation? = M2ButtonDefaults.elevation(), shape: Shape = M2MaterialTheme.shapes.small, border: BorderStroke? = null, colors: M2ButtonColors? = null, contentPadding: PaddingValues = M2ButtonDefaults.ContentPadding, content: @Composable RowScope.() -> Unit ): Unit = M2Button( onClick = onClick, modifier = modifier, enabled = enabled, interactionSource = interactionSource, elevation = elevation, shape = shape, border = border, colors = colors ?: buttonColoursFromM3Scheme(), contentPadding = contentPadding, content = content, ) @Composable public fun buttonColoursFromM3Scheme(): M2ButtonColors = M2ButtonDefaults.buttonColors( backgroundColor = MaterialTheme.colorScheme.primary, contentColor = MaterialTheme.colorScheme.onPrimary, disabledBackgroundColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.12f).compositeOver(MaterialTheme.colorScheme.surface), disabledContentColor = MaterialTheme.colorScheme.onSurface.copy(alpha = M2ContentAlpha.disabled), ) @Composable public fun Switch( checked: Boolean, onCheckedChange: ((Boolean) -> Unit)?, modifier: Modifier = Modifier, enabled: Boolean = true, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, colors: M2SwitchColors? = null ): Unit = M2Switch( checked = checked, onCheckedChange = onCheckedChange, modifier = modifier, enabled = enabled, interactionSource = interactionSource, colors = colors ?: switchColoursFromM3Scheme(), ) @Composable public fun switchColoursFromM3Scheme(): M2SwitchColors = M2SwitchDefaults.colors( checkedThumbColor = MaterialTheme.colorScheme.secondary, checkedTrackColor = MaterialTheme.colorScheme.secondary, uncheckedThumbColor = MaterialTheme.colorScheme.surface, uncheckedTrackColor = MaterialTheme.colorScheme.onSurface, disabledCheckedThumbColor = MaterialTheme.colorScheme.secondary.copy(alpha = ContentAlpha.disabled).compositeOver(MaterialTheme.colorScheme.surface), disabledCheckedTrackColor = MaterialTheme.colorScheme.secondary.copy(alpha = ContentAlpha.disabled).compositeOver(MaterialTheme.colorScheme.surface), disabledUncheckedThumbColor = MaterialTheme.colorScheme.surface.copy(alpha = ContentAlpha.disabled).compositeOver(MaterialTheme.colorScheme.surface), disabledUncheckedTrackColor = MaterialTheme.colorScheme.onSurface.copy(alpha = ContentAlpha.disabled).compositeOver(MaterialTheme.colorScheme.surface), ) ```
dragossusi commented 2 years ago

Material 3 navigation bar is not working either

jakobkmar commented 2 years ago

The only problem here is that the material3 dependency exposed by compose-jb is very old, while 1.0.0-alpha02 is already around and all documentation is made for that version. It just has to be updated.

dragossusi commented 2 years ago

@jakobkmar is this a bug for AndroidX repository?

jakobkmar commented 2 years ago

@dragossusi you can see the state of Material 3 compose-jb is currently using here while the origin repo already has a lot more components. This is not really a bug, it is just behind.

dragossusi commented 2 years ago

Update: Button is now available with material 3 in jetbrains compose 1.1.0-alpha02.

Thank you!

akurasov commented 2 years ago

@igordmn should we close it?