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

Add custom TextBadge() component #459

Merged
merged 11 commits into from
Jun 9, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@

package com.jerboa.ui.components.person

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.Badge
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.jerboa.datatypes.PersonSafe
import com.jerboa.datatypes.samplePersonSafe
import com.jerboa.personNameShown
Expand All @@ -34,14 +39,19 @@ fun PersonName(
val style = MaterialTheme.typography.bodyMedium

if (isPostCreator) {
Badge(
containerColor = MaterialTheme.colorScheme.tertiary,
Box(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well externalize this to its own composable, we'll probably have more uses for it later on. Put it in one of the files (or a new one), in ui/common/...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do just that, thanks!

Copy link
Contributor Author

@mxmvncnt mxmvncnt Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dessalines Hey, I didnt change the other Badge() since it looks like they are being used as their intended use case, which is to show a number for like notifications. And I am not sure if this badge should be affected by the corner radius changes since they are very small and I don't think there would be a way to make them slightly squared off but still looking nice, I feel the radius would make it look off-circley, kind of like a broken circle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmk that's fine.

modifier = Modifier
.clip(RoundedCornerShape(4.dp))
.background(MaterialTheme.colorScheme.tertiary),
) {
Text(
text = name,
style = style,
overflow = TextOverflow.Clip,
maxLines = 1,
color = MaterialTheme.colorScheme.onTertiary,
modifier = Modifier
.padding(6.dp, 0.dp),
)
}
} else {
Expand Down