Refactors Add and Remove button to remove dependency on a specific modifier.
This commit is contained in:
+8
-15
@@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.ui.note.elements
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -56,20 +55,16 @@ fun AddButtonPreview() {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AddButton(
|
fun AddButton(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
text: Int = R.string.add,
|
text: Int = R.string.add,
|
||||||
isActive: Boolean = true,
|
isActive: Boolean = true,
|
||||||
modifier: Modifier = Modifier.padding(start = 3.dp),
|
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
onClick = {
|
|
||||||
if (isActive) {
|
|
||||||
onClick()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
shape = ButtonBorder,
|
|
||||||
enabled = isActive,
|
enabled = isActive,
|
||||||
|
onClick = onClick,
|
||||||
|
shape = ButtonBorder,
|
||||||
contentPadding = PaddingValues(vertical = 0.dp, horizontal = 16.dp),
|
contentPadding = PaddingValues(vertical = 0.dp, horizontal = 16.dp),
|
||||||
) {
|
) {
|
||||||
Text(text = stringRes(text), textAlign = TextAlign.Center)
|
Text(text = stringRes(text), textAlign = TextAlign.Center)
|
||||||
@@ -78,20 +73,18 @@ fun AddButton(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RemoveButton(
|
fun RemoveButton(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
text: Int = R.string.remove,
|
||||||
isActive: Boolean = true,
|
isActive: Boolean = true,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
modifier = Modifier.padding(start = 3.dp),
|
modifier = modifier,
|
||||||
onClick = {
|
onClick = onClick,
|
||||||
if (isActive) {
|
|
||||||
onClick()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
shape = ButtonBorder,
|
shape = ButtonBorder,
|
||||||
enabled = isActive,
|
enabled = isActive,
|
||||||
contentPadding = PaddingValues(vertical = 0.dp, horizontal = 16.dp),
|
contentPadding = PaddingValues(vertical = 0.dp, horizontal = 16.dp),
|
||||||
) {
|
) {
|
||||||
Text(text = stringRes(R.string.remove))
|
Text(text = stringRes(text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,9 +183,9 @@ private fun EmojiListOptions(
|
|||||||
|
|
||||||
CrossfadeIfEnabled(targetState = hasAddedThis, label = "EmojiListOptions", accountViewModel = accountViewModel) {
|
CrossfadeIfEnabled(targetState = hasAddedThis, label = "EmojiListOptions", accountViewModel = accountViewModel) {
|
||||||
if (it != true) {
|
if (it != true) {
|
||||||
AddButton { accountViewModel.addEmojiPack(usersEmojiList, emojiPackNote) }
|
AddButton(modifier = Modifier.padding(start = 3.dp)) { accountViewModel.addEmojiPack(usersEmojiList, emojiPackNote) }
|
||||||
} else {
|
} else {
|
||||||
RemoveButton { accountViewModel.removeEmojiPack(usersEmojiList, emojiPackNote) }
|
RemoveButton(modifier = Modifier.padding(start = 3.dp)) { accountViewModel.removeEmojiPack(usersEmojiList, emojiPackNote) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user