remove text from nav
This commit is contained in:
+25
-25
@@ -20,9 +20,9 @@ import androidx.compose.foundation.layout.widthIn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.ClickableText
|
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
@@ -41,12 +41,14 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.text.LinkAnnotation
|
||||||
import androidx.compose.ui.text.SpanStyle
|
import androidx.compose.ui.text.SpanStyle
|
||||||
|
import androidx.compose.ui.text.TextLinkStyles
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
import androidx.compose.ui.text.withStyle
|
import androidx.compose.ui.text.withLink
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import org.jetbrains.compose.resources.stringResource
|
import org.jetbrains.compose.resources.stringResource
|
||||||
@@ -198,42 +200,40 @@ private fun MessageBubble(
|
|||||||
val contentColor = if (isUser) MaterialTheme.colorScheme.onPrimaryContainer else MaterialTheme.colorScheme.onSurfaceVariant
|
val contentColor = if (isUser) MaterialTheme.colorScheme.onPrimaryContainer else MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
val tokens = remember(message.content) { onParseMessage(message.content) }
|
val tokens = remember(message.content) { onParseMessage(message.content) }
|
||||||
val annotatedString = buildAnnotatedString {
|
val annotatedString = buildAnnotatedString {
|
||||||
tokens.forEachIndexed { index, token ->
|
tokens.forEach { token ->
|
||||||
when (token) {
|
when (token) {
|
||||||
is TextToken.Plain -> { append(token.text) }
|
is TextToken.Plain -> { append(token.text) }
|
||||||
is TextToken.Link -> {
|
is TextToken.Link -> {
|
||||||
pushStringAnnotation(tag = "LINK_INDEX", annotation = index.toString())
|
val linkAnnotation = LinkAnnotation.Clickable(
|
||||||
withStyle(
|
tag = "LINK",
|
||||||
style = SpanStyle(
|
styles = TextLinkStyles(
|
||||||
color = MaterialTheme.colorScheme.primary,
|
style = SpanStyle(
|
||||||
fontWeight = FontWeight.Bold,
|
color = MaterialTheme.colorScheme.primary,
|
||||||
textDecoration = TextDecoration.Underline
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
textDecoration = TextDecoration.Underline
|
||||||
) { append(token.text) }
|
)
|
||||||
pop()
|
),
|
||||||
|
linkInteractionListener = {
|
||||||
|
onClickLink(token.text)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
withLink(linkAnnotation) { append(token.text) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = alignment) {
|
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = alignment) {
|
||||||
Card(
|
Card(
|
||||||
colors = CardDefaults.cardColors(containerColor = containerColor, contentColor = contentColor),
|
colors = CardDefaults.cardColors(containerColor = containerColor, contentColor = contentColor),
|
||||||
modifier = Modifier.widthIn(max = 280.dp)
|
modifier = Modifier.widthIn(max = 280.dp)
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(12.dp)) {
|
Column(modifier = Modifier.padding(12.dp)) {
|
||||||
ClickableText(
|
SelectionContainer {
|
||||||
text = annotatedString,
|
Text(
|
||||||
style = MaterialTheme.typography.bodyLarge.copy(color = contentColor),
|
text = annotatedString,
|
||||||
onClick = { offset ->
|
style = MaterialTheme.typography.bodyLarge.copy(color = contentColor)
|
||||||
annotatedString.getStringAnnotations(tag = "LINK_INDEX", start = offset, end = offset)
|
)
|
||||||
.firstOrNull()?.let { annotation ->
|
}
|
||||||
val tokenIndex = annotation.item.toIntOrNull() ?: return@ClickableText
|
|
||||||
val clickedToken = tokens.getOrNull(tokenIndex) as? TextToken.Link ?: return@ClickableText
|
|
||||||
onClickLink(clickedToken.text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import androidx.compose.material3.NavigationRailItem
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SnackbarHost
|
import androidx.compose.material3.SnackbarHost
|
||||||
import androidx.compose.material3.SnackbarHostState
|
import androidx.compose.material3.SnackbarHostState
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.material3.TopAppBarScrollBehavior
|
import androidx.compose.material3.TopAppBarScrollBehavior
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -137,8 +136,7 @@ private fun <T : Route> BottomBar(
|
|||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
selected = currentRoute == entry.route,
|
selected = currentRoute == entry.route,
|
||||||
onClick = { onSelectNavigation?.invoke(entry.route) },
|
onClick = { onSelectNavigation?.invoke(entry.route) },
|
||||||
icon = { Icon(entry.painter, contentDescription = entry.title) },
|
icon = { Icon(entry.painter, contentDescription = entry.title) }
|
||||||
label = { Text(entry.title) }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,8 +163,7 @@ private fun <T : Route> ExpandedContent(
|
|||||||
NavigationRailItem(
|
NavigationRailItem(
|
||||||
selected = currentRoute == entry.route,
|
selected = currentRoute == entry.route,
|
||||||
onClick = { onSelectNavigation?.invoke(entry.route) },
|
onClick = { onSelectNavigation?.invoke(entry.route) },
|
||||||
icon = { Icon(entry.painter, contentDescription = entry.title) },
|
icon = { Icon(entry.painter, contentDescription = entry.title) }
|
||||||
label = { Text(entry.title) }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user