feat: Google Sans Flex variable font, MotionTokens, and expressive shape scale

This commit is contained in:
2026-10-05 22:07:32 +03:00
Unverified
parent a6da3046fe
commit 2b056b5cdd
12 changed files with 78 additions and 38 deletions
@@ -0,0 +1,36 @@
package ru.fromchat.ui
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.graphics.Shape
/**
* Central spring / motion tokens shared by the expressive components and
* transitions. Keeping them in one place keeps the whole app feeling
* consistent.
*/
/** Emphasized transitions — modal dialogs, large reveals. Slightly bouncy. */
val EmphasizedSpring = spring<Float>(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow,
)
/** Standard interaction spring — press feedback, chip expansion. Snappy. */
val StandardSpring = spring<Float>(
dampingRatio = 0.85f,
stiffness = Spring.StiffnessMedium,
)
/**
* The app-bar title slide spring — slightly slower than standard so the
* word-by-word reflow reads as a deliberate motion rather than a snap.
*/
val TitleSpring = spring<Float>(
dampingRatio = 0.82f,
stiffness = 240f,
)
/** Full / CTA shape (nav pill, primary buttons) — fully rounded. */
val FullCtaShape: Shape = CircleShape
@@ -2,15 +2,18 @@ package ru.fromchat.ui
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import ru.fromchat.config.Settings
import ru.fromchat.ui.components.googleSansMaterialTypography
import ru.fromchat.ui.components.googleSansFlexTypography
enum class Theme {
AsSystem,
@@ -26,6 +29,18 @@ var theme by mutableStateOf(
runCatching { Settings.theme }.getOrNull() ?: Theme.AsSystem
)
/**
* Expressive shape scale used by the redesigned UI (cards, nav pill, CTAs).
* Independent of the color scheme, so it is shared across platforms.
*/
val expressiveShapes = Shapes(
extraSmall = RoundedCornerShape(8.dp),
small = RoundedCornerShape(8.dp),
medium = RoundedCornerShape(12.dp),
large = RoundedCornerShape(16.dp),
extraLarge = RoundedCornerShape(28.dp),
)
@Composable
expect fun getColorScheme(darkTheme: Boolean, dynamicColor: Boolean): ColorScheme
@@ -122,7 +137,8 @@ fun FromChatTheme(
MaterialTheme(
colorScheme = colorScheme,
typography = googleSansMaterialTypography(),
typography = googleSansFlexTypography(),
shapes = expressiveShapes,
content = content
)
}
@@ -3,47 +3,35 @@ package ru.fromchat.ui.components
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import org.jetbrains.compose.resources.Font
import ru.fromchat.Res
import ru.fromchat.google_sans_bold
import ru.fromchat.google_sans_bold_italic
import ru.fromchat.google_sans_italic
import ru.fromchat.google_sans_medium
import ru.fromchat.google_sans_medium_italic
import ru.fromchat.google_sans_regular
import ru.fromchat.google_sans_semibold
import ru.fromchat.google_sans_semibold_italic
import ru.fromchat.google_sans_flex
@Composable
fun googleSansMaterialTypography() = Typography().let {
fun googleSansFlexTypography(): Typography {
// Single variable font (GRAD, ROND, opsz, slnt, wdth, wght axes) covers all weights.
val family = FontFamily(
Font(Res.font.google_sans_regular, FontWeight.Normal, FontStyle.Normal),
Font(Res.font.google_sans_italic, FontWeight.Normal, FontStyle.Italic),
Font(Res.font.google_sans_medium, FontWeight.Medium, FontStyle.Normal),
Font(Res.font.google_sans_medium_italic, FontWeight.Medium, FontStyle.Italic),
Font(Res.font.google_sans_semibold, FontWeight.SemiBold, FontStyle.Normal),
Font(Res.font.google_sans_semibold_italic, FontWeight.SemiBold, FontStyle.Italic),
Font(Res.font.google_sans_bold, FontWeight.Bold, FontStyle.Normal),
Font(Res.font.google_sans_bold_italic, FontWeight.Bold, FontStyle.Italic),
Font(Res.font.google_sans_flex),
)
it.copy(
displayLarge = it.displayLarge.copy(fontFamily = family),
displayMedium = it.displayMedium.copy(fontFamily = family),
displaySmall = it.displaySmall.copy(fontFamily = family),
headlineLarge = it.headlineLarge.copy(fontFamily = family),
headlineMedium = it.headlineMedium.copy(fontFamily = family),
headlineSmall = it.headlineSmall.copy(fontFamily = family),
titleLarge = it.titleLarge.copy(fontFamily = family),
titleMedium = it.titleMedium.copy(fontFamily = family),
titleSmall = it.titleSmall.copy(fontFamily = family),
bodyLarge = it.bodyLarge.copy(fontFamily = family),
bodyMedium = it.bodyMedium.copy(fontFamily = family),
bodySmall = it.bodySmall.copy(fontFamily = family),
labelLarge = it.labelLarge.copy(fontFamily = family),
labelMedium = it.labelMedium.copy(fontFamily = family),
labelSmall = it.labelSmall.copy(fontFamily = family),
)
}
return Typography().let {
it.copy(
displayLarge = it.displayLarge.copy(fontFamily = family),
displayMedium = it.displayMedium.copy(fontFamily = family),
displaySmall = it.displaySmall.copy(fontFamily = family),
headlineLarge = it.headlineLarge.copy(fontFamily = family),
headlineMedium = it.headlineMedium.copy(fontFamily = family),
headlineSmall = it.headlineSmall.copy(fontFamily = family),
titleLarge = it.titleLarge.copy(fontFamily = family),
titleMedium = it.titleMedium.copy(fontFamily = family),
titleSmall = it.titleSmall.copy(fontFamily = family),
bodyLarge = it.bodyLarge.copy(fontFamily = family),
bodyMedium = it.bodyMedium.copy(fontFamily = family),
bodySmall = it.bodySmall.copy(fontFamily = family),
labelLarge = it.labelLarge.copy(fontFamily = family),
labelMedium = it.labelMedium.copy(fontFamily = family),
labelSmall = it.labelSmall.copy(fontFamily = family),
)
}
}