Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using vectorResource in Call Link's Fragments #13911

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.core.app.ShareCompat
Expand Down Expand Up @@ -299,19 +301,19 @@ private fun CreateCallLinkBottomSheetContent(

Rows.TextRow(
text = stringResource(id = R.string.CreateCallLinkBottomSheetDialogFragment__share_link_via_signal),
icon = painterResource(id = R.drawable.symbol_forward_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_forward_24),
onClick = onShareViaSignalClicked
)

Rows.TextRow(
text = stringResource(id = R.string.CreateCallLinkBottomSheetDialogFragment__copy_link),
icon = painterResource(id = R.drawable.symbol_copy_android_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_copy_android_24),
onClick = onCopyLinkClicked
)

Rows.TextRow(
text = stringResource(id = R.string.CreateCallLinkBottomSheetDialogFragment__share_link),
icon = painterResource(id = R.drawable.symbol_share_android_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_share_android_24),
onClick = onShareLinkClicked
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -316,25 +318,25 @@ private fun CallLinkDetails(

Rows.TextRow(
text = stringResource(id = R.string.CreateCallLinkBottomSheetDialogFragment__share_link_via_signal),
icon = painterResource(id = R.drawable.symbol_forward_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_forward_24),
onClick = callback::onShareLinkViaSignalClicked
)

Rows.TextRow(
text = stringResource(id = R.string.CreateCallLinkBottomSheetDialogFragment__copy_link),
icon = painterResource(id = R.drawable.symbol_copy_android_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_copy_android_24),
onClick = callback::onCopyClicked
)

Rows.TextRow(
text = stringResource(id = R.string.CallLinkDetailsFragment__share_link),
icon = painterResource(id = R.drawable.symbol_link_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_link_24),
onClick = callback::onShareClicked
)

Rows.TextRow(
text = stringResource(id = R.string.CallLinkDetailsFragment__delete_call_link),
icon = painterResource(id = R.drawable.symbol_trash_24),
icon = ImageVector.vectorResource(id = R.drawable.symbol_trash_24),
foregroundTint = MaterialTheme.colorScheme.error,
onClick = callback::onDeleteClicked
)
Expand Down
44 changes: 44 additions & 0 deletions core-ui/src/main/java/org/signal/core/ui/Rows.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -197,6 +198,49 @@ object Rows {
)
}

/**
* Text row that positions [text] and optional [label] in a [TextAndLabel] to the side of an [icon] using ImageVector.
*/
@Composable
fun TextRow(
text: String,
icon: ImageVector?,
modifier: Modifier = Modifier,
iconModifier: Modifier = Modifier,
label: String? = null,
foregroundTint: Color = MaterialTheme.colorScheme.onSurface,
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
enabled: Boolean = true
) {
TextRow(
text = {
TextAndLabel(
text = text,
label = label,
textColor = foregroundTint,
enabled = enabled
)
},
icon = if (icon != null) {
{
Icon(
imageVector = icon,
contentDescription = null,
tint = foregroundTint,
modifier = iconModifier
)
}
} else {
null
},
modifier = modifier,
onClick = onClick,
onLongClick = onLongClick,
enabled = enabled
)
}

/**
* Customizable text row that allows [text] and [icon] to be provided as composable functions instead of primitives.
*/
Expand Down