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/commonMain/kotlin/ru/fromchat/config/Settings.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/config/Settings.kt index 9724020..6848c22 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.Traditional.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..de57df3 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/App.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/App.kt @@ -9,6 +9,8 @@ import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut +import androidx.compose.animation.slideInHorizontally +import androidx.compose.animation.slideOutHorizontally import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.SnackbarDuration @@ -98,6 +100,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,23 +145,53 @@ private fun standaloneProfileUserId(entry: NavBackStackEntry?): Int? { return entry.savedStateHandle.get("userId")?.toIntOrNull()?.takeIf { it > 0 } } -private val rootNavTween = tween(durationMillis = 250, easing = FastOutSlowInEasing) - +/** + * Root NavHost transitions — emphasized-spring scale+fade for the primary + * flow (welcome ↔ auth ↔ chat). List→detail routes (DMs, profiles, settings + * detail) get their own shared-axis transitions on each composable (see + * [conversationDetailDestinations] and friends). + */ private fun rootNavEnterTransition(): EnterTransition = - scaleIn(initialScale = 0.9f, animationSpec = rootNavTween) + - fadeIn(animationSpec = rootNavTween) + scaleIn(initialScale = 0.92f, animationSpec = EmphasizedSpring) + + fadeIn(animationSpec = EmphasizedSpring) private fun rootNavExitTransition(): ExitTransition = - scaleOut(targetScale = 1.1f, animationSpec = rootNavTween) + - fadeOut(animationSpec = rootNavTween) + scaleOut(targetScale = 1.06f, animationSpec = EmphasizedSpring) + + fadeOut(animationSpec = EmphasizedSpring) private fun rootNavPopEnterTransition(): EnterTransition = - scaleIn(initialScale = 1.1f, animationSpec = rootNavTween) + - fadeIn(animationSpec = rootNavTween) + scaleIn(initialScale = 1.06f, animationSpec = EmphasizedSpring) + + fadeIn(animationSpec = EmphasizedSpring) private fun rootNavPopExitTransition(): ExitTransition = - scaleOut(targetScale = 0.9f, animationSpec = rootNavTween) + - fadeOut(animationSpec = rootNavTween) + scaleOut(targetScale = 0.92f, animationSpec = EmphasizedSpring) + + fadeOut(animationSpec = EmphasizedSpring) + +/** + * Shared-axis transition pair for list→detail screens. The target slides in + * from the right (a quarter of the screen) while scaling up from 0.92 and + * fading in; the source scales down and slides slightly left. Classic + * "expanding panel" feel from Material 3 Expressive. + */ +fun sharedAxisDetailEnter(): EnterTransition = + slideInHorizontally(animationSpec = SharedAxisSpring, initialOffsetX = { it / 4 }) + + scaleIn(initialScale = 0.92f, animationSpec = StandardSpring) + + fadeIn(animationSpec = StandardSpring) + +fun sharedAxisDetailExit(): ExitTransition = + slideOutHorizontally(animationSpec = SharedAxisSpring, targetOffsetX = { -it / 6 }) + + scaleOut(targetScale = 0.95f, animationSpec = StandardSpring) + + fadeOut(animationSpec = StandardSpring) + +fun sharedAxisDetailPopEnter(): EnterTransition = + slideInHorizontally(animationSpec = SharedAxisSpring, initialOffsetX = { -it / 6 }) + + scaleIn(initialScale = 0.95f, animationSpec = StandardSpring) + + fadeIn(animationSpec = StandardSpring) + +fun sharedAxisDetailPopExit(): ExitTransition = + slideOutHorizontally(animationSpec = SharedAxisSpring, targetOffsetX = { it / 4 }) + + scaleOut(targetScale = 1.04f, animationSpec = StandardSpring) + + fadeOut(animationSpec = StandardSpring) private val searchScreenFade = tween(durationMillis = 260) @@ -356,6 +389,7 @@ fun App( } FromChatTheme { + provideSwitchHaptics { SharedTransitionLayout { val navController = rememberNavController() val chatsDetailNavController = rememberNavController() @@ -778,6 +812,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 index b441021..42a4525 100644 --- a/app/shared/src/commonMain/kotlin/ru/fromchat/ui/MotionTokens.kt +++ b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/MotionTokens.kt @@ -4,6 +4,7 @@ import androidx.compose.animation.core.Spring import androidx.compose.animation.core.spring import androidx.compose.foundation.shape.CircleShape import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.unit.IntOffset /** * Central spring / motion tokens shared by the expressive components and @@ -32,5 +33,11 @@ val TitleSpring = spring( stiffness = 240f, ) +/** Shared-axis slide spring (IntOffset) — nav transitions slide, panel morphs. */ +val SharedAxisSpring = spring( + dampingRatio = Spring.DampingRatioMediumBouncy, + stiffness = Spring.StiffnessMediumLow, +) + /** Full / CTA shape (nav pill, primary buttons) — fully rounded. */ val FullCtaShape: Shape = CircleShape 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/main/MainDetailDestinations.kt b/app/shared/src/commonMain/kotlin/ru/fromchat/ui/main/MainDetailDestinations.kt index 562258a..5be4c1d 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 @@ -8,6 +8,10 @@ import androidx.navigation.NavType import androidx.navigation.compose.composable import androidx.navigation.navArgument import ru.fromchat.Logger +import ru.fromchat.ui.sharedAxisDetailEnter +import ru.fromchat.ui.sharedAxisDetailExit +import ru.fromchat.ui.sharedAxisDetailPopEnter +import ru.fromchat.ui.sharedAxisDetailPopExit import ru.fromchat.legal.DocumentScreen import ru.fromchat.legal.DocumentType import ru.fromchat.ui.chat.panels.dm.DmChatRoute @@ -46,7 +50,13 @@ fun NavGraphBuilder.conversationDetailDestinations( sharedTransitionScope: SharedTransitionScope, scrollToMessageId: Int?, ) { - composable(PublicChatNav.CHAT_ROUTE) { + composable( + route = PublicChatNav.CHAT_ROUTE, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { PublicChatChatRoute( scrollToMessageId = scrollToMessageId, navController = navController, @@ -55,7 +65,13 @@ fun NavGraphBuilder.conversationDetailDestinations( ) } - composable(PublicChatNav.PROFILE_ROUTE) { + composable( + route = PublicChatNav.PROFILE_ROUTE, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { PublicChatProfileRoute( navController = navController, sharedTransitionScope = sharedTransitionScope, @@ -65,6 +81,10 @@ fun NavGraphBuilder.conversationDetailDestinations( composable( route = DmNav.CHAT_ROUTE, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, arguments = listOf( navArgument("otherUserId") { type = NavType.StringType }, navArgument("sourceMessageId") { type = NavType.StringType; defaultValue = "0" }, @@ -84,6 +104,10 @@ fun NavGraphBuilder.conversationDetailDestinations( composable( route = DmNav.PROFILE_ROUTE, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, arguments = listOf(navArgument("otherUserId") { type = NavType.StringType }), ) { entry -> val otherUserId = entry.pathInt("otherUserId") @@ -109,6 +133,10 @@ fun NavGraphBuilder.profileDetailDestinations( ) { composable( route = "profile/{userId}?fromDeepLink={fromDeepLink}", + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, arguments = listOf( navArgument("userId") { type = NavType.StringType }, navArgument("fromDeepLink") { @@ -154,6 +182,10 @@ fun NavGraphBuilder.profileDetailDestinations( composable( route = ProfileRoutes.Edit, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, arguments = listOf( navArgument(ProfileRoutes.ARG_FOCUS) { type = NavType.StringType @@ -180,15 +212,33 @@ fun NavGraphBuilder.settingsDetailDestinations( navController: NavController, rootNavController: NavController = navController, ) { - composable("about") { + composable( + "about", + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { AboutScreen() } - composable(SettingsRoutes.Logs) { + composable( + SettingsRoutes.Logs, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { LogsScreen() } - composable(SettingsRoutes.LogFiles) { + composable( + SettingsRoutes.LogFiles, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { LogFilesScreen( onOpenFile = { file -> navController.previousBackStackEntry @@ -201,6 +251,10 @@ fun NavGraphBuilder.settingsDetailDestinations( composable( route = DocumentType.ROUTE, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, arguments = listOf( navArgument(DocumentType.ARG_DOCUMENT_TYPE) { type = NavType.StringType }, ), @@ -220,26 +274,56 @@ fun NavGraphBuilder.settingsDetailDestinations( ) } - composable(SettingsRoutes.Appearance) { + composable( + SettingsRoutes.Appearance, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { AppearanceScreen(onBack = { navController.navigateUp() }) } - composable(SettingsRoutes.Notifications) { + composable( + SettingsRoutes.Notifications, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { NotificationsScreen(onBack = { navController.navigateUp() }) } - composable(SettingsRoutes.Devices) { + composable( + SettingsRoutes.Devices, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { DevicesScreen(onBack = { navController.navigateUp() }) } - composable(SettingsRoutes.SecurityPasswordFlow) { + composable( + SettingsRoutes.SecurityPasswordFlow, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { ChangePasswordScreen( onBack = { navController.navigateUp() }, onDone = { navController.popBackStack() }, ) } - composable(SettingsRoutes.AccountDeleteFlow) { + composable( + SettingsRoutes.AccountDeleteFlow, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { DeleteAccountScreen( onBack = { navController.navigateUp() }, onDeleted = { @@ -250,19 +334,37 @@ fun NavGraphBuilder.settingsDetailDestinations( ) } - composable(SettingsRoutes.AccountYandexFlow) { + composable( + SettingsRoutes.AccountYandexFlow, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { ChangeYandexConfirmScreen( onBack = { navController.navigateUp() }, ) } - composable(SettingsRoutes.AccountYandexOAuth) { + composable( + SettingsRoutes.AccountYandexOAuth, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { ChangeYandexOAuthScreen( onBack = { navController.navigateUp() }, ) } - composable(SettingsRoutes.AccountYandexDone) { + composable( + SettingsRoutes.AccountYandexDone, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { ChangeYandexDoneScreen( onDone = { navController.popBackStack(SettingsRoutes.Account, inclusive = false) @@ -270,7 +372,13 @@ fun NavGraphBuilder.settingsDetailDestinations( ) } - composable(SettingsRoutes.Account) { + composable( + SettingsRoutes.Account, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { AccountScreen( onBack = { navController.navigateUp() }, onLogout = { @@ -285,7 +393,13 @@ fun NavGraphBuilder.settingsDetailDestinations( } // Same route string as pre-auth server config on the root graph; fine on a nested graph. - composable(SettingsRoutes.ServerConfig) { + composable( + SettingsRoutes.ServerConfig, + enterTransition = { sharedAxisDetailEnter() }, + exitTransition = { sharedAxisDetailExit() }, + popEnterTransition = { sharedAxisDetailPopEnter() }, + popExitTransition = { sharedAxisDetailPopExit() }, + ) { ServerConfigScreen() } } 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..79bdbdd 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,6 +64,7 @@ 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 @@ -74,6 +75,8 @@ 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 +85,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 +267,7 @@ fun MainScreen( val contactsLabel = stringResource(Res.string.contacts) val settingsLabel = stringResource(Res.string.settings) val profileLabel = stringResource(Res.string.profile) + val navBarStyle = AppSettings.navBarStyle BoxWithConstraints( Modifier.fillMaxSize(), @@ -342,9 +347,51 @@ fun MainScreen( bottomChromeHeightDp = measured } } - .background(MaterialTheme.colorScheme.surfaceContainer) - .hazeBlur(input = HazeInput.Backdrop(navBarHazeState), style = navBarHazeStyle), + .then( + if (navBarStyle == NavBarStyle.Floating) { + Modifier.padding(horizontal = 16.dp, vertical = 8.dp) + } else { + Modifier + .background(MaterialTheme.colorScheme.surfaceContainer) + .hazeBlur(input = HazeInput.Backdrop(navBarHazeState), style = navBarHazeStyle) + }, + ), ) { + if (navBarStyle == NavBarStyle.Floating) { + FloatingNavBar( + 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(), + 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 +469,7 @@ fun MainScreen( }, ) } + } } } 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..d2616e5 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 @@ -17,7 +17,6 @@ import androidx.compose.material.icons.filled.Person import androidx.compose.material.icons.filled.Storage import androidx.compose.material.icons.outlined.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,88 @@ fun SettingsTab() { if (isTwoPane) { Category(Modifier.padding(top = 16.dp)) { - ListItem( + ExpressiveListItem( + icon = Icons.Filled.Person, + iconTint = ExpressiveTints.LightBlue, + iconSubTint = 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.Filled.AccountCircle, + iconTint = ExpressiveTints.LightGreen, + iconSubTint = 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.Filled.Devices, + iconTint = ExpressiveTints.LightBlue, + iconSubTint = ExpressiveTints.Blue, 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( + ExpressiveListItem( + icon = Icons.Filled.Palette, + iconTint = ExpressiveTints.LightPurple, + iconSubTint = ExpressiveTints.Purple, 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.Filled.Notifications, + iconTint = ExpressiveTints.LightYellow, + iconSubTint = ExpressiveTints.Yellow, 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( + ExpressiveListItem( + icon = Icons.Filled.Storage, + iconTint = ExpressiveTints.LightRed, + iconSubTint = ExpressiveTints.Red, 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.Filled.Info, + iconTint = ExpressiveTints.LightGreen, + iconSubTint = ExpressiveTints.Green, 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.Outlined.BugReport, + iconTint = ExpressiveTints.LightBlue, + iconSubTint = ExpressiveTints.Blue, 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/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/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) }) +}