diff --git a/.idea/artifacts/shared.xml b/.idea/artifacts/shared.xml index df2c7e6..59ff3f6 100644 --- a/.idea/artifacts/shared.xml +++ b/.idea/artifacts/shared.xml @@ -1,8 +1,6 @@ $PROJECT_DIR$/utils/shared/build/libs - - - + \ No newline at end of file diff --git a/.idea/artifacts/shared_jvm.xml b/.idea/artifacts/shared_jvm.xml index 2435e77..264b35f 100644 --- a/.idea/artifacts/shared_jvm.xml +++ b/.idea/artifacts/shared_jvm.xml @@ -1,8 +1,6 @@ $PROJECT_DIR$/utils/shared/build/libs - - - + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index 4f368d4..473f106 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -2,6 +2,6 @@ \ No newline at end of file diff --git a/.idea/runConfigurations/Android.xml b/.idea/runConfigurations/Android.xml new file mode 100644 index 0000000..e847ac8 --- /dev/null +++ b/.idea/runConfigurations/Android.xml @@ -0,0 +1,68 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Desktop.xml b/.idea/runConfigurations/Desktop.xml new file mode 100644 index 0000000..f8fa980 --- /dev/null +++ b/.idea/runConfigurations/Desktop.xml @@ -0,0 +1,27 @@ + + + + + + + true + true + false + false + false + false + false + + + \ No newline at end of file diff --git a/IDEA.md b/IDEA.md index 83ff357..f61bee8 100644 --- a/IDEA.md +++ b/IDEA.md @@ -1 +1 @@ -100% бесплатный и открытый мессенджер. +FromChat - 100% бесплатный и открытый мессенджер. diff --git a/app/shared/src/androidMain/kotlin/ru/fromchat/ui/components/BackHandler.android.kt b/app/shared/src/androidMain/kotlin/ru/fromchat/ui/components/BackHandler.android.kt index 3a9d453..f77f803 100644 --- a/app/shared/src/androidMain/kotlin/ru/fromchat/ui/components/BackHandler.android.kt +++ b/app/shared/src/androidMain/kotlin/ru/fromchat/ui/components/BackHandler.android.kt @@ -1,6 +1,8 @@ package ru.fromchat.ui.components import android.annotation.SuppressLint +import android.os.Build +import android.os.VibrationEffect import android.view.HapticFeedbackConstants import androidx.activity.BackEventCompat import androidx.activity.compose.PredictiveBackHandler @@ -44,15 +46,40 @@ actual fun rememberHapticFeedbackInternal(): (Int) -> Unit { val view = LocalView.current return remember(view) { { ordinal -> - val constant = when (ordinal) { - HapticFeedbackEvent.ProfileOpened.ordinal -> HapticFeedbackConstants.CLOCK_TICK - HapticFeedbackEvent.ProfileClosed.ordinal -> HapticFeedbackConstants.CLOCK_TICK - HapticFeedbackEvent.MessageSent.ordinal -> HapticFeedbackConstants.CONFIRM - HapticFeedbackEvent.ContextMenuOpened.ordinal -> HapticFeedbackConstants.CONFIRM - HapticFeedbackEvent.SelectionModeEntered.ordinal -> HapticFeedbackConstants.CONFIRM - else -> HapticFeedbackConstants.CLOCK_TICK + // Two-stage premium switch feel: SwitchPress → light tick, SwitchToggle → + // heavier commit click. On API 26+ we use the predefined-effect overload + // (VibrationEffect.EFFECT_TICK / EFFECT_CLICK) which routes to the system + // without VIBRATE permission and has built-in device fallback. On API 24-25 + // we fall back to the legacy int constants. + when (ordinal) { + HapticFeedbackEvent.SwitchPress.ordinal -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + view.performHapticFeedback(0, VibrationEffect.EFFECT_TICK) + } else { + view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK) + } + } + + HapticFeedbackEvent.SwitchToggle.ordinal -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + view.performHapticFeedback(0, VibrationEffect.EFFECT_CLICK) + } else { + view.performHapticFeedback(HapticFeedbackConstants.CONFIRM) + } + } + + else -> { + val constant = when (ordinal) { + HapticFeedbackEvent.ProfileOpened.ordinal -> HapticFeedbackConstants.CLOCK_TICK + HapticFeedbackEvent.ProfileClosed.ordinal -> HapticFeedbackConstants.CLOCK_TICK + HapticFeedbackEvent.MessageSent.ordinal -> HapticFeedbackConstants.CONFIRM + HapticFeedbackEvent.ContextMenuOpened.ordinal -> HapticFeedbackConstants.CONFIRM + HapticFeedbackEvent.SelectionModeEntered.ordinal -> HapticFeedbackConstants.CONFIRM + else -> HapticFeedbackConstants.CLOCK_TICK + } + view.performHapticFeedback(constant) + } } - view.performHapticFeedback(constant) } } } diff --git a/app/shared/src/androidMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.android.kt b/app/shared/src/androidMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.android.kt new file mode 100644 index 0000000..6a49393 --- /dev/null +++ b/app/shared/src/androidMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.android.kt @@ -0,0 +1,5 @@ +package ru.fromchat.ui.main.settings + +// On Android, Compose MP's android renderer cannot load .svg +// painter resources and throws. +actual fun svgDrawablesSupported(): Boolean = false diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_bold.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_bold.ttf deleted file mode 100644 index 71b847f..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_bold.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_bold_italic.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_bold_italic.ttf deleted file mode 100644 index 82e0e6a..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_bold_italic.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_flex.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_flex.ttf new file mode 100644 index 0000000..0ca1de3 Binary files /dev/null and b/app/shared/src/commonMain/composeResources/font/google_sans_flex.ttf differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_italic.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_italic.ttf deleted file mode 100644 index 1f9059a..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_italic.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_medium.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_medium.ttf deleted file mode 100644 index 8b9aebc..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_medium.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_medium_italic.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_medium_italic.ttf deleted file mode 100644 index 407b297..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_medium_italic.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_regular.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_regular.ttf deleted file mode 100644 index cc37c3f..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_regular.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_rounded_regular.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_rounded_regular.ttf new file mode 100644 index 0000000..db3efea Binary files /dev/null and b/app/shared/src/commonMain/composeResources/font/google_sans_rounded_regular.ttf differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_semibold.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_semibold.ttf deleted file mode 100644 index b80284d..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_semibold.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/font/google_sans_semibold_italic.ttf b/app/shared/src/commonMain/composeResources/font/google_sans_semibold_italic.ttf deleted file mode 100644 index 4d34849..0000000 Binary files a/app/shared/src/commonMain/composeResources/font/google_sans_semibold_italic.ttf and /dev/null differ diff --git a/app/shared/src/commonMain/composeResources/values-ru/strings.xml b/app/shared/src/commonMain/composeResources/values-ru/strings.xml index dcb2df8..6cff6ba 100644 --- a/app/shared/src/commonMain/composeResources/values-ru/strings.xml +++ b/app/shared/src/commonMain/composeResources/values-ru/strings.xml @@ -341,6 +341,12 @@ Оформление Тема и Material You + Стиль панели навигации + Как выглядит нижняя панель навигации + Классическая + Плавающая + Показывать названия вкладок + Показывать подпись выбранной вкладки Сервер и инструменты Смена сервера, отладка API Уведомления diff --git a/app/shared/src/commonMain/composeResources/values/strings.xml b/app/shared/src/commonMain/composeResources/values/strings.xml index 4d1fda0..4f94d13 100644 --- a/app/shared/src/commonMain/composeResources/values/strings.xml +++ b/app/shared/src/commonMain/composeResources/values/strings.xml @@ -373,6 +373,12 @@ Appearance Theme and Material You + Navigation bar style + How the bottom navigation bar looks + Traditional + Floating + Show tab titles + Reveal the label of the selected tab Server and tools Change server, debug API Notifications diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/config/Settings.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/config/Settings.kt index 9724020..d97b664 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/config/Settings.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/config/Settings.kt @@ -30,6 +30,8 @@ object Settings { private const val LAST_SERVER_INSTANCE_ID_KEY = "last_server_instance_id" private const val LAST_ACKNOWLEDGED_APP_VERSION_KEY = "last_acknowledged_app_version" private const val RELEASE_NOTES_PERMANENTLY_HIDDEN_KEY = "release_notes_permanently_hidden" + private const val NAV_BAR_STYLE_KEY = "nav_bar_style" + private const val NAV_BAR_SHOW_TITLE_KEY = "nav_bar_show_title" private val settings = PlatformSettings() private val deviceSessionsJson = Json { ignoreUnknownKeys = true } @@ -83,6 +85,20 @@ object Settings { get() = runBlocking { Theme.entries[settings.getInt(THEME_KEY, Theme.AsSystem.ordinal)] } set(value) = runIO { settings.putInt(THEME_KEY, value.ordinal) } + var navBarStyle: NavBarStyle + get() = runBlocking { + NavBarStyle.entries[settings.getInt(NAV_BAR_STYLE_KEY, NavBarStyle.Floating.ordinal)] + } + set(value) = runIO { settings.putInt(NAV_BAR_STYLE_KEY, value.ordinal) } + + /** + * When true, compact (single-pane) detail screens use the Pixel top app bar + * with an app "seed" chip instead of the stock collapsing app bar. + */ + var navBarShowTitle: Boolean + get() = runBlocking { settings.getBoolean(NAV_BAR_SHOW_TITLE_KEY, true) } + set(value) = runIO { settings.putBoolean(NAV_BAR_SHOW_TITLE_KEY, value) } + /** * When true, Enter sends the message and Shift+Enter inserts a newline. * When false, Enter inserts a newline (previous composer behavior). @@ -204,3 +220,12 @@ object Settings { get() = runBlocking { settings.getBoolean(RELEASE_NOTES_PERMANENTLY_HIDDEN_KEY, false) } set(value) = runIO { settings.putBoolean(RELEASE_NOTES_PERMANENTLY_HIDDEN_KEY, value) } } + +/** Main-screen bottom navigation bar style. */ +enum class NavBarStyle { + /** Standard [androidx.compose.material3.NavigationBar] with icon + text labels. */ + Traditional, + + /** Floating, fully-rounded pill bar (drag-to-swap, colorful haze). */ + Floating, +} diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/App.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/App.kt index 0647c7e..2194648 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/App.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/App.kt @@ -98,6 +98,7 @@ import ru.fromchat.ui.chat.panels.dm.navigateToDmChat import ru.fromchat.ui.chat.panels.publicchat.PublicChatNav import ru.fromchat.ui.chat.panels.publicchat.navigateToPublicChat import ru.fromchat.ui.chat.utils.appRootAttachmentDropTarget +import ru.fromchat.ui.components.provideSwitchHaptics import ru.fromchat.ui.main.ConversationListDetailShell import ru.fromchat.ui.main.DesktopChatsDetailNavHost import ru.fromchat.ui.main.DesktopContactsDetailNavHost @@ -142,6 +143,10 @@ private fun standaloneProfileUserId(entry: NavBackStackEntry?): Int? { return entry.savedStateHandle.get("userId")?.toIntOrNull()?.takeIf { it > 0 } } +/** + * Root NavHost transitions — scale+fade for the primary + * flow (welcome ↔ auth ↔ chat). + */ private val rootNavTween = tween(durationMillis = 250, easing = FastOutSlowInEasing) private fun rootNavEnterTransition(): EnterTransition = @@ -356,6 +361,7 @@ fun App( } FromChatTheme { + provideSwitchHaptics { SharedTransitionLayout { val navController = rememberNavController() val chatsDetailNavController = rememberNavController() @@ -778,6 +784,7 @@ fun App( } } } + } } } diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/MotionTokens.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/MotionTokens.kt new file mode 100644 index 0000000..b441021 --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/MotionTokens.kt @@ -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( + dampingRatio = Spring.DampingRatioMediumBouncy, + stiffness = Spring.StiffnessLow, +) + +/** Standard interaction spring — press feedback, chip expansion. Snappy. */ +val StandardSpring = spring( + 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( + dampingRatio = 0.82f, + stiffness = 240f, +) + +/** Full / CTA shape (nav pill, primary buttons) — fully rounded. */ +val FullCtaShape: Shape = CircleShape diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/Theme.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/Theme.kt index 7126f81..d2bc6da 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/Theme.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/Theme.kt @@ -2,15 +2,19 @@ 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.NavBarStyle import ru.fromchat.config.Settings -import ru.fromchat.ui.components.googleSansMaterialTypography +import ru.fromchat.ui.components.googleSansFlexTypography enum class Theme { AsSystem, @@ -26,6 +30,26 @@ var theme by mutableStateOf( runCatching { Settings.theme }.getOrNull() ?: Theme.AsSystem ) +var navBarStyle by mutableStateOf( + runCatching { Settings.navBarStyle }.getOrNull() ?: NavBarStyle.Floating +) + +var navBarShowTitle by mutableStateOf( + runCatching { Settings.navBarShowTitle }.getOrNull() ?: true +) + +/** + * 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 +146,8 @@ fun FromChatTheme( MaterialTheme( colorScheme = colorScheme, - typography = googleSansMaterialTypography(), + typography = googleSansFlexTypography(), + shapes = expressiveShapes, content = content ) } diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/ExpressiveListItem.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/ExpressiveListItem.kt new file mode 100644 index 0000000..0072d05 --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/ExpressiveListItem.kt @@ -0,0 +1,73 @@ +package ru.fromchat.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.unit.dp +import com.pr0gramm3r101.components.ListItem +import com.pr0gramm3r101.components.ListItemContextMenuScope +import com.pr0gramm3r101.components.ListItemPosition +import tech.annexflow.constraintlayout.compose.ConstraintLayoutScope + +/** + * A [ListItem] with the "expressive" settings-card look: a soft colored icon + * chip (40dp tile, full-round corners) behind a 26dp glyph, on a + * `surfaceBright` card. Everything else (press scaling, dividers, group + * clipping, context menus) is inherited from the base [ListItem]. + * + * @param icon The icon to draw inside the chip. + * @param iconPreset The background + foreground (glyph) colors for the chip. + */ +@Composable +fun ExpressiveListItem( + icon: ImageVector, + iconPreset: IconPreset = ExpressiveTints.Purple, + headline: String, + supportingText: String? = null, + modifier: Modifier = Modifier, + trailingContent: (@Composable ConstraintLayoutScope.() -> Unit)? = null, + enabled: Boolean = true, + divider: Boolean = false, + position: ListItemPosition = ListItemPosition.MIDDLE, + groupItemCount: Int? = null, + onClick: (() -> Unit)? = null, + onContextMenuOpen: (() -> Unit)? = null, + contextMenu: (ListItemContextMenuScope.() -> Unit)? = null, +) { + ListItem( + modifier = modifier, + headline = headline, + supportingText = supportingText, + leadingContent = { + Box( + modifier = Modifier + .size(40.dp) + .background(iconPreset.background, shape = CircleShape), + contentAlignment = Alignment.Center, + ) { + Icon( + imageVector = icon, + contentDescription = null, + tint = iconPreset.foreground, + modifier = Modifier.size(26.dp), + ) + } + }, + trailingContent = trailingContent, + containerColor = MaterialTheme.colorScheme.surfaceBright, + enabled = enabled, + divider = divider, + position = position, + groupItemCount = groupItemCount, + onClick = onClick, + onContextMenuOpen = onContextMenuOpen, + contextMenu = contextMenu, + ) +} diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/ExpressiveTints.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/ExpressiveTints.kt new file mode 100644 index 0000000..1a7992f --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/ExpressiveTints.kt @@ -0,0 +1,43 @@ +package ru.fromchat.ui.components + +import androidx.compose.ui.graphics.Color + +/** + * A paired icon-tile color preset for the expressive list items / nav bar: a + * "background" fill behind a matching "foreground" (glyph) color. Each preset is + * a self-contained, reusable chip color extracted from the reference design. + */ +class IconPreset( + val background: Color, + val foreground: Color, +) + +/** + * The fixed set of [IconPreset]s used by the settings list and the floating nav + * bar. Values are pulled directly from the Vaffuru reference (bg / fg pairs). + */ +object ExpressiveTints { + /** Light lavender chip, deep-violet glyph. */ + val Purple = IconPreset(Color(0xFFB89CD1), Color(0xFF5229A4)) + + /** Deep violet chip, magenta glyph. */ + val Rose = IconPreset(Color(0xFFD492BF), Color(0xFF8C0052)) + + /** Gold chip, brown glyph. */ + val Yellow = IconPreset(Color(0xFFD29E0A), Color(0xFF693801)) + + /** Warm terracotta chip, dark-brown glyph. */ + val Orange = IconPreset(Color(0xFFD39B71), Color(0xFF783707)) + + /** Green chip, deep-green glyph. */ + val Green = IconPreset(Color(0xFF70B576), Color(0xFF00512B)) + + /** Sky-blue chip, deep-navy glyph. Good fit for "identity / account" items. */ + val Blue = IconPreset(Color(0xFFA1C9FF), Color(0xFF04409F)) + + /** Cyan chip, deep-teal glyph. Good fit for "server / network" items. */ + val Cyan = IconPreset(Color(0xFF67D4FF), Color(0xFF004D68)) + + /** Neutral surface tile (accent / default). */ + val NeutralTile: Color = Color(0xFF1C1C1C).copy(alpha = 0.06f) +} diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/FloatingNavBar.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/FloatingNavBar.kt new file mode 100644 index 0000000..69b0039 --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/FloatingNavBar.kt @@ -0,0 +1,270 @@ +package ru.fromchat.ui.components + +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.core.tween +import androidx.compose.animation.expandHorizontally +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkHorizontally +import androidx.compose.foundation.clickable +import androidx.compose.foundation.gestures.detectDragGestures +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateMapOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.layout.LayoutCoordinates +import androidx.compose.ui.layout.boundsInRoot +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.platform.LocalHapticFeedback +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.zIndex +import dev.chrisbanes.haze.HazeState +import kotlin.math.abs + +/** + * A single item in a [FloatingNavBar]. When [selected], the item is expanded + * to reveal its [label] and drawn on a tone-container pill (secondaryContainer) + * to highlight it. When not selected, the item is a plain round chip with + * no container color. + */ +@Composable +private fun FloatingNavItem( + icon: ImageVector, + label: String, + selected: Boolean, + showTitle: Boolean, + onClick: () -> Unit, + onPositioned: (LayoutCoordinates) -> Unit, +) { + val contentColor by animateColorAsState( + targetValue = if (selected) { + MaterialTheme.colorScheme.onSecondaryContainer + } else { + MaterialTheme.colorScheme.onSurfaceVariant + }, + animationSpec = tween(300), + label = "navItemContentColor", + ) + val containerColor by animateColorAsState( + targetValue = if (selected) { + MaterialTheme.colorScheme.secondaryContainer + } else { + Color.Transparent + }, + animationSpec = tween(300), + label = "navItemContainerColor", + ) + val interactionSource = remember { MutableInteractionSource() } + + Surface( + modifier = Modifier + .onGloballyPositioned { onPositioned(it) } + .clip(CircleShape) + .clickable( + interactionSource = interactionSource, + indication = null, + onClick = onClick, + ), + shape = CircleShape, + color = containerColor, + ) { + Row( + modifier = Modifier.padding(horizontal = 12.dp, vertical = 12.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, + ) { + Icon( + imageVector = icon, + contentDescription = label, + tint = contentColor, + modifier = Modifier.size(22.dp), + ) + AnimatedVisibility( + visible = selected && showTitle, + enter = expandHorizontally(animationSpec = tween(300)) + fadeIn(animationSpec = tween(300)), + exit = shrinkHorizontally(animationSpec = tween(300)) + fadeOut(animationSpec = tween(300)), + ) { + Text( + text = label, + modifier = Modifier.padding(start = 8.dp), + color = contentColor, + style = MaterialTheme.typography.labelMedium, + maxLines = 1, + softWrap = false, + overflow = TextOverflow.Ellipsis, + ) + } + } + } +} + +/** + * A floating, fully-rounded (CircleShape) pill navigation bar with: + * * a subtle primary-tinted haze backdrop (the "colorful" blur), + * * an expanded selected-state that reveals the item label on tap, + * * a tonal (secondaryContainer) pill highlight on the selected item, + * * a drag-to-swap gesture (hold + slide across the bar). + * + * The bar is centered horizontally within its parent; the parent is expected to + * handle window-inset padding (status / navigation bars, IME) before calling + * this composable. + * + * @param items The items to render. Exactly one should have `selected = true`. + * @param selectedId The id of the currently selected item (label reveal + pill highlight). + * @param onItemClick Called on tap with the item id. + * @param onSwap Called when a drag-to-swap gesture completes over another item. + * @param hazeState Optional [HazeState]; when present, the pill uses a tinted + * haze backdrop. When null, `containerColor` is used instead. + */ +@Composable +fun FloatingNavBar( + items: List, + selectedId: String, + showTitles: Boolean = true, + onItemClick: (String) -> Unit, + onSwap: (String) -> Unit = {}, + modifier: Modifier = Modifier, + hazeState: HazeState? = null, + containerColor: Color = MaterialTheme.colorScheme.surfaceContainerLow, + tint: Color = MaterialTheme.colorScheme.primary, +) { + val itemCoordinates = remember { mutableStateMapOf() } + val rootBounds = remember { mutableMapOf() } + var isDragging by remember { mutableStateOf(false) } + var dragTargetId by remember { mutableStateOf(null) } + val haptic = LocalHapticFeedback.current + + fun updateBounds() { + itemCoordinates.forEach { (id, coords) -> + if (coords.isAttached) { + rootBounds[id] = coords.boundsInRoot() + } + } + } + + fun dragNearest(targetX: Float): String? { + return items.minByOrNull { item -> + val rect = rootBounds[item.id] + if (rect != null) { + val centerX = rect.left + rect.width / 2 + abs(centerX - targetX) + } else { + Float.MAX_VALUE + } + }?.id + } + + fun endDrag() { + val target = dragTargetId + isDragging = false + dragTargetId = null + if (target != null && target != selectedId) { + onSwap(target) + } + } + + val surfaceColor = if (hazeState != null) Color.Transparent else containerColor + + // Outer Box: fill parent width, center horizontally. Inner Surface: natural + // width capped at 620dp so it reads as a floating pill (not full-width). + Box( + modifier = modifier, + contentAlignment = Alignment.Center, + ) { + Surface( + shape = CircleShape, + color = surfaceColor, + shadowElevation = 8.dp, + modifier = Modifier + .widthIn(max = 620.dp) + .zIndex(1f) + .clip(CircleShape) + .then(if (hazeState != null) Modifier.tintedHaze(hazeState, tint = tint) else Modifier), + ) { + Row( + modifier = Modifier + .wrapContentWidth(Alignment.Start) + .padding(8.dp) + .pointerInput(Unit) { + detectDragGestures( + onDragStart = { offset -> + isDragging = true + updateBounds() + val container = itemCoordinates.values.firstOrNull() + if (container != null && container.isAttached) { + val rootTouchX = container.localToRoot(offset).x + dragTargetId = dragNearest(rootTouchX) + } + }, + onDragEnd = { endDrag() }, + onDragCancel = { endDrag() }, + onDrag = { change, _ -> + change.consume() + val coords = itemCoordinates.values.firstOrNull() + if (coords != null && coords.isAttached) { + val rootTouchX = coords.localToRoot(change.position).x + val nearest = dragNearest(rootTouchX) + if (nearest != dragTargetId) { + dragTargetId = nearest + if (nearest != null) { + haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove) + } + } + } + }, + ) + }, + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, + ) { + items.forEach { item -> + if (item.id != items.first().id) { + Spacer(modifier = Modifier.width(4.dp)) + } + FloatingNavItem( + icon = item.icon, + label = item.label, + selected = item.id == selectedId, + showTitle = showTitles, + onClick = { onItemClick(item.id) }, + onPositioned = { itemCoordinates[item.id] = it }, + ) + } + } + } + } +} + +/** A spec for an item in a [FloatingNavBar]. */ +data class FloatingNavItemSpec( + val id: String, + val icon: ImageVector, + val label: String, +) diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/HazeTint.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/HazeTint.kt new file mode 100644 index 0000000..6c33b9e --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/HazeTint.kt @@ -0,0 +1,36 @@ +package ru.fromchat.ui.components + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import dev.chrisbanes.haze.HazeInput +import dev.chrisbanes.haze.HazeState +import dev.chrisbanes.haze.blur.HazeColorEffect +import dev.chrisbanes.haze.blur.hazeBlur +import dev.chrisbanes.haze.blur.materials.HazeMaterials + +private const val DEFAULT_TINT_ALPHA = 0.06f + +/** + * Applies [HazeMaterials.thin] with a subtle primary-color [tint] on top, + * producing the "colorful blur" look from the Pixel-styled redesign. Use on + * the nav bar and any panel/chrome surface where we want the blur to pick up + * a little color. Search bars and text fields should **not** use it. + * + * @param hazeState The [HazeState] to blur against (must have matching + * `.hazeSource(hazeState)` ancestors). + * @param tint The color to tint the blurred backdrop with. + * @param alpha How visible the tint is, 0.0 = no tint, 1.0 = full tint. + */ +@Composable +fun Modifier.tintedHaze( + hazeState: HazeState, + tint: Color = MaterialTheme.colorScheme.primary, + alpha: Float = DEFAULT_TINT_ALPHA, +): Modifier = hazeBlur( + input = HazeInput.Backdrop(hazeState), + style = HazeMaterials.thin().then { + colorEffects(listOf(HazeColorEffect.tint(tint.copy(alpha = alpha)))) + }, +) diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/PixelTopAppBar.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/PixelTopAppBar.kt new file mode 100644 index 0000000..dd667d7 --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/PixelTopAppBar.kt @@ -0,0 +1,168 @@ +package ru.fromchat.ui.components + +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.animation.core.spring +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Menu +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import kotlinx.coroutines.delay +import kotlin.time.Duration.Companion.milliseconds + +/** + * Word-by-word staggered reveal for the app bar title. Each word fades and + * rises in with a small per-word delay, giving the deliberate "reflow" feel. + * Re-runs whenever [text] changes. + */ +/** + * Word-by-word staggered reveal for the app bar title. Each word fades and + * rises in with a small per-word delay, giving the deliberate "reflow" feel. + * Re-runs whenever [text] changes. + */ +@Composable +fun AnimatedWordTitle( + text: String, + modifier: Modifier = Modifier, +) { + val words = remember(text) { text.split(" ") } + var generation by remember { mutableIntStateOf(0) } + LaunchedEffect(text) { + generation++ + } + + Row( + modifier = modifier, + horizontalArrangement = Arrangement.Start, + verticalAlignment = Alignment.CenterVertically, + ) { + words.forEachIndexed { index, word -> + var visible by remember { mutableStateOf(false) } + LaunchedEffect(generation) { + visible = false + delay((index * 45).milliseconds) + visible = true + } + val alpha by animateFloatAsState( + targetValue = if (visible) 1f else 0f, + animationSpec = spring(dampingRatio = 0.82f, stiffness = 240f), + label = "pTitleWordAlpha$index", + ) + Box( + modifier = Modifier.alpha(alpha), + ) { + Text( + text = word, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + if (index < words.lastIndex) { + Spacer(modifier = Modifier.width(8.dp)) + } + } + } +} + +/** + * A Pixel-style compact top app bar: an app "seed" chip on the leading edge + * (replacing the old back-arrow slot), a word-by-word animated title, and + * optional trailing actions. Intentionally **not** the stock M3 [TopAppBar] — + * the title refills via the staggered [AnimatedWordTitle]. + * + * @param title The plain title text (split into words for the reveal). + * @param topPadding Top padding to apply above the bar (status-bar insets, etc). + * @param leadingIcon Icon drawn in the round chip (defaults to a menu icon). + * @param onLeadingAction Invoked when the leading chip is tapped (optional). + * @param trailingActions Trailing action slot. + */ +@Composable +fun PixelTopAppBar( + title: String, + modifier: Modifier = Modifier, + topPadding: Dp = 0.dp, + leadingIcon: ImageVector = Icons.Default.Menu, + leadingTint: Color = MaterialTheme.colorScheme.surfaceBright, + leadingSubTint: Color = MaterialTheme.colorScheme.onSurface, + onLeadingAction: (() -> Unit)? = null, + trailingActions: @Composable RowScope.() -> Unit = {}, + containerColor: Color = Color.Transparent, +) { + Surface( + modifier = modifier.fillMaxWidth(), + color = containerColor, + content = { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(top = topPadding), + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp) + .height(64.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + if (onLeadingAction != null) { + IconButton( + onClick = onLeadingAction, + modifier = Modifier.size(48.dp), + ) { + Box( + modifier = Modifier + .size(40.dp) + .background(leadingTint, shape = CircleShape), + contentAlignment = Alignment.Center, + ) { + Icon( + imageVector = leadingIcon, + contentDescription = null, + tint = leadingSubTint, + modifier = Modifier.size(26.dp), + ) + } + } + } + AnimatedWordTitle( + text = title, + modifier = Modifier + .weight(1f) + .padding(horizontal = 16.dp), + ) + trailingActions() + } + } + }, + ) +} diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/SwitchHaptics.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/SwitchHaptics.kt new file mode 100644 index 0000000..e874426 --- /dev/null +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/SwitchHaptics.kt @@ -0,0 +1,35 @@ +package ru.fromchat.ui.components + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import com.pr0gramm3r101.components.LocalSwitchHaptic +import ru.fromchat.utils.haptic.HapticFeedbackEvent +import ru.fromchat.utils.haptic.rememberHapticFeedback + +/** + * Provides the real haptic-firing lambda to every `SwitchListItem` in the subtree. + * Call once at the app root (e.g., inside `@Preview`/`App`/main activity content). + * + * - `SwitchPress` (light tick on touch-down) → `VibrationEffect.EFFECT_TICK` (API 26+) + * or `HapticFeedbackConstants.CLOCK_TICK` (API 24–25) on Android; `UIImpactFeedbackStyleLight` + * on iOS; no-op on Desktop. + * - `SwitchToggle` (heavier commit click when state flips) → `VibrationEffect.EFFECT_CLICK` + * / `HapticFeedbackConstants.CONFIRM` on Android; `UIImpactFeedbackStyleHeavy` on iOS. + * + * The default [LocalSwitchHaptic] is a no-op, so a screen that forgets to call this + * provider still renders correctly — it just doesn't vibrate. + */ +@Composable +fun provideSwitchHaptics(content: @Composable () -> Unit) { + val fire = rememberHapticFeedback() + CompositionLocalProvider( + LocalSwitchHaptic provides { ordinal: Int -> + // Map integer ordinal → enum by position. The enum ordinals are stable + // because we only append at the end (see HapticFeedbackEvent.kt). + val event = HapticFeedbackEvent.entries.getOrNull(ordinal) + if (event != null) fire(event) + }, + ) { + content() + } +} diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/Typography.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/Typography.kt index 671db1e..6699e7c 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/Typography.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/components/Typography.kt @@ -2,48 +2,142 @@ package ru.fromchat.ui.components import androidx.compose.material3.Typography import androidx.compose.runtime.Composable +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp 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_rounded_regular +/** + * Typography matching Vaffuru's expressive Material 3 look. + * + * Font: **Google Sans Rounded** (the `zE.ttf` shipped in the Vaffuru APK — OFL, + * weight-class 500, 36k glyphs with full Latin + Cyrillic + Greek coverage). + * Multiple weight instances are registered (300–900) so Compose picks the + * closest available weight per role. + * + * Vaffuru's `s27.java` uses a single FontFamily of `google_sans_rounded_regular` + * with 6 weight slots (300, 400, 500, 600, 700, 900) plus ROND=100 + wght + * variable settings (no-op for a non-variable font, kept for intent). + */ @Composable -fun googleSansMaterialTypography() = Typography().let { +fun googleSansFlexTypography(): Typography { 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_rounded_regular, FontWeight(300)), + Font(Res.font.google_sans_rounded_regular, FontWeight(400)), + Font(Res.font.google_sans_rounded_regular, FontWeight(500)), + Font(Res.font.google_sans_rounded_regular, FontWeight(600)), + Font(Res.font.google_sans_rounded_regular, FontWeight(700)), + Font(Res.font.google_sans_rounded_regular, FontWeight(900)), ) - 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( + displayLarge = TextStyle( + fontFamily = family, + fontSize = 48.sp, + fontWeight = FontWeight(700), + lineHeight = 56.sp, + letterSpacing = 0.sp, + ), + displayMedium = TextStyle( + fontFamily = family, + fontSize = 36.sp, + fontWeight = FontWeight(700), + lineHeight = 44.sp, + letterSpacing = 0.sp, + ), + displaySmall = TextStyle( + fontFamily = family, + fontSize = 30.sp, + fontWeight = FontWeight(400), + lineHeight = 38.sp, + letterSpacing = 0.sp, + ), + headlineLarge = TextStyle( + fontFamily = family, + fontSize = 32.sp, + fontWeight = FontWeight(600), + lineHeight = 40.sp, + letterSpacing = 0.sp, + ), + headlineMedium = TextStyle( + fontFamily = family, + fontSize = 28.sp, + fontWeight = FontWeight(600), + lineHeight = 36.sp, + letterSpacing = 0.sp, + ), + headlineSmall = TextStyle( + fontFamily = family, + fontSize = 24.sp, + fontWeight = FontWeight(600), + lineHeight = 32.sp, + letterSpacing = 0.sp, + ), + titleLarge = TextStyle( + fontFamily = family, + fontSize = 22.sp, + fontWeight = FontWeight(400), + lineHeight = 28.sp, + letterSpacing = 0.sp, + ), + titleMedium = TextStyle( + fontFamily = family, + fontSize = 18.sp, + fontWeight = FontWeight(500), + lineHeight = 24.sp, + letterSpacing = 0.15.sp, + ), + titleSmall = TextStyle( + fontFamily = family, + fontSize = 14.sp, + fontWeight = FontWeight(500), + lineHeight = 20.sp, + letterSpacing = 0.1.sp, + ), + bodyLarge = TextStyle( + fontFamily = family, + fontSize = 16.sp, + fontWeight = FontWeight(400), + lineHeight = 24.sp, + letterSpacing = 0.5.sp, + ), + bodyMedium = TextStyle( + fontFamily = family, + fontSize = 14.sp, + fontWeight = FontWeight(400), + lineHeight = 20.sp, + letterSpacing = 0.25.sp, + ), + bodySmall = TextStyle( + fontFamily = family, + fontSize = 12.sp, + fontWeight = FontWeight(400), + lineHeight = 16.sp, + letterSpacing = 0.4.sp, + ), + labelLarge = TextStyle( + fontFamily = family, + fontSize = 16.sp, + fontWeight = FontWeight(500), + lineHeight = 20.sp, + letterSpacing = 0.1.sp, + ), + labelMedium = TextStyle( + fontFamily = family, + fontSize = 14.sp, + fontWeight = FontWeight(500), + lineHeight = 16.sp, + letterSpacing = 0.5.sp, + ), + labelSmall = TextStyle( + fontFamily = family, + fontSize = 11.sp, + fontWeight = FontWeight(500), + lineHeight = 16.sp, + letterSpacing = 0.5.sp, + ), ) -} \ No newline at end of file +} diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainDetailDestinations.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainDetailDestinations.kt index 562258a..bd19b0b 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainDetailDestinations.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainDetailDestinations.kt @@ -46,7 +46,9 @@ fun NavGraphBuilder.conversationDetailDestinations( sharedTransitionScope: SharedTransitionScope, scrollToMessageId: Int?, ) { - composable(PublicChatNav.CHAT_ROUTE) { + composable( + route = PublicChatNav.CHAT_ROUTE, + ) { PublicChatChatRoute( scrollToMessageId = scrollToMessageId, navController = navController, @@ -55,7 +57,9 @@ fun NavGraphBuilder.conversationDetailDestinations( ) } - composable(PublicChatNav.PROFILE_ROUTE) { + composable( + route = PublicChatNav.PROFILE_ROUTE, + ) { PublicChatProfileRoute( navController = navController, sharedTransitionScope = sharedTransitionScope, diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainScreen.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainScreen.kt index 42f0e44..6423d59 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainScreen.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainScreen.kt @@ -64,16 +64,21 @@ import org.jetbrains.compose.resources.stringResource import ru.fromchat.Res import ru.fromchat.api.ApiClient import ru.fromchat.chats +import ru.fromchat.config.NavBarStyle import ru.fromchat.contacts import ru.fromchat.desktop.DesktopMenuCommand import ru.fromchat.desktop.DesktopMenuCommands import ru.fromchat.profile import ru.fromchat.settings import ru.fromchat.ui.LocalNavController +import ru.fromchat.ui.navBarShowTitle +import ru.fromchat.ui.navBarStyle import ru.fromchat.ui.chat.rememberChatSurfaceContainerHazeStyle import ru.fromchat.ui.chat.panels.dm.navigateToDmChat import ru.fromchat.ui.components.BackHandler import ru.fromchat.ui.components.FromChatSnackbarHost +import ru.fromchat.ui.components.FloatingNavBar +import ru.fromchat.ui.components.FloatingNavItemSpec import ru.fromchat.ui.components.LocalPaneHazeState import ru.fromchat.ui.components.Text import ru.fromchat.ui.extraStatusBars @@ -82,6 +87,7 @@ import ru.fromchat.ui.main.chats.ChatContextMenuOverlayHost import ru.fromchat.ui.main.chats.ChatsSearchScreen import ru.fromchat.ui.main.chats.ChatsTab import ru.fromchat.ui.main.settings.SettingsTab +import ru.fromchat.config.Settings as AppSettings import ru.fromchat.ui.profile.ProfileScreen const val MAIN_PAGE_CHATS = 0 @@ -263,6 +269,7 @@ fun MainScreen( val contactsLabel = stringResource(Res.string.contacts) val settingsLabel = stringResource(Res.string.settings) val profileLabel = stringResource(Res.string.profile) + val navBarStyle = navBarStyle BoxWithConstraints( Modifier.fillMaxSize(), @@ -342,9 +349,60 @@ fun MainScreen( bottomChromeHeightDp = measured } } - .background(MaterialTheme.colorScheme.surfaceContainer) - .hazeBlur(input = HazeInput.Backdrop(navBarHazeState), style = navBarHazeStyle), + .then( + if (navBarStyle == NavBarStyle.Floating) { + Modifier.padding( + start = 16.dp, + end = 16.dp, + top = 16.dp, + bottom = 16.dp + WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).let { + with(density) { it.getBottom(this).toDp() } + }, + ) + } else { + Modifier + .background(MaterialTheme.colorScheme.surfaceContainer) + .hazeBlur(input = HazeInput.Backdrop(navBarHazeState), style = navBarHazeStyle) + }, + ), ) { + if (navBarStyle == NavBarStyle.Floating) { + FloatingNavBar( + modifier = Modifier.fillMaxWidth(), + items = + listOf( + FloatingNavItemSpec(PAGE_CHATS.toString(), Icons.AutoMirrored.Filled.Chat, chatsLabel), + FloatingNavItemSpec(PAGE_CONTACTS.toString(), Icons.Filled.Contacts, contactsLabel), + FloatingNavItemSpec(PAGE_SETTINGS.toString(), Icons.Filled.Settings, settingsLabel), + FloatingNavItemSpec(PAGE_PROFILE.toString(), Icons.Filled.Person, profileLabel), + ), + selectedId = selectedPage.toString(), + showTitles = navBarShowTitle, + onItemClick = { id -> + id.toIntOrNull()?.let { page -> + selectMainPage( + page = page, + widthClass = widthClass, + scope = scope, + pagerState = pagerState, + settingsDetailNavController = settingsDetailNavController, + ) + } + }, + onSwap = { id -> + id.toIntOrNull()?.let { page -> + selectMainPage( + page = page, + widthClass = widthClass, + scope = scope, + pagerState = pagerState, + settingsDetailNavController = settingsDetailNavController, + ) + } + }, + hazeState = navBarHazeState, + ) + } else { NavigationBar( modifier = Modifier.fillMaxWidth(), containerColor = Color.Transparent, @@ -422,6 +480,7 @@ fun MainScreen( }, ) } + } } } diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AboutScreen.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AboutScreen.kt index 3b57aaa..aa3b203 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AboutScreen.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AboutScreen.kt @@ -30,7 +30,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.pr0gramm3r101.components.Category import com.pr0gramm3r101.components.ListItem @@ -77,13 +76,7 @@ fun AboutScreen() { containerColor = MaterialTheme.colorScheme.background, topBar = { SettingsDetailTopBar( - title = { - Text( - stringResource(Res.string.about), - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - }, + title = stringResource(Res.string.about), onBack = { navController.navigateUp() }, scrollBehavior = scrollBehavior, ) diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AppearanceScreen.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AppearanceScreen.kt index ced6611..d724e9b 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AppearanceScreen.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/AppearanceScreen.kt @@ -39,7 +39,14 @@ import com.pr0gramm3r101.utils.conditional import com.pr0gramm3r101.utils.materialYouAvailable import org.jetbrains.compose.resources.stringResource import ru.fromchat.Res +import ru.fromchat.appearance_nav_bar_floating +import ru.fromchat.appearance_nav_bar_show_titles +import ru.fromchat.appearance_nav_bar_show_titles_d +import ru.fromchat.appearance_nav_bar_style +import ru.fromchat.appearance_nav_bar_style_d +import ru.fromchat.appearance_nav_bar_traditional import ru.fromchat.as_system +import ru.fromchat.config.NavBarStyle import ru.fromchat.config.Settings import ru.fromchat.dark import ru.fromchat.enter_to_send @@ -52,6 +59,8 @@ import ru.fromchat.theme import ru.fromchat.ui.Theme import ru.fromchat.ui.components.Text import ru.fromchat.ui.dynamicThemeEnabled +import ru.fromchat.ui.navBarShowTitle +import ru.fromchat.ui.navBarStyle import ru.fromchat.ui.theme @OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @@ -70,7 +79,7 @@ fun AppearanceScreen(onBack: () -> Unit) { containerColor = MaterialTheme.colorScheme.background, topBar = { SettingsDetailTopBar( - title = { Text(stringResource(Res.string.settings_category_appearance)) }, + title = stringResource(Res.string.settings_category_appearance), onBack = onBack, scrollBehavior = scrollBehavior, ) @@ -155,6 +164,52 @@ fun AppearanceScreen(onBack: () -> Unit) { } ) } + + Category( + Modifier.padding(top = 8.dp), + containerColor = MaterialTheme.colorScheme.surfaceContainerLow + ) { + ListItem( + headline = stringResource(Res.string.appearance_nav_bar_style), + supportingText = stringResource(Res.string.appearance_nav_bar_style_d), + leadingContent = { Icon(Icons.Filled.Brush, null) }, + divider = true, + bottomContent = { + FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + NavBarStyle.entries.forEach { style -> + FilterChip( + onClick = { + Settings.navBarStyle = style + navBarStyle = style + }, + selected = navBarStyle == style, + label = { + Text( + text = if (style == NavBarStyle.Traditional) { + stringResource(Res.string.appearance_nav_bar_traditional) + } else { + stringResource(Res.string.appearance_nav_bar_floating) + }, + overflow = TextOverflow.Ellipsis + ) + } + ) + } + } + } + ) + SwitchListItem( + headline = stringResource(Res.string.appearance_nav_bar_show_titles), + supportingText = stringResource(Res.string.appearance_nav_bar_show_titles_d), + enabled = navBarStyle == NavBarStyle.Floating, + checked = navBarShowTitle, + onCheckedChange = { + Settings.navBarShowTitle = it + navBarShowTitle = it + }, + divider = false + ) + } } } } diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.kt index 123eb96..fce27ed 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.kt @@ -145,14 +145,21 @@ internal fun deviceSessionIcon(d: DeviceSessionInfo): ImageVector { } } -internal fun deviceSessionLogoResource(d: DeviceSessionInfo): DrawableResource? = - when (resolveDeviceOsName(d)?.lowercase()) { +internal fun deviceSessionLogoResource(d: DeviceSessionInfo): DrawableResource? { + // Android (Compose MP AndroidRenderer) cannot rasterise SVG files and throws + // "Android platform doesn't support SVG format." when a .svg drawable is used + // via painterResource. On Android fall back to the vector [deviceSessionIcon]. + if (!svgDrawablesSupported()) return null + return when (resolveDeviceOsName(d)?.lowercase()) { "windows" -> Res.drawable.os_windows "macos" -> Res.drawable.os_macos "linux" -> Res.drawable.os_linux else -> null } +} +/** True when the Compose renderer can load .svg drawables (JVM / iOS). */ +expect fun svgDrawablesSupported(): Boolean internal fun resolveDeviceOsName(d: DeviceSessionInfo): String? { val direct = normalizeDeviceOsName(d.osName) if (direct != null) return direct diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/NotificationsScreen.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/NotificationsScreen.kt index 2f0d148..e9210c8 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/NotificationsScreen.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/NotificationsScreen.kt @@ -44,7 +44,6 @@ import ru.fromchat.settings_push_notifications_unavailable import ru.fromchat.settings_desktop_notifications import ru.fromchat.settings_desktop_notifications_d import ru.fromchat.ui.components.FromChatSnackbarHost -import ru.fromchat.ui.components.Text @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -68,7 +67,7 @@ fun NotificationsScreen(onBack: () -> Unit) { snackbarHost = { FromChatSnackbarHost(hostState = snackbarHostState) }, topBar = { SettingsDetailTopBar( - title = { Text(stringResource(Res.string.settings_notifications_title)) }, + title = stringResource(Res.string.settings_notifications_title), onBack = onBack, scrollBehavior = scrollBehavior, ) diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsDetailTopBar.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsDetailTopBar.kt index ab3c5e7..e244789 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsDetailTopBar.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsDetailTopBar.kt @@ -33,6 +33,7 @@ import kotlinx.coroutines.launch import org.jetbrains.compose.resources.stringResource import ru.fromchat.Res import ru.fromchat.back +import ru.fromchat.ui.components.AnimatedWordTitle import ru.fromchat.ui.extraStatusBars import ru.fromchat.ui.main.detailPaneShowBackButton @@ -72,7 +73,7 @@ fun rememberSettingsCollapsingScrollBehavior(): TopAppBarScrollBehavior { @OptIn(ExperimentalMaterial3Api::class) @Composable fun SettingsDetailTopBar( - title: @Composable () -> Unit, + title: String, onBack: () -> Unit, scrollBehavior: TopAppBarScrollBehavior? = null, ) { @@ -86,14 +87,11 @@ fun SettingsDetailTopBar( } } } - // Match Profile / shell (`background`), not AppPanel's default - // `surfaceContainerLowest` — that token reads as a separate pane fill in - // two-pane against the list–detail shell. val paneColor = MaterialTheme.colorScheme.background val topBarWindowInsets = settingsDetailWindowInsets() if (settingsDetailUseCollapsingTopBar()) { MediumTopAppBar( - title = title, + title = { AnimatedWordTitle(text = title) }, navigationIcon = navigationIcon, scrollBehavior = scrollBehavior, windowInsets = topBarWindowInsets, @@ -105,7 +103,7 @@ fun SettingsDetailTopBar( } else { // Desktop / expanded: pinned TopAppBar (not Large/Medium). TopAppBar( - title = title, + title = { AnimatedWordTitle(text = title) }, navigationIcon = navigationIcon, windowInsets = topBarWindowInsets, colors = TopAppBarDefaults.topAppBarColors( diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsTab.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsTab.kt index ba6ccf3..fbb40dc 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsTab.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/SettingsTab.kt @@ -8,16 +8,15 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.AccountCircle -import androidx.compose.material.icons.filled.Devices -import androidx.compose.material.icons.filled.Info -import androidx.compose.material.icons.filled.Notifications -import androidx.compose.material.icons.filled.Palette -import androidx.compose.material.icons.filled.Person -import androidx.compose.material.icons.filled.Storage -import androidx.compose.material.icons.outlined.BugReport +import androidx.compose.material.icons.rounded.AccountCircle +import androidx.compose.material.icons.rounded.Devices +import androidx.compose.material.icons.rounded.Info +import androidx.compose.material.icons.rounded.Notifications +import androidx.compose.material.icons.rounded.Palette +import androidx.compose.material.icons.rounded.Person +import androidx.compose.material.icons.rounded.Storage +import androidx.compose.material.icons.rounded.BugReport import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.TopAppBar @@ -28,7 +27,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.pr0gramm3r101.components.Category -import com.pr0gramm3r101.components.ListItem import com.pr0gramm3r101.utils.WindowWidthSizeClass import com.pr0gramm3r101.utils.currentWindowAdaptiveInfo import com.pr0gramm3r101.utils.verticalScroll @@ -55,6 +53,8 @@ import ru.fromchat.settings_hub_logs_sub import ru.fromchat.settings_hub_profile_sub import ru.fromchat.ui.LocalNavController import ru.fromchat.ui.components.Text +import ru.fromchat.ui.components.ExpressiveListItem +import ru.fromchat.ui.components.ExpressiveTints import ru.fromchat.ui.extraStatusBars import ru.fromchat.ui.main.LocalConversationListDetailActive import ru.fromchat.ui.main.LocalDesktopSettingsNavController @@ -111,72 +111,82 @@ fun SettingsTab() { if (isTwoPane) { Category(Modifier.padding(top = 16.dp)) { - ListItem( + ExpressiveListItem( + icon = Icons.Rounded.Person, + iconPreset = ExpressiveTints.Blue, headline = stringResource(Res.string.profile), supportingText = stringResource(Res.string.settings_hub_profile_sub), onClick = { - val userId = ApiClient.user?.id?.takeIf { it > 0 } ?: return@ListItem + val userId = ApiClient.user?.id?.takeIf { it > 0 } ?: return@ExpressiveListItem openDetail("profile/$userId") }, - leadingContent = { Icon(Icons.Filled.Person, null) }, ) } } Category(Modifier.padding(top = 16.dp)) { - ListItem( + ExpressiveListItem( + icon = Icons.Rounded.AccountCircle, + iconPreset = ExpressiveTints.Green, headline = stringResource(Res.string.settings_category_account), supportingText = stringResource(Res.string.settings_category_account_d), onClick = { openDetail(SettingsRoutes.Account) }, - leadingContent = { Icon(Icons.Filled.AccountCircle, null) }, divider = true ) - ListItem( + ExpressiveListItem( + icon = Icons.Rounded.Devices, + iconPreset = ExpressiveTints.Rose, headline = stringResource(Res.string.settings_category_devices), supportingText = stringResource(Res.string.settings_category_devices_d), onClick = { openDetail(SettingsRoutes.Devices) }, - leadingContent = { Icon(Icons.Filled.Devices, null) }, - divider = true ) + } - ListItem( + Category(Modifier.padding(top = 8.dp)) { + ExpressiveListItem( + icon = Icons.Rounded.Palette, + iconPreset = ExpressiveTints.Yellow, headline = stringResource(Res.string.settings_category_appearance), supportingText = stringResource(Res.string.settings_category_appearance_d), onClick = { openDetail(SettingsRoutes.Appearance) }, - leadingContent = { Icon(Icons.Filled.Palette, null) }, divider = true ) - ListItem( + ExpressiveListItem( + icon = Icons.Rounded.Notifications, + iconPreset = ExpressiveTints.Orange, headline = stringResource(Res.string.settings_category_notifications), supportingText = stringResource(Res.string.settings_category_notifications_d), onClick = { openDetail(SettingsRoutes.Notifications) }, - leadingContent = { Icon(Icons.Filled.Notifications, null) }, - divider = true ) + } - ListItem( + Category(Modifier.padding(top = 8.dp)) { + ExpressiveListItem( + icon = Icons.Rounded.Storage, + iconPreset = ExpressiveTints.Cyan, headline = stringResource(Res.string.change_server), supportingText = stringResource(Res.string.change_server_d), onClick = { openDetail(SettingsRoutes.ServerConfig) }, - leadingContent = { Icon(Icons.Filled.Storage, null) }, divider = true ) - ListItem( + ExpressiveListItem( + icon = Icons.Rounded.Info, + iconPreset = ExpressiveTints.Purple, headline = stringResource(Res.string.about), supportingText = stringResource(Res.string.settings_hub_about_sub), onClick = { openDetail(SettingsRoutes.About) }, - leadingContent = { Icon(Icons.Filled.Info, null) }, divider = true ) - ListItem( + ExpressiveListItem( + icon = Icons.Rounded.BugReport, + iconPreset = ExpressiveTints.Rose, headline = stringResource(Res.string.logs_title), supportingText = stringResource(Res.string.settings_hub_logs_sub), onClick = { openDetail(SettingsRoutes.Logs) }, - leadingContent = { Icon(Icons.Outlined.BugReport, null) } ) } } diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/account/AccountScreen.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/account/AccountScreen.kt index 765d0c8..f65794c 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/account/AccountScreen.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/settings/account/AccountScreen.kt @@ -79,7 +79,7 @@ fun AccountScreen( containerColor = MaterialTheme.colorScheme.background, topBar = { SettingsDetailTopBar( - title = { Text(stringResource(Res.string.settings_account_title)) }, + title = stringResource(Res.string.settings_account_title), onBack = onBack, scrollBehavior = scrollBehavior, ) diff --git a/app/shared/src/commonMain/kotlin/ru/fromchat/utils/haptic/HapticFeedbackEvent.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/utils/haptic/HapticFeedbackEvent.kt index d784459..19f90d2 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/utils/haptic/HapticFeedbackEvent.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/utils/haptic/HapticFeedbackEvent.kt @@ -6,4 +6,8 @@ enum class HapticFeedbackEvent { MessageSent, ContextMenuOpened, SelectionModeEntered, + /** Light tick on touch-down of a switch — fires before the state flips. */ + SwitchPress, + /** Heavier click at the commit moment — fires exactly when the state flips. */ + SwitchToggle, } \ No newline at end of file diff --git a/app/shared/src/iosMain/kotlin/ru/fromchat/ui/components/BackHandler.ios.kt b/app/shared/src/iosMain/kotlin/ru/fromchat/ui/components/BackHandler.ios.kt index 28a5244..8973ac8 100644 --- a/app/shared/src/iosMain/kotlin/ru/fromchat/ui/components/BackHandler.ios.kt +++ b/app/shared/src/iosMain/kotlin/ru/fromchat/ui/components/BackHandler.ios.kt @@ -21,6 +21,8 @@ actual fun rememberHapticFeedbackInternal(): (Int) -> Unit = HapticFeedbackEvent.MessageSent.ordinal -> UIImpactFeedbackStyle.UIImpactFeedbackStyleMedium HapticFeedbackEvent.ContextMenuOpened.ordinal -> UIImpactFeedbackStyle.UIImpactFeedbackStyleHeavy HapticFeedbackEvent.SelectionModeEntered.ordinal -> UIImpactFeedbackStyle.UIImpactFeedbackStyleMedium + HapticFeedbackEvent.SwitchPress.ordinal -> UIImpactFeedbackStyle.UIImpactFeedbackStyleLight + HapticFeedbackEvent.SwitchToggle.ordinal -> UIImpactFeedbackStyle.UIImpactFeedbackStyleHeavy else -> UIImpactFeedbackStyle.UIImpactFeedbackStyleLight } UIImpactFeedbackGenerator(style).impactOccurred() diff --git a/app/shared/src/iosMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.ios.kt b/app/shared/src/iosMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.ios.kt new file mode 100644 index 0000000..8f67e83 --- /dev/null +++ b/app/shared/src/iosMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.ios.kt @@ -0,0 +1,3 @@ +package ru.fromchat.ui.main.settings + +actual fun svgDrawablesSupported(): Boolean = true diff --git a/app/shared/src/jvmMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.jvm.kt b/app/shared/src/jvmMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.jvm.kt new file mode 100644 index 0000000..8f67e83 --- /dev/null +++ b/app/shared/src/jvmMain/kotlin/ru/fromchat/ui/main/settings/DeviceSessionDisplay.jvm.kt @@ -0,0 +1,3 @@ +package ru.fromchat.ui.main.settings + +actual fun svgDrawablesSupported(): Boolean = true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f9b1a71..b294b3b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,19 @@ [versions] -agp = "9.4.0" +agp = "9.4.1" androidx-activityCompose = "1.13.0" androidx-appcompat = "1.8.0" -androidx-core-ktx = "1.19.0" +androidx-core-ktx = "1.19.1" androidx-exifinterface = "1.4.2" -coilCompose = "3.6.2" -compose-multiplatform = "1.12.0" +coilCompose = "3.6.3" +compose-multiplatform = "1.12.1" #noinspection NewerVersionAvailable constraintlayout = "0.8.0-shaded" coreSplashscreen = "1.2.0" -firebaseMessaging = "25.1.3" +firebaseMessaging = "26.0.0" googleServices = "4.5.0" -haze = "2.0.0-beta03" +haze = "2.0.1" jnaPlatform = "5.19.1" -kotlin = "2.4.20" +kotlin = "2.4.21" adaptiveAndroid = "1.3.0" biometric = "1.4.0-alpha07" gson = "2.14.0" @@ -22,33 +22,33 @@ kotlinxCoroutinesCore = "1.11.0" kotlinxIoCore = "0.9.1" multiplatformCryptoLibsodiumBindings = "0.9.5" multiplatformSettings = "1.3.0" -serialization = "2.4.20" +serialization = "2.4.21" serialization-json = "1.11.0" material = "1.14.0" activityKtx = "1.13.0" navigationCompose = "2.9.2" datastore = "1.2.1" security-crypto = "1.1.0" -ktor = "3.5.2" +ktor = "3.6.0" slf4j = "1.7.36" kotlinxDatetime = "0.8.0" lifecycleRuntimeKtx = "2.11.0" composeBom = "2026.09.00" composeMaterialIconsExtended = "1.7.3" composeMaterial3 = "1.12.0-alpha03" -composeComponents = "1.12.0" -playServicesBase = "18.10.1" -tweetnaclJava = "1.1.3" -androidxWork = "2.11.2" +composeComponents = "1.12.1" +playServicesBase = "18.11.0" +tweetnaclJava = "1.1.4" +androidxWork = "2.12.0" cryptography-kotlin = "0.6.0" krypto = "4.0.10" -sqldelight = "2.3.2" -livekitAndroid = "2.28.2" +sqldelight = "2.4.1" +livekitAndroid = "2.29.0" livekitAndroidComposeComponents = "2.4.2" markdownRendererM3 = "0.45.0" -bouncycastle = "1.85.2" -webkit = "1.17.0" -openjfx = "22.0.2" +bouncycastle = "1.86" +webkit = "1.17.1" +openjfx = "27" [libraries] androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "coreSplashscreen" } diff --git a/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/Components.kt b/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/Components.kt index fd38a44..9d3b107 100644 --- a/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/Components.kt +++ b/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/Components.kt @@ -14,7 +14,9 @@ import androidx.compose.foundation.LocalIndication import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.detectTapGestures +import androidx.compose.foundation.interaction.Interaction import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope @@ -837,8 +839,29 @@ inline fun SwitchListItem( groupItemCount: Int? = null, noinline onContextMenuOpen: (() -> Unit)? = null, noinline contextMenu: (ListItemContextMenuScope.() -> Unit)? = null, + /** + * Premium two-stage haptic: a light tick on touch-down (before state flips) and a + * heavier click at the commit moment (exactly when state flips). Defaults ON so + * every switch in the app gets the feel automatically; pass `false` to silence. + * + * No-op on platforms that don't support haptics. + */ + hapticFeedback: Boolean = true, ) { val interactionSource = remember { MutableInteractionSource() } + val (pressHaptic, commitHaptic) = if (enabled && hapticFeedback) { + switchHapticCallbacks() + } else { + val noop: () -> Unit = { } + noop to noop + } + LaunchedEffect(interactionSource) { + interactionSource.interactions.collect { interaction -> + if (interaction is PressInteraction.Press) { + pressHaptic() + } + } + } ListItem( modifier = if (enabled) Modifier.clickable( interactionSource = interactionSource, @@ -852,7 +875,12 @@ inline fun SwitchListItem( val (sw) = createRefs() Switch( checked = checked, - onCheckedChange = onCheckedChange, + // Fire the heavier click exactly at the commit moment (when state + // actually flips) so the haptic aligns with the visual switch. + onCheckedChange = { newState -> + commitHaptic() + onCheckedChange(newState) + }, interactionSource = interactionSource, enabled = enabled, modifier = Modifier.constrainAs(sw) { diff --git a/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/SwitchHaptics.kt b/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/SwitchHaptics.kt new file mode 100644 index 0000000..a478bcd --- /dev/null +++ b/utils/shared/src/commonMain/kotlin/com/pr0gramm3r101/components/SwitchHaptics.kt @@ -0,0 +1,35 @@ +package com.pr0gramm3r101.components + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.compositionLocalOf + +/** + * CompositionLocal that carries the haptic-firing lambda for `SwitchListItem`. + * Defaults to a no-op so it works on any platform / without a provider. + * + * The app root (in `:app:shared`) calls `provideSwitchHaptics()`, which stores the + * `rememberHapticFeedback()` callback here. + * + * @see SwitchListItem + */ +val LocalSwitchHaptic = compositionLocalOf<(Int) -> Unit> { { _ -> } } + +// Ordinals mirror `ru.fromchat.utils.haptic.HapticFeedbackEvent` (see enum). +internal const val HAPTIC_OR_SWITCH_PRESS: Int = 5 +internal const val HAPTIC_OR_SWITCH_TOGGLE: Int = 6 + +/** + * Internal accessor used by the inline [SwitchListItem]. + * + * Returns: + * - first element → press haptic (light tick at touch-down) + * - second element → commit haptic (heavier click at state flip) + * + * We pass a plain `Int` so `:utils:shared` has no compile-time dependency on the + * `ru.fromchat.utils.haptic.HapticFeedbackEvent` enum (which lives in `:app:shared`). + */ +@Composable +fun switchHapticCallbacks(): Pair<() -> Unit, () -> Unit> { + val fire = LocalSwitchHaptic.current + return ({ fire(HAPTIC_OR_SWITCH_PRESS) }) to ({ fire(HAPTIC_OR_SWITCH_TOGGLE) }) +}