Buttons re-arranging

This commit is contained in:
ThomasSession 2024-06-12 13:38:23 +10:00
parent cf1649a6af
commit 7dceb7c66a
5 changed files with 101 additions and 101 deletions

View File

@ -54,6 +54,7 @@ import org.thoughtcrime.securesms.ui.components.AppBar
import org.thoughtcrime.securesms.ui.components.BorderlessButtonSecondary import org.thoughtcrime.securesms.ui.components.BorderlessButtonSecondary
import org.thoughtcrime.securesms.ui.components.MaybeScanQrCode import org.thoughtcrime.securesms.ui.components.MaybeScanQrCode
import org.thoughtcrime.securesms.ui.components.OutlineButton import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.components.SessionButtonText
import org.thoughtcrime.securesms.ui.components.SessionOutlinedTextField import org.thoughtcrime.securesms.ui.components.SessionOutlinedTextField
import org.thoughtcrime.securesms.ui.components.SessionTabRow import org.thoughtcrime.securesms.ui.components.SessionTabRow
import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.contentDescription
@ -161,7 +162,7 @@ fun EnterAccountId(
error = state.error?.string(), error = state.error?.string(),
) )
if (state.error == null) { if (state.error == null) {
BorderlessButtonWithIcon( BorderlessButtonSecondary(
text = stringResource(R.string.messageNewDescription), text = stringResource(R.string.messageNewDescription),
modifier = Modifier.contentDescription(R.string.AccessibilityId_help_desk_link) modifier = Modifier.contentDescription(R.string.AccessibilityId_help_desk_link)
) { onHelp() } ) { onHelp() }
@ -176,10 +177,7 @@ fun EnterAccountId(
onClick = { callbacks.onContinue() } onClick = { callbacks.onContinue() }
) { ) {
LoadingArcOr(state.loading) { LoadingArcOr(state.loading) {
Text( SessionButtonText(stringResource(R.string.next))
stringResource(R.string.next),
style = MaterialTheme.typography.baseBold
)
} }
} }
} }

View File

@ -34,13 +34,11 @@ import org.thoughtcrime.securesms.preferences.copyPublicKey
import org.thoughtcrime.securesms.preferences.sendInvitationToUseSession import org.thoughtcrime.securesms.preferences.sendInvitationToUseSession
import org.thoughtcrime.securesms.ui.AppTheme import org.thoughtcrime.securesms.ui.AppTheme
import org.thoughtcrime.securesms.ui.base import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.baseBold
import org.thoughtcrime.securesms.ui.classicDarkColors import org.thoughtcrime.securesms.ui.classicDarkColors
import org.thoughtcrime.securesms.ui.components.AppBar import org.thoughtcrime.securesms.ui.components.AppBar
import org.thoughtcrime.securesms.ui.components.OnPrimaryButtons import org.thoughtcrime.securesms.ui.components.OnPrimaryButtons
import org.thoughtcrime.securesms.ui.components.OutlineButton import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.components.OutlineCopyButton import org.thoughtcrime.securesms.ui.components.OutlineCopyButton
import org.thoughtcrime.securesms.ui.components.OutlineTemporaryStateButton
import org.thoughtcrime.securesms.ui.components.SmallButtons import org.thoughtcrime.securesms.ui.components.SmallButtons
import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.small import org.thoughtcrime.securesms.ui.small
@ -122,13 +120,9 @@ private fun InviteFriend(
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.contentDescription("Share button"), .contentDescription("Share button"),
text = stringResource(R.string.share),
onClick = sendInvitation onClick = sendInvitation
) { )
Text(
stringResource(R.string.share),
style = MaterialTheme.typography.baseBold
)
}
OutlineCopyButton( OutlineCopyButton(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),

View File

@ -78,6 +78,7 @@ import org.thoughtcrime.securesms.ui.baseBold
import org.thoughtcrime.securesms.ui.baseMonospace import org.thoughtcrime.securesms.ui.baseMonospace
import org.thoughtcrime.securesms.ui.blackAlpha40 import org.thoughtcrime.securesms.ui.blackAlpha40
import org.thoughtcrime.securesms.ui.colorDestructive import org.thoughtcrime.securesms.ui.colorDestructive
import org.thoughtcrime.securesms.ui.components.SessionButtonText
import org.thoughtcrime.securesms.ui.destructiveButtonColors import org.thoughtcrime.securesms.ui.destructiveButtonColors
import javax.inject.Inject import javax.inject.Inject
@ -400,15 +401,7 @@ fun TitledText(
@Composable @Composable
fun TitledView(title: GetString, modifier: Modifier = Modifier, content: @Composable () -> Unit) { fun TitledView(title: GetString, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) { Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
Title(title) SessionButtonText(text = title.string())
content() content()
} }
} }
@Composable
fun Title(title: GetString) {
Text(
title.string(),
style = MaterialTheme.typography.baseBold
)
}

