enhance(android): add tab icon for flashcards in LiquidTabsPlugin

This commit is contained in:
charlie
2026-05-21 16:04:36 +08:00
parent 083e7da278
commit 37d878e6de
2 changed files with 32 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.ui.graphics.Color as ComposeColor
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp // New Import for DP units
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
@@ -77,6 +78,11 @@ class LiquidTabsPlugin : Plugin() {
private val TAB_BAR_HORIZONTAL_PADDING = 12.dp
private val ACCENT_COLOR_HEX = "#6097c7"
private fun tabIconResId(tabId: String): Int? = when (tabId) {
"flashcards" -> R.drawable.ic_tab_flashcards
else -> null
}
@PluginMethod
fun configureTabs(call: PluginCall) {
val activity = activity ?: run {
@@ -579,6 +585,7 @@ class LiquidTabsPlugin : Plugin() {
val icon = remember(tab.systemImage, tab.id) {
MaterialIconResolver.resolve(tab.systemImage) ?: MaterialIconResolver.resolve(tab.id)
}
val iconResId = remember(tab.id) { tabIconResId(tab.id) }
val accent = ComposeColor(NativeUiUtils.parseColor(ACCENT_COLOR_HEX, Color.parseColor(ACCENT_COLOR_HEX)))
NavigationBarItem(
@@ -592,10 +599,17 @@ class LiquidTabsPlugin : Plugin() {
indicatorColor = accent.copy(alpha = 0.12f)
),
icon = {
Icon(
imageVector = icon ?: Icons.Filled.Circle,
contentDescription = tab.title
)
if (iconResId != null) {
Icon(
painter = painterResource(id = iconResId),
contentDescription = tab.title
)
} else {
Icon(
imageVector = icon ?: Icons.Filled.Circle,
contentDescription = tab.title
)
}
},
// Slightly reduce the default Material3 gap between icon and label.
label = { Text(tab.title, modifier = Modifier.offset(y = (-4).dp)) }

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<group android:translateY="960">
<path
android:fillColor="#FF000000"
android:pathData="m608,-368l46,-166 -142,-98 -46,166 142,98ZM160,-207l-33,-16q-31,-13 -42,-44.5t3,-62.5l72,-156v279ZM320,-120q-33,0 -56.5,-24T240,-201v-239l107,294q3,7 5,13.5t7,12.5h-39ZM526,-125q-31,11 -62,-3t-42,-45L245,-662q-11,-31 3,-61.5t45,-41.5l301,-110q31,-11 61.5,3t41.5,45l178,489q11,31 -3,61.5T827,-235L526,-125ZM498,-200l302,-110 -179,-490 -301,110 178,490ZM560,-500Z" />
</group>
</vector>