mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Fix Borderless Buttons
This commit is contained in:
parent
d57158eb3d
commit
5147d059b9
@ -86,13 +86,13 @@ private fun EnterAccountId(
|
|||||||
|
|
||||||
BorderlessButtonWithIcon(
|
BorderlessButtonWithIcon(
|
||||||
text = stringResource(R.string.messageNewDescription),
|
text = stringResource(R.string.messageNewDescription),
|
||||||
iconRes = R.drawable.ic_circle_question_mark,
|
|
||||||
contentColor = LocalColors.current.textSecondary,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.animateContentSize()
|
.animateContentSize()
|
||||||
.contentDescription(R.string.AccessibilityId_help_desk_link)
|
.contentDescription(R.string.AccessibilityId_help_desk_link)
|
||||||
.padding(horizontal = LocalDimensions.current.margin)
|
.padding(horizontal = LocalDimensions.current.margin)
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
|
color = LocalColors.current.textSecondary,
|
||||||
|
iconRes = R.drawable.ic_circle_question_mark
|
||||||
) { onHelp() }
|
) { onHelp() }
|
||||||
|
|
||||||
OutlineButton(
|
OutlineButton(
|
||||||
|
@ -11,13 +11,13 @@ import androidx.compose.foundation.interaction.PressInteraction
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.RowScope
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.ButtonColors
|
import androidx.compose.material.ButtonColors
|
||||||
import androidx.compose.material.ButtonDefaults
|
import androidx.compose.material.ButtonDefaults
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.material.TextButton
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@ -65,6 +65,7 @@ fun Button(
|
|||||||
border: BorderStroke? = type.border(color, enabled),
|
border: BorderStroke? = type.border(color, enabled),
|
||||||
colors: ButtonColors = type.buttonColors(color),
|
colors: ButtonColors = type.buttonColors(color),
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
|
contentPadding: PaddingValues = type.contentPadding,
|
||||||
content: @Composable RowScope.() -> Unit
|
content: @Composable RowScope.() -> Unit
|
||||||
) {
|
) {
|
||||||
style.applyButtonConstraints {
|
style.applyButtonConstraints {
|
||||||
@ -76,7 +77,8 @@ fun Button(
|
|||||||
elevation = null,
|
elevation = null,
|
||||||
shape,
|
shape,
|
||||||
border,
|
border,
|
||||||
colors
|
colors,
|
||||||
|
contentPadding
|
||||||
) {
|
) {
|
||||||
// Button sets LocalTextStyle, so text style is applied inside to override that.
|
// Button sets LocalTextStyle, so text style is applied inside to override that.
|
||||||
style.applyTextConstraints {
|
style.applyTextConstraints {
|
||||||
@ -205,47 +207,37 @@ fun TemporaryClickedContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base [BorderlessButton] implementation.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun BorderlessButton(
|
fun BorderlessButton(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentColor: Color = LocalColors.current.text,
|
color: Color = LocalColors.current.text,
|
||||||
backgroundColor: Color = Color.Transparent,
|
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
content: @Composable RowScope.() -> Unit
|
content: @Composable RowScope.() -> Unit
|
||||||
) {
|
) {
|
||||||
TextButton(
|
Button(
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
|
color = color,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
colors = ButtonDefaults.outlinedButtonColors(
|
style = ButtonStyle.Borderless,
|
||||||
contentColor = contentColor,
|
type = ButtonType.Borderless,
|
||||||
backgroundColor = backgroundColor
|
|
||||||
),
|
|
||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Courtesy [BorderlessButton] implementation that accepts [text] as a [String].
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun BorderlessButton(
|
fun BorderlessButton(
|
||||||
text: String,
|
text: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentDescription: GetString = GetString(text),
|
color: Color = LocalColors.current.text,
|
||||||
contentColor: Color = LocalColors.current.text,
|
|
||||||
backgroundColor: Color = Color.Transparent,
|
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
BorderlessButton(
|
BorderlessButton(modifier, color, onClick) { Text(text) }
|
||||||
modifier = modifier.contentDescription(contentDescription),
|
|
||||||
contentColor = contentColor,
|
|
||||||
backgroundColor = backgroundColor,
|
|
||||||
onClick = onClick
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = text,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
style = extraSmall,
|
|
||||||
modifier = Modifier.padding(horizontal = 2.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -254,14 +246,12 @@ fun BorderlessButtonWithIcon(
|
|||||||
@DrawableRes iconRes: Int,
|
@DrawableRes iconRes: Int,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
style: TextStyle = baseBold,
|
style: TextStyle = baseBold,
|
||||||
contentColor: Color = LocalColors.current.text,
|
color: Color = LocalColors.current.text,
|
||||||
backgroundColor: Color = Color.Transparent,
|
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
BorderlessButton(
|
BorderlessButton(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentColor = contentColor,
|
color = color,
|
||||||
backgroundColor = backgroundColor,
|
|
||||||
onClick = onClick
|
onClick = onClick
|
||||||
) {
|
) {
|
||||||
AnnotatedTextWithIcon(text, iconRes, style = style)
|
AnnotatedTextWithIcon(text, iconRes, style = style)
|
||||||
@ -272,20 +262,12 @@ fun BorderlessButtonWithIcon(
|
|||||||
fun BorderlessHtmlButton(
|
fun BorderlessHtmlButton(
|
||||||
textId: Int,
|
textId: Int,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentColor: Color = LocalColors.current.text,
|
color: Color = LocalColors.current.text,
|
||||||
backgroundColor: Color = Color.Transparent,
|
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
BorderlessButton(
|
BorderlessButton(modifier, color, onClick) {
|
||||||
modifier,
|
|
||||||
contentColor = contentColor,
|
|
||||||
backgroundColor = backgroundColor,
|
|
||||||
onClick = onClick
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = annotatedStringResource(textId),
|
text = annotatedStringResource(textId),
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
style = extraSmall,
|
|
||||||
modifier = Modifier.padding(horizontal = 2.dp)
|
modifier = Modifier.padding(horizontal = 2.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -311,6 +293,8 @@ private fun VariousButtons(
|
|||||||
SlimOutlineButton("Slim Primary", color = LocalColors.current.buttonOutline) {}
|
SlimOutlineButton("Slim Primary", color = LocalColors.current.buttonOutline) {}
|
||||||
SlimOutlineButton("Slim Danger", color = LocalColors.current.danger) {}
|
SlimOutlineButton("Slim Danger", color = LocalColors.current.danger) {}
|
||||||
SlimOutlineCopyButton {}
|
SlimOutlineCopyButton {}
|
||||||
|
BorderlessButton("Borderless Button") {}
|
||||||
|
BorderlessButton("Borderless Secondary", color = LocalColors.current.textSecondary) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import org.thoughtcrime.securesms.ui.baseBold
|
import org.thoughtcrime.securesms.ui.baseBold
|
||||||
|
import org.thoughtcrime.securesms.ui.extraSmall
|
||||||
import org.thoughtcrime.securesms.ui.extraSmallBold
|
import org.thoughtcrime.securesms.ui.extraSmallBold
|
||||||
|
|
||||||
interface ButtonStyle {
|
interface ButtonStyle {
|
||||||
@ -43,4 +44,9 @@ interface ButtonStyle {
|
|||||||
override val textStyle = extraSmallBold.copy(textAlign = TextAlign.Center)
|
override val textStyle = extraSmallBold.copy(textAlign = TextAlign.Center)
|
||||||
override val minHeight = 29.dp
|
override val minHeight = 29.dp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Borderless: ButtonStyle {
|
||||||
|
override val textStyle = extraSmall.copy(textAlign = TextAlign.Center)
|
||||||
|
override val minHeight = 37.dp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.ui.components
|
package org.thoughtcrime.securesms.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.material.ButtonColors
|
import androidx.compose.material.ButtonColors
|
||||||
import androidx.compose.material.ButtonDefaults
|
import androidx.compose.material.ButtonDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@ -10,6 +11,8 @@ import org.thoughtcrime.securesms.ui.LocalDimensions
|
|||||||
import org.thoughtcrime.securesms.ui.color.LocalColors
|
import org.thoughtcrime.securesms.ui.color.LocalColors
|
||||||
|
|
||||||
interface ButtonType {
|
interface ButtonType {
|
||||||
|
val contentPadding: PaddingValues get() = ButtonDefaults.ContentPadding
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun border(color: Color, enabled: Boolean): BorderStroke?
|
fun border(color: Color, enabled: Boolean): BorderStroke?
|
||||||
@Composable
|
@Composable
|
||||||
@ -42,4 +45,17 @@ interface ButtonType {
|
|||||||
disabledBackgroundColor = Color.Unspecified
|
disabledBackgroundColor = Color.Unspecified
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Borderless: ButtonType {
|
||||||
|
override val contentPadding: PaddingValues
|
||||||
|
get() = PaddingValues(horizontal = 16.dp, vertical = 12.dp)
|
||||||
|
@Composable
|
||||||
|
override fun border(color: Color, enabled: Boolean) = null
|
||||||
|
@Composable
|
||||||
|
override fun buttonColors(color: Color) = ButtonDefaults.outlinedButtonColors(
|
||||||
|
contentColor = color,
|
||||||
|
backgroundColor = Color.Transparent,
|
||||||
|
disabledContentColor = LocalColors.current.disabled
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user