View File

@ -23,8 +23,6 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -80,11 +78,8 @@ import org.thoughtcrime.securesms.ui.Cell
import org.thoughtcrime.securesms.ui.Divider import org.thoughtcrime.securesms.ui.Divider
import org.thoughtcrime.securesms.ui.ItemButton import org.thoughtcrime.securesms.ui.ItemButton
import org.thoughtcrime.securesms.ui.ItemButtonWithDrawable import org.thoughtcrime.securesms.ui.ItemButtonWithDrawable
import org.thoughtcrime.securesms.ui.baseBold
import org.thoughtcrime.securesms.ui.components.OutlineButton import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.components.OutlineCopyButton import org.thoughtcrime.securesms.ui.components.OutlineCopyButton
import org.thoughtcrime.securesms.ui.components.OutlineTemporaryStateButton
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.destructiveButtonColors import org.thoughtcrime.securesms.ui.destructiveButtonColors
import org.thoughtcrime.securesms.util.BitmapDecodingException import org.thoughtcrime.securesms.util.BitmapDecodingException
import org.thoughtcrime.securesms.util.BitmapUtil import org.thoughtcrime.securesms.util.BitmapUtil

View File

@ -1,14 +1,18 @@
package org.thoughtcrime.securesms.ui.components package org.thoughtcrime.securesms.ui.components
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.Crossfade
import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ButtonDefaults import androidx.compose.material.ButtonDefaults
import androidx.compose.material.ContentAlpha import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
@ -22,6 +26,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -38,7 +43,6 @@ import org.thoughtcrime.securesms.ui.baseBold
import org.thoughtcrime.securesms.ui.colorDestructive import org.thoughtcrime.securesms.ui.colorDestructive
import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.extraSmall import org.thoughtcrime.securesms.ui.extraSmall
import kotlin.time.Duration.Companion.seconds
val LocalButtonSize = staticCompositionLocalOf { mediumButton } val LocalButtonSize = staticCompositionLocalOf { mediumButton }
@ -48,6 +52,18 @@ fun Modifier.applyButtonSize() = then(LocalButtonSize.current)
val mediumButton = Modifier.height(41.dp) val mediumButton = Modifier.height(41.dp)
val smallButton = Modifier.wrapContentHeight() val smallButton = Modifier.wrapContentHeight()
@Composable
fun SessionButtonText(
text: String,
modifier: Modifier = Modifier
){
Text(
modifier = modifier,
text = text,
style = MaterialTheme.typography.baseBold
)
}
@Composable @Composable
fun OutlineButton( fun OutlineButton(
@StringRes textId: Int, @StringRes textId: Int,
@ -64,7 +80,9 @@ fun OutlineButton(
OutlineButton( OutlineButton(
modifier = modifier, modifier = modifier,
onClick = onClick onClick = onClick
) { Text(text, style = MaterialTheme.typography.baseBold) } ) {
SessionButtonText(text = text)
}
} }
@Composable @Composable
@ -93,64 +111,68 @@ fun OutlineCopyButton(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClick: () -> Unit = {} onClick: () -> Unit = {}
) { ) {
OutlineTemporaryStateButton( val interactionSource = remember { MutableInteractionSource() }
text = stringResource(R.string.copy),
temporaryText = stringResource(R.string.copy),
modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button),
onClick = onClick
)
}
@Composable OutlineButton(
fun OutlineTemporaryStateButton( modifier = modifier,
text: String, interactionSource = interactionSource,
temporaryText: String, onClick = onClick
modifier: Modifier = Modifier, ) {
onClick: () -> Unit = {} TemporaryClickedContent(
) { interactionSource = interactionSource,
OutlineTemporaryStateButton(modifier, onClick) { isTemporary -> content = {
Text( // using a centered box because the outline button uses rowscope internally and it shows the crossfade
if (isTemporary) temporaryText else text, Box(
style = MaterialTheme.typography.baseBold modifier = Modifier.fillMaxWidth()
) {
SessionButtonText(
modifier = Modifier.align(Alignment.Center),
text = stringResource(R.string.copy)
)
}
},
temporaryContent = {
// using a centered box because the outline button uses rowscope internally and it shows the crossfade
Box(
modifier = Modifier.fillMaxWidth()
) {
SessionButtonText(
modifier = Modifier.align(Alignment.Center),
text = stringResource(R.string.copied)
)
}
}
) )
} }
} }
@Composable @Composable
fun OutlineTemporaryStateButton( fun TemporaryClickedContent(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClick: () -> Unit = {}, interactionSource: MutableInteractionSource,
content: @Composable (Boolean) -> Unit, content: @Composable () -> Unit,
temporaryContent: @Composable () -> Unit,
temporaryDelay: Long = 2000
) { ) {
TemporaryStateButton { source, isTemporary ->
OutlineButton(
modifier = modifier,
interactionSource = source,
onClick = onClick,
) {
AnimatedVisibility(isTemporary) { content(true) }
AnimatedVisibility(!isTemporary) { content(false) }
}
}
}
@Composable
fun TemporaryStateButton(
content: @Composable (MutableInteractionSource, Boolean) -> Unit,
) {
val interactions = remember { MutableInteractionSource() }
var clicked by remember { mutableStateOf(false) } var clicked by remember { mutableStateOf(false) }
content(interactions, clicked)
LaunchedEffectAsync { LaunchedEffectAsync {
interactions.releases.collectLatest { interactionSource.releases.collectLatest {
clicked = true clicked = true
delay(2.seconds) delay(temporaryDelay)
clicked = false clicked = false
} }
} }
Crossfade(
modifier = modifier,
targetState = clicked
) {
when(it) {
false -> content()
true -> temporaryContent()
}
}
} }
@Composable @Composable
@ -167,7 +189,7 @@ fun FilledButton(
backgroundColor = LocalButtonColor.current backgroundColor = LocalButtonColor.current
) )
) { ) {
Text(text = text, style = MaterialTheme.typography.baseBold) SessionButtonText(text)
} }
} }
@ -185,32 +207,6 @@ fun BorderlessButtonSecondary(
) )
} }
@Composable
fun BorderlessButton(
text: String,
modifier: Modifier = Modifier,
contentDescription: GetString = GetString(text),
contentColor: Color = MaterialTheme.colors.onBackground,
backgroundColor: Color = Color.Transparent,
onClick: () -> Unit
) {
TextButton(
onClick = onClick,
modifier = modifier.contentDescription(contentDescription),
colors = ButtonDefaults.outlinedButtonColors(
contentColor = contentColor,
backgroundColor = backgroundColor
)
) {
Text(
text = text,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.extraSmall,
modifier = Modifier.padding(horizontal = 2.dp)
)
}
}
@Composable @Composable
fun BorderlessButton( fun BorderlessButton(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@ -229,6 +225,30 @@ fun BorderlessButton(
) { content() } ) { content() }
} }
@Composable
fun BorderlessButton(
text: String,
modifier: Modifier = Modifier,
contentDescription: GetString = GetString(text),
contentColor: Color = MaterialTheme.colors.onBackground,
backgroundColor: Color = Color.Transparent,
onClick: () -> Unit
) {
BorderlessButton(
modifier = modifier.contentDescription(contentDescription),
contentColor = contentColor,
backgroundColor = backgroundColor,
onClick = onClick
) {
Text(
text = text,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.extraSmall,
modifier = Modifier.padding(horizontal = 2.dp)
)
}
}
@Composable @Composable
fun BorderlessHtmlButton( fun BorderlessHtmlButton(
textId: Int, textId: Int,