diff --git a/.github/nightly-notes/2026-11-16-feat-floating-nav-bubble.md b/.github/nightly-notes/2026-11-16-feat-floating-nav-bubble.md new file mode 100644 index 0000000000..0149d50fee --- /dev/null +++ b/.github/nightly-notes/2026-11-16-feat-floating-nav-bubble.md @@ -0,0 +1,2 @@ +## New +- While the floating navigation bar is shrunk, the mini player can sit beside it in the same row (Settings, Navigation bar, Mini player beside the bubble) diff --git a/.github/nightly-notes/2026-11-16-feat-floating-nav-glide.md b/.github/nightly-notes/2026-11-16-feat-floating-nav-glide.md new file mode 100644 index 0000000000..9c232e2096 --- /dev/null +++ b/.github/nightly-notes/2026-11-16-feat-floating-nav-glide.md @@ -0,0 +1,2 @@ +## Improved +- The floating navigation bar now slides one highlight between tabs, springs its width and names smoothly, and lets you drag along it to switch tabs diff --git a/.github/nightly-notes/2026-11-16-feat-floating-nav-shrink.md b/.github/nightly-notes/2026-11-16-feat-floating-nav-shrink.md new file mode 100644 index 0000000000..df6fc21f49 --- /dev/null +++ b/.github/nightly-notes/2026-11-16-feat-floating-nav-shrink.md @@ -0,0 +1,2 @@ +## New +- The floating navigation bar can shrink to the open tab while you scroll instead of hiding (Settings, Navigation bar, When you scroll) diff --git a/app/src/main/java/io/github/aedev/flow/data/local/PlayerPreferences.kt b/app/src/main/java/io/github/aedev/flow/data/local/PlayerPreferences.kt index 26ca65617f..1d32fb98eb 100644 --- a/app/src/main/java/io/github/aedev/flow/data/local/PlayerPreferences.kt +++ b/app/src/main/java/io/github/aedev/flow/data/local/PlayerPreferences.kt @@ -184,6 +184,10 @@ class PlayerPreferences( val BOTTOM_NAV_HIDE_ON_SCROLL = booleanPreferencesKey("bottom_nav_hide_on_scroll") val BOTTOM_NAV_LABELS = stringPreferencesKey("bottom_nav_labels") val BOTTOM_NAV_STYLE = stringPreferencesKey("bottom_nav_style") + val BOTTOM_NAV_SCRUB = booleanPreferencesKey("bottom_nav_scrub") + val BOTTOM_NAV_ICON_POP = booleanPreferencesKey("bottom_nav_icon_pop") + val BOTTOM_NAV_SCROLL = stringPreferencesKey("bottom_nav_scroll") + val BOTTOM_NAV_MINI_BESIDE = booleanPreferencesKey("bottom_nav_mini_beside") val SEARCH_SHOWS_NAV_BAR = booleanPreferencesKey("search_shows_nav_bar") val INNER_PAGES_SHOW_NAV_BAR = booleanPreferencesKey("inner_pages_show_nav_bar") val MUSIC_NAVIGATION_ENABLED = booleanPreferencesKey("music_navigation_enabled") @@ -1698,8 +1702,66 @@ class PlayerPreferences( } } + // Dragging along the floating bar moves between tabs. + val bottomNavScrub: Flow = + context.playerPreferencesDataStore.data + .map { preferences -> preferences[Keys.BOTTOM_NAV_SCRUB] ?: true } + .distinctUntilChanged() + + suspend fun setBottomNavScrub(enabled: Boolean) { + context.playerPreferencesDataStore.edit { preferences -> + preferences[Keys.BOTTOM_NAV_SCRUB] = enabled + } + } + + val bottomNavIconPop: Flow = + context.playerPreferencesDataStore.data + .map { preferences -> preferences[Keys.BOTTOM_NAV_ICON_POP] ?: false } + .distinctUntilChanged() + + suspend fun setBottomNavIconPop(enabled: Boolean) { + context.playerPreferencesDataStore.edit { preferences -> + preferences[Keys.BOTTOM_NAV_ICON_POP] = enabled + } + } + + val bottomNavScroll: Flow = + context.playerPreferencesDataStore.data + .map { preferences -> + preferences[Keys.BOTTOM_NAV_SCROLL] + ?.let { stored -> runCatching { NavBarScroll.valueOf(stored) }.getOrNull() } + ?: NavBarScroll.SHRINK + }.distinctUntilChanged() + + suspend fun setBottomNavScroll(scroll: NavBarScroll) { + context.playerPreferencesDataStore.edit { preferences -> + preferences[Keys.BOTTOM_NAV_SCROLL] = scroll.name + } + } + + // Beside the shrunk floating bar, the mini player drops into the bar's row. + val bottomNavMiniBeside: Flow = + context.playerPreferencesDataStore.data + .map { preferences -> preferences[Keys.BOTTOM_NAV_MINI_BESIDE] ?: false } + .distinctUntilChanged() + + suspend fun setBottomNavMiniBeside(enabled: Boolean) { + context.playerPreferencesDataStore.edit { preferences -> + preferences[Keys.BOTTOM_NAV_MINI_BESIDE] = enabled + } + } + val bottomNavLook: Flow = - combine(bottomNavStyle, bottomNavLabels) { style, labels -> NavBarLook(style, labels) }.distinctUntilChanged() + combine( + bottomNavStyle, + bottomNavLabels, + bottomNavScrub, + bottomNavIconPop, + bottomNavScroll, + ) { style, labels, scrub, iconPop, scroll -> + NavBarLook(style, labels, scrub, iconPop, scroll) + }.combine(bottomNavMiniBeside) { look, miniBeside -> look.copy(miniBeside = miniBeside) } + .distinctUntilChanged() // Search keeps its full-screen layout unless this is on. val searchShowsNavBar: Flow = @@ -5686,8 +5748,18 @@ enum class NavBarStyle { data class NavBarLook( val style: NavBarStyle = NavBarStyle.STANDARD, val labels: NavBarLabels = NavBarLabels.ALWAYS, + val scrub: Boolean = true, + val iconPop: Boolean = false, + val scroll: NavBarScroll = NavBarScroll.SHRINK, + val miniBeside: Boolean = false, ) +/** What scrolling does to the floating bar, when the bar reacts to scrolling at all. */ +enum class NavBarScroll { + HIDE, + SHRINK, +} + enum class SharedLinkAction { /** Play the video straight away, replacing what plays. */ PLAY, diff --git a/app/src/main/java/io/github/aedev/flow/ui/FlowApp.kt b/app/src/main/java/io/github/aedev/flow/ui/FlowApp.kt index 6d6c44e5b0..7d803cc633 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/FlowApp.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/FlowApp.kt @@ -2,7 +2,6 @@ package io.github.aedev.flow.ui import android.app.Activity import androidx.compose.animation.* -import androidx.compose.animation.core.Animatable import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.offset @@ -17,7 +16,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.IntOffset -import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -27,6 +25,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import io.github.aedev.flow.MainActivity import io.github.aedev.flow.data.local.NavBarLook +import io.github.aedev.flow.data.local.NavBarScroll +import io.github.aedev.flow.data.local.NavBarStyle import io.github.aedev.flow.data.local.PlayerPreferences import io.github.aedev.flow.data.profile.PendingSlice import io.github.aedev.flow.data.recommendation.FlowNeuroEngine @@ -38,7 +38,6 @@ import io.github.aedev.flow.player.SleepTimerManager import io.github.aedev.flow.sync2.service.LinkedCatchUp import io.github.aedev.flow.ui.components.donation.DonationPromptHost import io.github.aedev.flow.ui.components.equalizer.LocalEqualizerState -import io.github.aedev.flow.ui.components.layout.FlowBottomInsets import io.github.aedev.flow.ui.components.layout.LocalFlowBottomInsets import io.github.aedev.flow.ui.components.layout.LocalFlowSnackbarHostState import io.github.aedev.flow.ui.components.layout.navigation.FlowNavigationChrome @@ -58,10 +57,8 @@ import io.github.aedev.flow.ui.components.settings.SettingsDestination import io.github.aedev.flow.ui.components.settings.SettingsTarget import io.github.aedev.flow.ui.components.shared.FlowLoadingIndicator import io.github.aedev.flow.ui.components.shared.LocalMediaOpenOrigins -import io.github.aedev.flow.ui.components.shared.MediaMiniBarDefaults import io.github.aedev.flow.ui.components.shared.MediaOpenOrigins import io.github.aedev.flow.ui.components.shared.SubscriptionBellAlerts -import io.github.aedev.flow.ui.components.shared.mediaMiniBarBounds import io.github.aedev.flow.ui.components.videoplayer.PlayerSheetValue import io.github.aedev.flow.ui.components.videoplayer.rememberPlayerDraggableState import io.github.aedev.flow.ui.screens.equalizer.EqualizerViewModel @@ -78,8 +75,6 @@ import io.github.aedev.flow.ui.screens.update.UPDATE_ROUTE import io.github.aedev.flow.ui.screens.update.UpdateLaunchEffect import io.github.aedev.flow.ui.theme.ThemeMode import io.github.aedev.flow.ui.theme.ThemeVariant -import io.github.aedev.flow.ui.utils.LocalWindowSizeClass -import io.github.aedev.flow.ui.utils.isMediumWidth import kotlinx.coroutines.flow.first import kotlin.math.roundToInt @@ -366,59 +361,19 @@ fun FlowApp( !isInPipMode && remote.shows(activeMiniPlayer, activeVideo != null, musicPlayerSheetState.isDismissed, isShortsPlayerRoute) val isMiniBarObscuringContent = (isMusicSheetShown && !musicPlayerSheetState.isDismissed && !musicPlayerSheetState.isExpanded) || showVideoBar || showRemoteBar - val motionScheme = MaterialTheme.motionScheme - val barFraction = remember { Animatable(if (isBottomNavPresent) 1f else 0f) } - LaunchedEffect(isBottomNavPresent) { - // The same springs as the bar's own slide, so whatever rides on it stays glued to it. - barFraction.animateTo( - targetValue = if (isBottomNavPresent) 1f else 0f, - animationSpec = if (isBottomNavPresent) motionScheme.defaultSpatialSpec() else motionScheme.fastSpatialSpec(), + val (bottomInsets, miniPlayerBounds, miniPlayerDock) = + rememberFlowBottomChrome( + barPresent = isBottomNavPresent, + barShown = isBottomNavShown, + miniPlayerShown = isMiniBarObscuringContent, + systemBottomPx = navBarBottomInset, + barHeight = if (usesNavigationRail) 0.dp else navigationBarHeight, + containerWidthPx = constraints.maxWidth.toFloat(), + railWidth = if (usesNavigationRail && isNavigationRailVisible) navigationRailWidth else 0.dp, + navScrollState = navScrollState, + miniPlayerBesideShrunkBar = + bottomNavLook.style == NavBarStyle.FLOATING && bottomNavLook.scroll == NavBarScroll.SHRINK && bottomNavLook.miniBeside, ) - } - val systemBottomState = rememberUpdatedState(with(density) { navBarBottomInset.toDp() }) - val barHeightState = rememberUpdatedState(if (usesNavigationRail) 0.dp else navigationBarHeight) - val barShownState = rememberUpdatedState(isBottomNavShown) - val miniPlayerFraction = remember { Animatable(if (isMiniBarObscuringContent) 1f else 0f) } - LaunchedEffect(isMiniBarObscuringContent) { - miniPlayerFraction.animateTo( - targetValue = if (isMiniBarObscuringContent) 1f else 0f, - animationSpec = motionScheme.defaultSpatialSpec(), - ) - } - val miniPlayerShownState = rememberUpdatedState(isMiniBarObscuringContent) - val miniPlayerHeightState = rememberUpdatedState(MediaMiniBarDefaults.Height + MediaMiniBarDefaults.BottomSpacer) - val miniPlayerBounds = - with(density) { - mediaMiniBarBounds( - containerWidthPx = constraints.maxWidth.toFloat(), - startInsetPx = (if (usesNavigationRail && isNavigationRailVisible) navigationRailWidth else 0.dp).toPx(), - isCompactWidth = !LocalWindowSizeClass.current.isMediumWidth, - compactMarginPx = MediaMiniBarDefaults.CompactMargin.toPx(), - largeMarginPx = MediaMiniBarDefaults.LargeMargin.toPx(), - maxWidthPx = MediaMiniBarDefaults.MaxWidth.toPx(), - ) - } - val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl - val miniPlayerSpanState = - rememberUpdatedState( - miniPlayerBounds.let { bounds -> - val left = if (isRtl) constraints.maxWidth - bounds.start - bounds.width else bounds.start - left..(left + bounds.width) - }, - ) - val bottomInsets = - remember { - FlowBottomInsets( - systemInset = systemBottomState, - barHeight = barHeightState, - barShown = barShownState, - miniPlayerHeight = miniPlayerHeightState, - miniPlayerShown = miniPlayerShownState, - barFraction = { barFraction.value * (1f - navScrollState.hiddenFraction) }, - miniPlayerFraction = { miniPlayerFraction.value }, - miniPlayerSpanPx = miniPlayerSpanState, - ) - } FlowNavigationChrome( tabs = navigationTabs, selectedTab = selectedTab, @@ -557,6 +512,7 @@ fun FlowApp( isShortsPlayerRoute = isShortsPlayerRoute, bottomPadding = bottomPaddingTarget, startInset = if (usesNavigationRail && isNavigationRailVisible) navigationRailWidth else 0.dp, + miniDock = miniPlayerDock, miniPlayerScale = miniPlayerScale, miniPlayerShowSkipControls = miniPlayerShowSkipControls, miniPlayerShowNextPrevControls = miniPlayerShowNextPrevControls, diff --git a/app/src/main/java/io/github/aedev/flow/ui/FlowBottomChrome.kt b/app/src/main/java/io/github/aedev/flow/ui/FlowBottomChrome.kt new file mode 100644 index 0000000000..6d53f6170d --- /dev/null +++ b/app/src/main/java/io/github/aedev/flow/ui/FlowBottomChrome.kt @@ -0,0 +1,133 @@ +package io.github.aedev.flow.ui + +import androidx.compose.animation.core.Animatable +import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi +import androidx.compose.material3.FloatingToolbarDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.snapshotFlow +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalLayoutDirection +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.unit.dp +import io.github.aedev.flow.ui.components.layout.FlowBottomInsets +import io.github.aedev.flow.ui.components.layout.navigation.FlowNavigationDefaults +import io.github.aedev.flow.ui.components.layout.navigation.FlowNavigationScrollState +import io.github.aedev.flow.ui.components.shared.MediaMiniBarBounds +import io.github.aedev.flow.ui.components.shared.MediaMiniBarDefaults +import io.github.aedev.flow.ui.components.shared.mediaMiniBarBounds +import io.github.aedev.flow.ui.components.videoplayer.MiniPlayerDock +import io.github.aedev.flow.ui.utils.LocalWindowSizeClass +import io.github.aedev.flow.ui.utils.isMediumWidth +import kotlinx.coroutines.flow.collectLatest + +private val DockGap = 8.dp + +/** What the shell draws over the bottom of every page, and where the collapsed mini bars rest across it. */ +internal data class FlowBottomChrome( + val insets: FlowBottomInsets, + val miniBarBounds: MediaMiniBarBounds, + val miniPlayerDock: MiniPlayerDock?, +) + +/** + * The bottom chrome's insets, riding on the bar's and the mini player's own springs, and the mini bars' + * span across a window [containerWidthPx] wide whose content starts after [railWidth]. + */ +@OptIn(ExperimentalMaterial3ExpressiveApi::class) +@Composable +internal fun rememberFlowBottomChrome( + barPresent: Boolean, + barShown: Boolean, + miniPlayerShown: Boolean, + systemBottomPx: Int, + barHeight: Dp, + containerWidthPx: Float, + railWidth: Dp, + navScrollState: FlowNavigationScrollState, + miniPlayerBesideShrunkBar: Boolean, +): FlowBottomChrome { + val density = LocalDensity.current + val motionScheme = MaterialTheme.motionScheme + val barFraction = remember { Animatable(if (barPresent) 1f else 0f) } + LaunchedEffect(barPresent) { + // The same springs as the bar's own slide, so whatever rides on it stays glued to it. + barFraction.animateTo( + targetValue = if (barPresent) 1f else 0f, + animationSpec = if (barPresent) motionScheme.defaultSpatialSpec() else motionScheme.fastSpatialSpec(), + ) + } + val systemBottomState = rememberUpdatedState(with(density) { systemBottomPx.toDp() }) + val barHeightState = rememberUpdatedState(barHeight) + val barShownState = rememberUpdatedState(barShown) + val miniPlayerFraction = remember { Animatable(if (miniPlayerShown) 1f else 0f) } + LaunchedEffect(miniPlayerShown) { + miniPlayerFraction.animateTo( + targetValue = if (miniPlayerShown) 1f else 0f, + animationSpec = motionScheme.defaultSpatialSpec(), + ) + } + // Beside the shrunk bar, the mini player drops into the bar's row on the bar's own spring. + val dock = remember { Animatable(0f) } + LaunchedEffect(miniPlayerBesideShrunkBar, barPresent) { + snapshotFlow { miniPlayerBesideShrunkBar && barPresent && navScrollState.isCollapsed } + .collectLatest { docked -> dock.animateTo(if (docked) 1f else 0f, motionScheme.defaultSpatialSpec()) } + } + val miniPlayerShownState = rememberUpdatedState(miniPlayerShown) + val miniPlayerHeightState = rememberUpdatedState(MediaMiniBarDefaults.Height + MediaMiniBarDefaults.BottomSpacer) + val miniBarBounds = + with(density) { + mediaMiniBarBounds( + containerWidthPx = containerWidthPx, + startInsetPx = railWidth.toPx(), + isCompactWidth = !LocalWindowSizeClass.current.isMediumWidth, + compactMarginPx = MediaMiniBarDefaults.CompactMargin.toPx(), + largeMarginPx = MediaMiniBarDefaults.LargeMargin.toPx(), + maxWidthPx = MediaMiniBarDefaults.MaxWidth.toPx(), + ) + } + val toolbarPadding = FloatingToolbarDefaults.ContentPadding.calculateLeftPadding(LayoutDirection.Ltr) + val shrunkBarEndDp = MediaMiniBarDefaults.CompactMargin + toolbarPadding * 2 + FlowNavigationDefaults.FloatingItemSize + DockGap + val shrunkBarEnd = with(density) { shrunkBarEndDp.toPx() } + val docked = miniPlayerBesideShrunkBar && barPresent && navScrollState.isCollapsed + val miniPlayerDock = + if (docked) { + MiniPlayerDock( + restBottom = with(density) { systemBottomPx.toDp() } + FloatingToolbarDefaults.ScreenOffset, + sideClearance = shrunkBarEndDp, + ) + } else { + null + } + val dockShiftState = rememberUpdatedState((shrunkBarEnd - miniBarBounds.start).coerceAtLeast(0f)) + val dockedLiftState = rememberUpdatedState(FloatingToolbarDefaults.ScreenOffset - MediaMiniBarDefaults.BottomSpacer) + val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl + val miniPlayerSpanState = + rememberUpdatedState( + miniBarBounds.let { bounds -> + val left = if (isRtl) containerWidthPx - bounds.start - bounds.width else bounds.start + left..(left + bounds.width) + }, + ) + val insets = + remember { + FlowBottomInsets( + systemInset = systemBottomState, + barHeight = barHeightState, + barShown = barShownState, + miniPlayerHeight = miniPlayerHeightState, + miniPlayerShown = miniPlayerShownState, + barFraction = { barFraction.value * (1f - navScrollState.hiddenFraction) }, + miniPlayerFraction = { miniPlayerFraction.value }, + miniPlayerSpanPx = miniPlayerSpanState, + miniPlayerDock = { dock.value }, + miniPlayerDockShift = dockShiftState, + dockedLift = dockedLiftState, + ) + } + return FlowBottomChrome(insets, miniBarBounds, miniPlayerDock) +} diff --git a/app/src/main/java/io/github/aedev/flow/ui/FlowPlayerOverlays.kt b/app/src/main/java/io/github/aedev/flow/ui/FlowPlayerOverlays.kt index 229fbbd069..5c7991e0c9 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/FlowPlayerOverlays.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/FlowPlayerOverlays.kt @@ -47,6 +47,7 @@ import io.github.aedev.flow.ui.components.shared.MediaOpenOrigins import io.github.aedev.flow.ui.components.shared.quickactions.QuickActionsHost import io.github.aedev.flow.ui.components.shared.quickactions.sharedQuickActionsViewModel import io.github.aedev.flow.ui.components.videoplayer.BackgroundQueueTransport +import io.github.aedev.flow.ui.components.videoplayer.MiniPlayerDock import io.github.aedev.flow.ui.components.videoplayer.PlayerDraggableState import io.github.aedev.flow.ui.components.videoplayer.PlayerSheetValue import io.github.aedev.flow.ui.components.videoplayer.SheetOpenOrigin @@ -201,6 +202,7 @@ internal fun FlowPlayerOverlays( isShortsPlayerRoute: Boolean, bottomPadding: Dp, startInset: Dp, + miniDock: MiniPlayerDock?, miniPlayerScale: Float, miniPlayerShowSkipControls: Boolean, miniPlayerShowNextPrevControls: Boolean, @@ -258,6 +260,7 @@ internal fun FlowPlayerOverlays( playerSheetState = playerSheetState, bottomPadding = bottomPadding.coerceAtLeast(0.dp), startInset = startInset, + miniDock = miniDock, miniPlayerScale = miniPlayerScale, miniPlayerShowSkipControls = miniPlayerShowSkipControls, miniPlayerShowNextPrevControls = miniPlayerShowNextPrevControls, @@ -300,6 +303,7 @@ internal fun FlowPlayerOverlays( containerWidthPx = with(density) { containerWidth.toPx() }, containerHeightPx = with(density) { containerHeight.toPx() }, restingBottomPx = { bottomInsets.miniPlayerBaselinePx(density) }, + dockShiftPx = bottomInsets::miniPlayerDockShiftPx, onRestore = { videoWindowBounds -> openOrigins.holdOriginFor(barVideo.id, videoWindowBounds) barHandoffId = barVideo.id @@ -317,6 +321,7 @@ internal fun FlowPlayerOverlays( bounds = miniBarBounds, containerHeightPx = with(density) { containerHeight.toPx() }, restingBottomPx = { bottomInsets.miniPlayerBaselinePx(density) }, + dockShiftPx = bottomInsets::miniPlayerDockShiftPx, ) } if (showVideoBar && showBarQueue) { @@ -339,6 +344,7 @@ internal fun FlowPlayerOverlays( containerHeight = containerHeight, miniBounds = miniBarBounds, restingBottomPx = { bottomInsets.miniPlayerBaselinePx(density) }, + miniDockShiftPx = bottomInsets::miniPlayerDockShiftPx, track = track, swipeLeftAction = swipeLeftAction, swipeRightAction = swipeRightAction, diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/layout/FlowBottomInsets.kt b/app/src/main/java/io/github/aedev/flow/ui/components/layout/FlowBottomInsets.kt index 51b0058ead..44a7359a46 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/layout/FlowBottomInsets.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/layout/FlowBottomInsets.kt @@ -41,6 +41,9 @@ class FlowBottomInsets( private val barFraction: () -> Float, private val miniPlayerFraction: () -> Float, private val miniPlayerSpanPx: State> = mutableStateOf(0f..Float.MAX_VALUE), + private val miniPlayerDock: () -> Float = { 0f }, + private val miniPlayerDockShift: State = mutableStateOf(0f), + private val dockedLift: State = mutableStateOf(0.dp), ) { /** Bottom space the settled chrome covers: gesture area, the bar when shown, the mini player when shown. */ val contentBottom: Dp get() = systemInset.value + barBottom + if (miniPlayerShown.value) miniPlayerHeight.value else 0.dp @@ -57,8 +60,20 @@ class FlowBottomInsets( /** What the settled bar and mini player add above the gesture area, for pages that pad that area themselves. */ val chromeAboveSystem: Dp get() = contentBottom - systemInset.value - /** Px from the window's bottom edge to where the mini player rests right now, following the bar. */ - fun miniPlayerBaselinePx(density: Density): Float = with(density) { systemInset.value.toPx() + barHeight.value.toPx() * barFraction() } + /** + * Px from the window's bottom edge to where the mini player rests right now, following the bar, or + * dropping into the floating bar's row while it sits beside the shrunk bar. + */ + fun miniPlayerBaselinePx(density: Density): Float = + with(density) { + val system = systemInset.value.toPx() + val aboveBar = system + barHeight.value.toPx() * barFraction() + val inRow = system + dockedLift.value.toPx() + aboveBar + (inRow - aboveBar) * miniPlayerDock() + } + + /** Px the mini player's start edge moves in, and its width shrinks, to sit beside the shrunk floating bar. */ + fun miniPlayerDockShiftPx(): Float = miniPlayerDockShift.value * miniPlayerDock() /** Px from the window's bottom edge to the top of the chrome right now, for things that float above it. */ fun floatingBottomPx(density: Density): Float = diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavGeometry.kt b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavGeometry.kt new file mode 100644 index 0000000000..82eae9cf3c --- /dev/null +++ b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavGeometry.kt @@ -0,0 +1,136 @@ +package io.github.aedev.flow.ui.components.layout.navigation + +import io.github.aedev.flow.data.local.NavBarLabels + +/** Item sizes of the floating bar, in px. */ +internal data class FloatingNavMetrics( + val iconItem: Float, + val icon: Float, + val labelledStart: Float, + val iconLabelGap: Float, + val labelledEnd: Float, + val namedItemMin: Float, + val namedItemPadding: Float, + val plainItem: Float, + val gap: Float, + val belowIndicatorWidth: Float, +) + +/** Where a tab's name sits. */ +internal enum class FloatingNavNames { + /** Only the open tab is named, beside its icon. */ + BESIDE_OPEN, + + /** Every tab is named under its icon. */ + BELOW, + + /** No names. */ + NONE, +} + +/** The bar at rest: each item's width and start, and the indicator's span over the open tab. */ +internal data class FloatingNavGeometry( + val widths: List, + val starts: List, + val names: FloatingNavNames, + val width: Float, + val indicatorStart: Float, + val indicatorEnd: Float, +) { + /** The item whose centre is nearest [x], ignoring items folded away. */ + fun itemAt(x: Float): Int { + var best = 0 + var bestDistance = Float.MAX_VALUE + widths.forEachIndexed { index, width -> + if (width <= 0f) return@forEachIndexed + val distance = kotlin.math.abs(x - (starts[index] + width / 2f)) + if (distance < bestDistance) { + bestDistance = distance + best = index + } + } + return best + } + + /** The indicator's span when it sits on [index]. */ + fun indicatorSpan( + index: Int, + metrics: FloatingNavMetrics, + ): ClosedFloatingPointRange { + val start = starts[index] + val width = widths[index] + if (names != FloatingNavNames.BELOW) return start..(start + width) + val centre = start + width / 2f + return (centre - metrics.belowIndicatorWidth / 2f)..(centre + metrics.belowIndicatorWidth / 2f) + } +} + +/** + * Lays out [nameWidths.size] tabs with [open] open inside [maxWidth]. The open tab's name goes beside its + * icon when [labels] allows it and it fits, else the tab shows its icon alone. [collapsed] folds the bar + * down to the open tab's icon. + */ +internal fun floatingNavGeometry( + nameWidths: List, + open: Int, + labels: NavBarLabels, + maxWidth: Float, + collapsed: Boolean, + metrics: FloatingNavMetrics, +): FloatingNavGeometry { + val count = nameWidths.size + val (widths, names) = + when { + collapsed -> List(count) { if (it == open) metrics.iconItem else 0f } to FloatingNavNames.NONE + labels == NavBarLabels.ALWAYS -> namedBelow(nameWidths, maxWidth, metrics) to FloatingNavNames.BELOW + labels == NavBarLabels.SELECTED -> nameBesideOpen(nameWidths, open, maxWidth, metrics) + else -> plain(count, maxWidth, metrics) to FloatingNavNames.NONE + } + val starts = ArrayList(count) + var x = 0f + widths.forEachIndexed { index, width -> + starts += x + x += width + if (index < count - 1 && width > 0f && widths.drop(index + 1).any { it > 0f }) x += metrics.gap + } + val geometry = FloatingNavGeometry(widths, starts, names, x, 0f, 0f) + val span = geometry.indicatorSpan(open.coerceIn(0, count - 1), metrics) + return geometry.copy(indicatorStart = span.start, indicatorEnd = span.endInclusive) +} + +private fun totalWidth( + widths: List, + metrics: FloatingNavMetrics, +): Float = widths.sum() + metrics.gap * (widths.size - 1).coerceAtLeast(0) + +private fun nameBesideOpen( + nameWidths: List, + open: Int, + maxWidth: Float, + metrics: FloatingNavMetrics, +): Pair, FloatingNavNames> { + val openWidth = metrics.labelledStart + metrics.icon + metrics.iconLabelGap + nameWidths[open] + metrics.labelledEnd + val named = nameWidths.indices.map { if (it == open) openWidth else metrics.iconItem } + if (totalWidth(named, metrics) <= maxWidth) return named to FloatingNavNames.BESIDE_OPEN + return plain(nameWidths.size, maxWidth, metrics) to FloatingNavNames.NONE +} + +private fun namedBelow( + nameWidths: List, + maxWidth: Float, + metrics: FloatingNavMetrics, +): List { + val natural = nameWidths.map { maxOf(metrics.namedItemMin, it + metrics.namedItemPadding) } + if (totalWidth(natural, metrics) <= maxWidth) return natural + val share = (maxWidth - metrics.gap * (nameWidths.size - 1)) / nameWidths.size + return List(nameWidths.size) { maxOf(metrics.iconItem, share) } +} + +private fun plain( + count: Int, + maxWidth: Float, + metrics: FloatingNavMetrics, +): List { + val roomy = List(count) { metrics.plainItem } + return if (totalWidth(roomy, metrics) <= maxWidth) roomy else List(count) { metrics.iconItem } +} diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavItem.kt b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavItem.kt new file mode 100644 index 0000000000..9998c7c56e --- /dev/null +++ b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavItem.kt @@ -0,0 +1,196 @@ +package io.github.aedev.flow.ui.components.layout.navigation + +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsPressedAsState +import androidx.compose.foundation.selection.selectable +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.ripple +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.State +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.layout.Layout +import androidx.compose.ui.layout.layout +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.clearAndSetSemantics +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Constraints +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import kotlin.math.roundToInt + +internal val FloatingNavItemHeight: Dp = 48.dp +internal val FloatingNavNamedBelowHeight: Dp = 56.dp +internal val FloatingNavBelowIndicatorHeight: Dp = 32.dp +private val NameBesideMinStart = 12.dp +private val NameBelowIconTop = 4.dp +private val NameBelowGap = 4.dp +private const val PRESSED_SCALE = 0.92f +private const val POP_VELOCITY = 4f + +/** + * One slot of the floating bar. Its width comes from [width], read in layout only, so the bar can spring + * every slot's width without recomposing. The name fades in as the open slot grows to [namedWidth]. + */ +@Composable +internal fun FloatingNavItem( + icon: ImageVector, + name: String, + selected: Boolean, + names: FloatingNavNames, + width: State, + namedWidth: Float, + contentColor: Color, + pop: Boolean, + hidden: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier, +) { + val motion = MaterialTheme.motionScheme + val interaction = remember { MutableInteractionSource() } + val pressed by interaction.collectIsPressedAsState() + val pressScale by animateFloatAsState( + targetValue = if (pressed) PRESSED_SCALE else 1f, + animationSpec = if (pressed) motion.fastEffectsSpec() else motion.fastSpatialSpec(), + label = "navItemPress", + ) + val popScale = remember { Animatable(1f) } + val firstSelection = remember { booleanArrayOf(true) } + LaunchedEffect(selected) { + val initial = firstSelection[0] + firstSelection[0] = false + if (selected && pop && !initial) popScale.animateTo(1f, motion.fastSpatialSpec(), initialVelocity = POP_VELOCITY) + } + val iconItem = FloatingNavItemHeight + val showsName = names == FloatingNavNames.BELOW || (names == FloatingNavNames.BESIDE_OPEN && selected) + val description = if (showsName) null else name + + Layout( + content = { + Icon( + imageVector = icon, + contentDescription = description, + tint = contentColor, + modifier = + Modifier.graphicsLayer { + scaleX = popScale.value + scaleY = popScale.value + }, + ) + if (names != FloatingNavNames.NONE) { + Text( + text = name, + color = contentColor, + style = + if (names == + FloatingNavNames.BELOW + ) { + MaterialTheme.typography.labelMedium + } else { + MaterialTheme.typography.labelLarge + }, + maxLines = 1, + softWrap = false, + overflow = if (names == FloatingNavNames.BELOW) TextOverflow.Ellipsis else TextOverflow.Clip, + ) + } + }, + modifier = + modifier + .layout { measurable, _ -> + val w = width.value.roundToInt().coerceAtLeast(0) + val h = (if (names == FloatingNavNames.BELOW) FloatingNavNamedBelowHeight else iconItem).roundToPx() + val placeable = measurable.measure(Constraints.fixed(w, h)) + layout(w, h) { + placeable.placeWithLayer(0, 0) { + alpha = (width.value / iconItem.toPx()).coerceIn(0f, 1f) + scaleX = pressScale + scaleY = pressScale + } + } + }.clip(CircleShape) + .then(if (hidden) Modifier.clearAndSetSemantics {} else Modifier) + .selectable( + selected = selected, + enabled = !hidden, + onClick = onClick, + role = Role.Tab, + interactionSource = interaction, + indication = ripple(), + ), + ) { measurables, constraints -> + val w = constraints.maxWidth + val h = constraints.maxHeight + val iconPlaceable = measurables[0].measure(Constraints()) + val namePlaceable = + measurables.getOrNull(1)?.measure( + if (names == + FloatingNavNames.BELOW + ) { + Constraints(maxWidth = w) + } else { + Constraints() + }, + ) + layout(w, h) { + when { + names == FloatingNavNames.BELOW && namePlaceable != null -> { + val iconTop = NameBelowIconTop.roundToPx() + (FloatingNavBelowIndicatorHeight.roundToPx() - iconPlaceable.height) / 2 + iconPlaceable.placeRelative((w - iconPlaceable.width) / 2, iconTop) + namePlaceable.placeRelative( + (w - namePlaceable.width) / 2, + NameBelowIconTop.roundToPx() + FloatingNavBelowIndicatorHeight.roundToPx() + NameBelowGap.roundToPx(), + ) + } + + showsName && namePlaceable != null -> { + val gap = 8.dp.roundToPx() + val content = iconPlaceable.width + gap + namePlaceable.width + val start = maxOf(NameBesideMinStart.roundToPx(), (w - content) / 2) + iconPlaceable.placeRelative(start, (h - iconPlaceable.height) / 2) + val iconOnly = iconItem.toPx() + namePlaceable.placeRelativeWithLayer(start + iconPlaceable.width + gap, (h - namePlaceable.height) / 2) { + alpha = ((width.value - iconOnly) / (namedWidth - iconOnly).coerceAtLeast(1f)).coerceIn(0f, 1f) + } + } + + else -> { + iconPlaceable.placeRelative((w - iconPlaceable.width) / 2, (h - iconPlaceable.height) / 2) + } + } + } + } +} + +/** The fixed sizes of the floating bar's slots. */ +@Composable +internal fun rememberFloatingNavMetrics(): FloatingNavMetrics { + val density = androidx.compose.ui.platform.LocalDensity.current + return remember(density) { + with(density) { + FloatingNavMetrics( + iconItem = FloatingNavItemHeight.toPx(), + icon = 24.dp.toPx(), + labelledStart = 16.dp.toPx(), + iconLabelGap = 8.dp.toPx(), + labelledEnd = 20.dp.toPx(), + namedItemMin = 64.dp.toPx(), + namedItemPadding = 16.dp.toPx(), + plainItem = 56.dp.toPx(), + gap = 2.dp.toPx(), + belowIndicatorWidth = 56.dp.toPx(), + ) + } + } +} diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowFloatingNavigationBar.kt b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowFloatingNavigationBar.kt index 50ee5289e2..82e10c662d 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowFloatingNavigationBar.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowFloatingNavigationBar.kt @@ -1,5 +1,11 @@ package io.github.aedev.flow.ui.components.layout.navigation +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.gestures.awaitEachGesture +import androidx.compose.foundation.gestures.awaitFirstDown +import androidx.compose.foundation.gestures.awaitHorizontalTouchSlopOrCancellation +import androidx.compose.foundation.gestures.horizontalDrag import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsetsSides @@ -7,151 +13,323 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.MoreHoriz import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi import androidx.compose.material3.FloatingToolbarDefaults import androidx.compose.material3.HorizontalFloatingToolbar -import androidx.compose.material3.NavigationItemIconPosition +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ShortNavigationBarDefaults +import androidx.compose.material3.ShortNavigationBarItemDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.key +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.SubcomposeLayout +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.CornerRadius +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.TransformOrigin +import androidx.compose.ui.graphics.graphicsLayer +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.Layout +import androidx.compose.ui.layout.layout +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalHapticFeedback +import androidx.compose.ui.platform.LocalLayoutDirection +import androidx.compose.ui.platform.LocalWindowInfo +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.rememberTextMeasurer import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.unit.dp +import io.github.aedev.flow.R import io.github.aedev.flow.data.local.NavBarLabels +import io.github.aedev.flow.data.local.NavBarLook import io.github.aedev.flow.ui.components.shared.MediaMiniBarDefaults +import kotlinx.coroutines.launch +import kotlin.math.roundToInt -/** How the floating bar lays out its tabs, from the most to the least room it needs. */ -internal enum class FloatingNavLayout { - /** Only the open tab is named, beside its icon. */ - EXPANDING, +private const val SCRUB_SCALE = 1.035f +private val BelowIndicatorTop = 4.dp - /** Every tab at its own width, named under its icon as the labels setting says. */ - PILL, - - /** The pill stretched to the mini player's width, tabs sharing it equally. */ - WIDE, -} - -/** Four tabs is where the open tab's name beside its icon stops fitting a phone. */ -internal const val MAX_EXPANDING_SLOTS = 4 - -/** - * Picks the first layout that fits [maxWidth]: expanding while there are at most - * [MAX_EXPANDING_SLOTS] slots and names are shown, then the pill, then the wide bar. - */ -internal fun chooseFloatingNavLayout( - slotCount: Int, - labels: NavBarLabels, - maxWidth: Int, - expandingWidth: () -> Int, - pillWidth: () -> Int, -): FloatingNavLayout = - when { - labels != NavBarLabels.NEVER && slotCount <= MAX_EXPANDING_SLOTS && expandingWidth() <= maxWidth -> FloatingNavLayout.EXPANDING - pillWidth() <= maxWidth -> FloatingNavLayout.PILL - else -> FloatingNavLayout.WIDE - } +/** One slot of the floating bar: a tab, or the "More" slot when [tab] is null. */ +private data class FloatingNavSlot( + val tab: FlowTab?, + val name: String, +) /** - * The bottom bar in its floating style: Material's floating toolbar holding the same items as the - * standard bar, above the gesture area. Its measured height includes that gap, so pages and the - * mini player clear it the way they clear the standard bar. + * The bottom bar in its floating style: Material's floating toolbar holding one row of tabs with a single + * indicator that travels between them. Its front edge leads on the fast spring and its back edge follows on + * the default one, so it stretches on the way, and every slot's width springs with it. Dragging along the + * bar scrubs the indicator across the tabs and opens the one under the finger on release. + * + * Material's navigation items each draw their own indicator, so none can travel between them; the row is + * built from foundation primitives inside Material's toolbar container instead. */ +@OptIn(ExperimentalMaterial3ExpressiveApi::class) @Composable internal fun FlowFloatingNavigationBar( tabs: List, selectedTab: FlowTab?, onTabSelected: (FlowTab) -> Unit, - labels: NavBarLabels, + look: NavBarLook, + collapsed: Boolean, + onExpand: () -> Unit, modifier: Modifier = Modifier, ) { val (barTabs, overflowTabs) = splitTabsForOverflow(tabs, MAX_BAR_TABS) - // What each slot shows when it is the open one: its own tab, or for "More" the first tab behind it. - val slotTabs = barTabs + listOfNotNull(overflowTabs.firstOrNull()) + val moreName = stringResource(R.string.nav_more) + val slots = + barTabs.map { FloatingNavSlot(it, stringResource(it.labelRes)) } + + listOfNotNull(FloatingNavSlot(null, moreName).takeIf { overflowTabs.isNotEmpty() }) + val open = + when (selectedTab) { + null -> -1 + in barTabs -> barTabs.indexOf(selectedTab) + in overflowTabs -> slots.lastIndex + else -> -1 + } + val labels = if (open < 0 && look.labels == NavBarLabels.SELECTED) NavBarLabels.NEVER else look.labels + + val metrics = rememberFloatingNavMetrics() + val density = LocalDensity.current + val sidePadding = FloatingToolbarDefaults.ContentPadding.calculateLeftPadding(LayoutDirection.Ltr) + val windowWidth = LocalWindowInfo.current.containerSize.width + val maxRowWidth = with(density) { windowWidth - 2 * (MediaMiniBarDefaults.CompactMargin + sidePadding).toPx() } + val measurer = rememberTextMeasurer() + val besideStyle = MaterialTheme.typography.labelLarge + val belowStyle = MaterialTheme.typography.labelMedium + val nameWidths = + remember(slots, labels, besideStyle, belowStyle, density) { + val style = if (labels == NavBarLabels.ALWAYS) belowStyle else besideStyle + slots.map { + measurer + .measure(it.name, style, maxLines = 1, softWrap = false) + .size.width + .toFloat() + } + } + val geometry = + remember(nameWidths, open, labels, maxRowWidth, metrics, collapsed) { + floatingNavGeometry( + nameWidths, + open.coerceAtLeast(0), + labels, + maxRowWidth, + collapsed = collapsed && open >= 0, + metrics = metrics, + ) + } + val folded = collapsed && open >= 0 + val fold = + animateFloatAsState( + targetValue = if (folded) 1f else 0f, + animationSpec = MaterialTheme.motionScheme.defaultSpatialSpec(), + label = "navFold", + ) + + var scrubbing by remember { mutableStateOf(false) } + val scrubScale by animateFloatAsState( + targetValue = if (scrubbing) SCRUB_SCALE else 1f, + animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), + label = "navScrubScale", + ) + var menuOpen by remember { mutableStateOf(false) } - SubcomposeLayout( + Box( modifier = modifier + .fillMaxWidth() .windowInsetsPadding(ShortNavigationBarDefaults.windowInsets.only(WindowInsetsSides.Bottom + WindowInsetsSides.Horizontal)) .padding(horizontal = MediaMiniBarDefaults.CompactMargin) .padding(bottom = FloatingToolbarDefaults.ScreenOffset), - ) { constraints -> - val unbounded = Constraints(maxHeight = constraints.maxHeight) - - // Measured with every slot open in turn, so the bar keeps its layout whichever tab is open. - fun widest(layout: FloatingNavLayout): Int = - slotTabs.withIndex().maxOf { (index, open) -> - subcompose("$layout$index") { - FloatingNavTabs(barTabs, overflowTabs, open, onTabSelected, labels, layout) - }.maxOf { it.measure(unbounded).width } - } - - val layout = - chooseFloatingNavLayout( - slotCount = slotTabs.size, - labels = labels, - maxWidth = constraints.maxWidth, - expandingWidth = { widest(FloatingNavLayout.EXPANDING) }, - pillWidth = { widest(FloatingNavLayout.PILL) }, + contentAlignment = Alignment.BottomStart, + ) { + HorizontalFloatingToolbar( + expanded = true, + colors = FloatingToolbarDefaults.standardFloatingToolbarColors(), + // Items bring their own height; the toolbar's vertical padding would make the bar taller than 64 dp. + contentPadding = PaddingValues(horizontal = sidePadding), + modifier = + Modifier + .layout { measurable, constraints -> + val placeable = measurable.measure(constraints.copy(minWidth = 0)) + layout(constraints.maxWidth, placeable.height) { + // Centred while open, sliding to the start edge as it folds to the open tab. + val centred = (constraints.maxWidth - placeable.width) / 2f + placeable.placeRelative((centred * (1f - fold.value)).roundToInt(), 0) + } + }.graphicsLayer { + scaleX = scrubScale + scaleY = scrubScale + transformOrigin = TransformOrigin(0.5f, 1f) + }, + ) { + FloatingNavRow( + slots = slots, + open = open, + geometry = geometry, + metrics = metrics, + scrub = look.scrub && !folded, + folded = folded, + pop = look.iconPop, + onScrubbing = { scrubbing = it }, + onSelect = { index -> + val tab = slots.getOrNull(index)?.tab + when { + folded -> onExpand() + tab != null -> onTabSelected(tab) + overflowTabs.isNotEmpty() -> menuOpen = true + } + }, ) - val bar = - subcompose(layout) { - FloatingNavTabs(barTabs, overflowTabs, selectedTab, onTabSelected, labels, layout) - }.map { it.measure(constraints.copy(minWidth = 0, minHeight = 0)) } - val height = bar.maxOf { it.height } - layout(constraints.maxWidth, height) { - bar.forEach { it.placeRelative((constraints.maxWidth - it.width) / 2, 0) } + if (overflowTabs.isNotEmpty()) { + // The menu anchors to the end of the bar, where "More" sits. + Box { + FlowTabOverflowMenu( + expanded = menuOpen, + onDismissRequest = { menuOpen = false }, + tabs = overflowTabs, + selectedTab = selectedTab, + onTabSelected = onTabSelected, + ) + } + } } } } -@OptIn(ExperimentalMaterial3ExpressiveApi::class) @Composable -private fun FloatingNavTabs( - barTabs: List, - overflowTabs: List, - selectedTab: FlowTab?, - onTabSelected: (FlowTab) -> Unit, - labels: NavBarLabels, - layout: FloatingNavLayout, +private fun FloatingNavRow( + slots: List, + open: Int, + geometry: FloatingNavGeometry, + metrics: FloatingNavMetrics, + scrub: Boolean, + folded: Boolean, + pop: Boolean, + onScrubbing: (Boolean) -> Unit, + onSelect: (Int) -> Unit, ) { - val wide = layout == FloatingNavLayout.WIDE - val sidePadding = FloatingToolbarDefaults.ContentPadding.calculateLeftPadding(LayoutDirection.Ltr) - HorizontalFloatingToolbar( - expanded = true, - colors = FloatingToolbarDefaults.standardFloatingToolbarColors(), - // Items bring their own vertical padding; the toolbar's would make a labelled bar 80 dp tall. - contentPadding = PaddingValues(horizontal = sidePadding), - modifier = if (wide) Modifier.fillMaxWidth() else Modifier, - ) { - val itemModifier = if (wide) Modifier.weight(1f) else Modifier - - fun showsLabel(selected: Boolean) = if (layout == FloatingNavLayout.EXPANDING) selected else labels.shows(selected) + val motion = MaterialTheme.motionScheme + val colors = ShortNavigationBarItemDefaults.colors() + val haptics = LocalHapticFeedback.current + var hover by remember { mutableIntStateOf(-1) } + val target = if (hover >= 0) geometry.indicatorSpan(hover, metrics) else geometry.indicatorStart..geometry.indicatorEnd + val indicatorStart = remember { Animatable(target.start) } + val indicatorEnd = remember { Animatable(target.endInclusive) } + LaunchedEffect(target.start, target.endInclusive) { + val forward = target.start > indicatorStart.value + launch { indicatorStart.animateTo(target.start, if (forward) motion.defaultSpatialSpec() else motion.fastSpatialSpec()) } + launch { indicatorEnd.animateTo(target.endInclusive, if (forward) motion.fastSpatialSpec() else motion.defaultSpatialSpec()) } + } + val currentGeometry by rememberUpdatedState(geometry) + val ltr by rememberUpdatedState(LocalLayoutDirection.current == LayoutDirection.Ltr) + val currentSelect by rememberUpdatedState(onSelect) + val indicatorColor = colors.selectedIndicatorColor + val belowNames = geometry.names == FloatingNavNames.BELOW - fun position(selected: Boolean) = - if (layout == FloatingNavLayout.EXPANDING && selected) NavigationItemIconPosition.Start else NavigationItemIconPosition.Top - barTabs.forEach { tab -> - val selected = tab == selectedTab - Box(itemModifier, propagateMinConstraints = true) { - FlowTabBarItem( - tab = tab, - selected = selected, - onClick = { onTabSelected(tab) }, - showsLabel = showsLabel(selected), - iconPosition = position(selected), - ) + Layout( + content = { + slots.forEachIndexed { index, slot -> + key(slot.tab, slot.name) { + val selected = index == open + val target = geometry.widths.getOrElse(index) { 0f } + val width = animateFloatAsState(target, motion.defaultSpatialSpec(), label = "navItemWidth") + FloatingNavItem( + icon = slot.tab?.icon(selected) ?: Icons.Filled.MoreHoriz, + name = slot.name, + selected = selected, + names = geometry.names, + width = width, + namedWidth = target, + contentColor = + when { + !selected -> colors.unselectedIconColor + belowNames -> colors.selectedIconColor + else -> colors.selectedTextColorStartIconPosition + }, + pop = pop, + hidden = folded && !selected, + onClick = { currentSelect(index) }, + ) + } } + }, + modifier = + Modifier + .drawBehind { + if (open < 0) return@drawBehind + val height = if (belowNames) FloatingNavBelowIndicatorHeight.toPx() else size.height + val top = if (belowNames) BelowIndicatorTop.toPx() else 0f + var start = indicatorStart.value + var end = maxOf(indicatorEnd.value, start + height) + if (layoutDirection == LayoutDirection.Rtl) { + val mirroredStart = size.width - end + end = size.width - start + start = mirroredStart + } + drawRoundRect( + color = indicatorColor, + topLeft = Offset(start, top), + size = Size(end - start, height), + cornerRadius = CornerRadius(height / 2f), + ) + }.pointerInput(scrub) { + if (!scrub) return@pointerInput + awaitEachGesture { + val down = awaitFirstDown(requireUnconsumed = false) + val drag = + awaitHorizontalTouchSlopOrCancellation(down.id) { change, _ -> change.consume() } + ?: return@awaitEachGesture + + fun hoverAt(x: Float) { + val index = currentGeometry.itemAt(if (ltr) x else size.width - x) + if (index != hover) { + hover = index + haptics.performHapticFeedback(HapticFeedbackType.SegmentTick) + } + } + onScrubbing(true) + hoverAt(drag.position.x) + val finished = + horizontalDrag(drag.id) { change -> + change.consume() + hoverAt(change.position.x) + } + val chosen = hover + hover = -1 + onScrubbing(false) + if (finished && chosen >= 0) { + haptics.performHapticFeedback(HapticFeedbackType.Confirm) + currentSelect(chosen) + } + } + }, + ) { measurables, constraints -> + val placeables = measurables.map { it.measure(constraints.copy(minWidth = 0, maxWidth = Constraints.Infinity)) } + val starts = IntArray(placeables.size) + var x = 0f + placeables.forEachIndexed { index, placeable -> + starts[index] = x.roundToInt() + x += placeable.width + val next = placeables.getOrNull(index + 1) + if (next != null) x += metrics.gap * minOf(1f, placeable.width / metrics.iconItem, next.width / metrics.iconItem) } - if (overflowTabs.isNotEmpty()) { - val selected = selectedTab in overflowTabs - FlowOverflowBarItem( - tabs = overflowTabs, - selectedTab = selectedTab, - onTabSelected = onTabSelected, - showsLabel = showsLabel(selected), - iconPosition = position(selected), - modifier = itemModifier, - ) + val height = placeables.maxOfOrNull { it.height } ?: 0 + layout(x.roundToInt(), height) { + placeables.forEachIndexed { index, placeable -> placeable.placeRelative(starts[index], (height - placeable.height) / 2) } } } } diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationChrome.kt b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationChrome.kt index ef8af8f31d..d2075203b1 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationChrome.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationChrome.kt @@ -14,10 +14,13 @@ import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.only +import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi +import androidx.compose.material3.FloatingToolbarDefaults.floatingToolbarVerticalNestedScroll import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ShortNavigationBarDefaults import androidx.compose.material3.WideNavigationRailDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.layout.onSizeChanged @@ -28,6 +31,7 @@ import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.window.core.layout.WindowSizeClass import io.github.aedev.flow.data.local.NavBarLook +import io.github.aedev.flow.data.local.NavBarScroll import io.github.aedev.flow.data.local.NavBarStyle import io.github.aedev.flow.ui.utils.LocalWindowIsLandscape import io.github.aedev.flow.ui.utils.LocalWindowSizeClass @@ -44,6 +48,9 @@ object FlowNavigationDefaults { * container. The bar reports its real height, which grows past this at large font scales. */ val BarHeight: Dp = 64.dp + + /** One tab of the floating bar; shrunk, the bar is this plus the toolbar's side padding. */ + val FloatingItemSize: Dp = FloatingNavItemHeight } /** @@ -71,6 +78,7 @@ internal fun usesNavigationRail( * moves it with the content's scroll. The rail takes * its own column; [onRailWidthChanged] is only for overlays drawn outside this layout. */ +@OptIn(ExperimentalMaterial3ExpressiveApi::class) @Composable fun FlowNavigationChrome( tabs: List, @@ -87,6 +95,18 @@ fun FlowNavigationChrome( ) { val usesRail = flowUsesNavigationRail() val showRail = usesRail && railVisible + val shrinks = !usesRail && barLook.style == NavBarStyle.FLOATING && barLook.scroll == NavBarScroll.SHRINK + SideEffect { barScrollState?.shrinks = shrinks } + val shrinkOnScroll = + if (barScrollState != null && barScrollState.shrinks) { + Modifier.floatingToolbarVerticalNestedScroll( + expanded = !barScrollState.isCollapsed, + onExpand = barScrollState::expand, + onCollapse = barScrollState::collapse, + ) + } else { + Modifier + } val density = LocalDensity.current val railInsets = WideNavigationRailDefaults.windowInsets @@ -107,6 +127,7 @@ fun FlowNavigationChrome( Modifier .weight(1f) .fillMaxHeight() + .then(shrinkOnScroll) .then( if (showRail) { Modifier.consumeWindowInsets(railInsets.only(WindowInsetsSides.Start)) @@ -173,7 +194,9 @@ private fun BoxScope.NavigationBarSlot( tabs = tabs, selectedTab = selectedTab, onTabSelected = onTabSelected, - labels = look.labels, + look = look, + collapsed = scrollState?.isCollapsed == true, + onExpand = { scrollState?.expand() }, modifier = barModifier, ) } diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationScrollState.kt b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationScrollState.kt index 855053931a..12d98f9956 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationScrollState.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/layout/navigation/FlowNavigationScrollState.kt @@ -9,11 +9,15 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.rememberBottomAppBarState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.MutableState import androidx.compose.runtime.Stable +import androidx.compose.runtime.State import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.setValue import androidx.compose.ui.input.nestedscroll.NestedScrollConnection /** @@ -26,7 +30,28 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollConnection @Stable class FlowNavigationScrollState internal constructor( private val behavior: BottomAppBarScrollBehavior, + private val moves: State, + private val shrinkMode: MutableState, ) { + /** Whether scrolling shrinks the floating bar to its open tab instead of moving it away. */ + internal var shrinks: Boolean + get() = shrinkMode.value && moves.value + set(value) { + shrinkMode.value = value + } + + /** True while the floating bar is shrunk to its open tab. */ + var isCollapsed: Boolean by mutableStateOf(false) + internal set + + internal fun expand() { + isCollapsed = false + } + + internal fun collapse() { + if (shrinks) isCollapsed = true + } + val nestedScrollConnection: NestedScrollConnection get() = behavior.nestedScrollConnection @@ -48,6 +73,7 @@ class FlowNavigationScrollState internal constructor( } internal suspend fun show(animationSpec: AnimationSpec) { + isCollapsed = false val state = behavior.state if (state.heightOffset == 0f) return animate(state.heightOffset, 0f, animationSpec = animationSpec) { value, _ -> state.heightOffset = value } @@ -65,14 +91,15 @@ fun rememberFlowNavigationScrollState( routeKey: String, locked: Boolean, ): FlowNavigationScrollState { - val canScroll by rememberUpdatedState(hideOnScroll && !locked) + val moves = rememberUpdatedState(hideOnScroll && !locked) + val shrinkMode = remember { mutableStateOf(false) } val behavior = BottomAppBarDefaults.exitAlwaysScrollBehavior( state = rememberBottomAppBarState(), - canScroll = remember { { canScroll } }, + canScroll = remember { { moves.value && !shrinkMode.value } }, ) - val state = remember(behavior) { FlowNavigationScrollState(behavior) } + val state = remember(behavior) { FlowNavigationScrollState(behavior, moves, shrinkMode) } val showSpec = MaterialTheme.motionScheme.defaultSpatialSpec() - LaunchedEffect(state, routeKey, hideOnScroll) { state.show(showSpec) } + LaunchedEffect(state, routeKey, hideOnScroll, shrinkMode.value) { state.show(showSpec) } return state } diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/MusicSheetGeometry.kt b/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/MusicSheetGeometry.kt index 48515cf9e0..3ec4ebaac3 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/MusicSheetGeometry.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/MusicSheetGeometry.kt @@ -39,6 +39,7 @@ internal class MusicSheetGeometry( private val miniHeightPx: State, private val containerWidthPx: State, private val miniBounds: State, + private val dockShiftPx: () -> Float, private val collapsedRadiusPx: State, ) { fun fraction(): Float = (state.expansionFraction.value * (1f - predictiveBackProgress.value)).coerceIn(0f, 1f) @@ -63,9 +64,9 @@ internal class MusicSheetGeometry( } /** The card's start edge: the mini player's resting start, opening out to the window's edge. */ - fun cardStartPx(): Float = lerp(miniBounds.value.start, 0f, fraction()) + fun cardStartPx(): Float = lerp(miniBounds.value.start + dockShiftPx(), 0f, fraction()) - fun cardWidthPx(): Float = lerp(miniBounds.value.width, containerWidthPx.value, fraction()) + fun cardWidthPx(): Float = lerp((miniBounds.value.width - dockShiftPx()).coerceAtLeast(0f), containerWidthPx.value, fraction()) fun containerWidthPx(): Float = containerWidthPx.value @@ -82,6 +83,7 @@ internal fun rememberMusicSheetGeometry( miniHeightPx: Float, containerWidthPx: Float, miniBounds: MediaMiniBarBounds, + dockShiftPx: () -> Float, collapsedRadiusPx: Float, ): MusicSheetGeometry { val collapsedY = rememberUpdatedState(collapsedYPx) @@ -90,6 +92,7 @@ internal fun rememberMusicSheetGeometry( val miniHeight = rememberUpdatedState(miniHeightPx) val containerWidth = rememberUpdatedState(containerWidthPx) val bounds = rememberUpdatedState(miniBounds) + val dockShift = rememberUpdatedState(dockShiftPx) val collapsedRadius = rememberUpdatedState(collapsedRadiusPx) return remember(state, predictiveBackProgress) { MusicSheetGeometry( @@ -101,6 +104,7 @@ internal fun rememberMusicSheetGeometry( miniHeightPx = miniHeight, containerWidthPx = containerWidth, miniBounds = bounds, + dockShiftPx = { dockShift.value() }, collapsedRadiusPx = collapsedRadius, ) } diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/UnifiedMusicPlayerSheet.kt b/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/UnifiedMusicPlayerSheet.kt index 54d0bacc81..b9cef3c51c 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/UnifiedMusicPlayerSheet.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/musicplayer/sheet/UnifiedMusicPlayerSheet.kt @@ -93,6 +93,7 @@ internal fun UnifiedMusicPlayerSheet( containerHeight: Dp, miniBounds: MediaMiniBarBounds, restingBottomPx: () -> Float, + miniDockShiftPx: () -> Float, track: MusicTrack, swipeLeftAction: MiniBarSwipeAction, swipeRightAction: MiniBarSwipeAction, @@ -209,6 +210,7 @@ internal fun UnifiedMusicPlayerSheet( miniHeightPx = miniHeightPx, containerWidthPx = containerWidthPx, miniBounds = miniBounds, + dockShiftPx = miniDockShiftPx, collapsedRadiusPx = with(density) { MediaMiniBarDefaults.CornerRadius.toPx() }, ) val cardShape = remember(geometry) { MusicSheetDynamicShape(geometry::cornerRadiusPx) } diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/DraggablePlayerLayout.kt b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/DraggablePlayerLayout.kt index 9f9cc5ef6c..f5301c0af8 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/DraggablePlayerLayout.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/DraggablePlayerLayout.kt @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.statusBars import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.Immutable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.SideEffect import androidx.compose.runtime.derivedStateOf @@ -59,6 +60,17 @@ const val MINI_PLAYER_CORNER_RADIUS_DP = 12f private val MiniPlayerMargin = 8.dp +/** + * Where the mini player rests while the floating navigation bar is shrunk beside it: its bottom + * edge [restBottom] above the window's bottom, and, in the bar's bottom corner, [sideClearance] + * in from that edge. + */ +@Immutable +data class MiniPlayerDock( + val restBottom: Dp, + val sideClearance: Dp, +) + /** * What the mini player is worth on a window too wide to size it by fraction: the width the default * size setting gets, which the smaller and larger settings scale around. @@ -99,6 +111,7 @@ fun DraggablePlayerLayout( miniPlayerScale: Float = 0.45f, isLargeWindow: Boolean = false, startInset: Dp = 0.dp, + miniDock: MiniPlayerDock? = null, isTwoPaneWindow: Boolean = false, detailPaneWidth: Dp = 0.dp, tapToExpand: Boolean = true, @@ -193,6 +206,9 @@ fun DraggablePlayerLayout( isShrinkingToCorner = state.isShrinkingToCorner, cachedTargetX = state.cachedTargetX, offsetXFallback = { state.offsetX.value }, + dockedBottomNavPad = miniDock?.let { with(density) { (it.restBottom - MiniPlayerMargin).toPx() } }, + dockedSideClearance = miniDock?.let { with(density) { it.sideClearance.toPx() } } ?: 0f, + dockedOnLeft = LocalLayoutDirection.current == LayoutDirection.Ltr, ) val expandedVideoWidth = geometry.expandedVideoWidth val visualMiniScale = geometry.visualMiniScale diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/VideoBackgroundBar.kt b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/VideoBackgroundBar.kt index c5275f43b5..0c8f452a94 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/VideoBackgroundBar.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/VideoBackgroundBar.kt @@ -109,6 +109,7 @@ internal fun VideoBackgroundBar( containerWidthPx: Float, containerHeightPx: Float, restingBottomPx: () -> Float, + dockShiftPx: () -> Float, onRestore: (videoWindowBounds: Rect) -> Unit, onClose: () -> Unit, onOpenQueue: () -> Unit, @@ -151,11 +152,13 @@ internal fun VideoBackgroundBar( ) val restingTop = { containerHeightPx - restingBottomPx() - spacerPx - heightPx } + val barStart = { bounds.start + dockShiftPx() } + val barWidth = { (bounds.width - dockShiftPx()).coerceAtLeast(0f) } val frameAt = { fraction: Float -> val top = restingTop() backgroundBarExpandFrame( fraction = fraction, - bar = Rect(bounds.start, top, bounds.start + bounds.width, top + heightPx), + bar = Rect(barStart(), top, barStart() + barWidth(), top + heightPx), containerWidth = containerWidthPx, containerHeight = containerHeightPx, statusBarHeight = statusBarPx, @@ -200,11 +203,15 @@ internal fun VideoBackgroundBar( Box( modifier = Modifier - .offset { IntOffset(bounds.start.roundToInt(), restingTop().roundToInt()) } - .size(with(density) { bounds.width.toDp() }, MediaMiniBarDefaults.Height) - .onPlaced { coordinates -> + .offset { IntOffset(barStart().roundToInt(), restingTop().roundToInt()) } + .layout { measurable, _ -> + val width = barWidth().roundToInt() + val height = heightPx.roundToInt() + val placeable = measurable.measure(Constraints.fixed(width, height)) + layout(width, height) { placeable.place(0, 0) } + }.onPlaced { coordinates -> val position = coordinates.positionInWindow() - containerOrigin[0] = position.x - bounds.start + containerOrigin[0] = position.x - barStart() containerOrigin[1] = position.y - restingTop() }.mediaMiniBarSwipe(enabled = true, handler = swipeHandler) .pointerInput(Unit) { @@ -283,7 +290,7 @@ internal fun VideoBackgroundBar( layout(constraints.maxWidth, constraints.maxHeight) { val top = restingTop() placeable.place( - (current.card.left - bounds.start).roundToInt(), + (current.card.left - barStart()).roundToInt(), (current.card.top - top).roundToInt(), ) } @@ -317,7 +324,7 @@ internal fun VideoBackgroundBar( isBuffering = playerState.isBuffering, hasQueue = hasQueue, onOpenQueue = onOpenQueue, - barWidthPx = bounds.width, + barWidthPx = barWidth, barHeightPx = heightPx, frame = frame, ) @@ -332,7 +339,7 @@ private fun BackgroundBarContent( isBuffering: Boolean, hasQueue: Boolean, onOpenQueue: () -> Unit, - barWidthPx: Float, + barWidthPx: () -> Float, barHeightPx: Float, frame: () -> BackgroundBarExpandFrame, ) { @@ -340,7 +347,7 @@ private fun BackgroundBarContent( Box( modifier = Modifier.layout { measurable, _ -> - val placeable = measurable.measure(Constraints.fixed(barWidthPx.roundToInt(), barHeightPx.roundToInt())) + val placeable = measurable.measure(Constraints.fixed(barWidthPx().roundToInt(), barHeightPx.roundToInt())) layout(placeable.width, placeable.height) { placeable.place(0, 0) } }, ) { diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/motion/DraggablePlayerGeometry.kt b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/motion/DraggablePlayerGeometry.kt index 27820edc82..c8e66ee503 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/motion/DraggablePlayerGeometry.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/motion/DraggablePlayerGeometry.kt @@ -58,6 +58,22 @@ internal fun miniBoxWidthFor( clampedAspect: Float, ): Float = if (clampedAspect >= 1f) envelopeSide else envelopeSide * clampedAspect +/** + * A mini player resting in a bottom corner on the shrunk navigation bar's side moves in by + * [clearance] from that edge, so it sits beside the bar instead of over it. + */ +internal fun clearDockedBar( + x: Float, + corner: MiniPlayerCorner, + width: Float, + screenWidth: Float, + clearance: Float, + barOnLeft: Boolean, +): Float { + if (clearance <= 0f || corner.isTop || corner.isLeft != barOnLeft) return x + return if (barOnLeft) maxOf(x, clearance) else minOf(x, screenWidth - width - clearance) +} + /** * @param isLargeWindow the window can host one of the detail layouts, so the mini player is sized * from the window instead of the user's scale and is free to rest anywhere along the edge. @@ -85,6 +101,9 @@ internal fun computeDraggablePlayerGeometry( isShrinkingToCorner: Boolean, cachedTargetX: Float, offsetXFallback: () -> Float, + dockedBottomNavPad: Float? = null, + dockedSideClearance: Float = 0f, + dockedOnLeft: Boolean = true, ): DraggablePlayerGeometry { // The size preference applies at every window size. It used to be overwritten with a constant // on anything large, which happened to equal the "small" option — so on a tablet the setting did @@ -109,19 +128,29 @@ internal fun computeDraggablePlayerGeometry( val minX = margin + startInset val maxX = (screenWidth - miniWidth - margin).coerceAtLeast(minX) val minY = statusBarHeight + topBarPad + margin - val maxY = (screenHeight - miniHeight - bottomNavPad - margin).coerceAtLeast(minY) + val wideBottomNavPad = bottomNavPad + val restingBottomNavPad = dockedBottomNavPad ?: bottomNavPad + val maxY = (screenHeight - miniHeight - restingBottomNavPad - margin).coerceAtLeast(minY) val normalMiniWidth = miniBoxWidthFor(baseMiniWidth, clampedAspect) val normalMiniHeight = normalMiniWidth / clampedAspect val normalMaxX = (screenWidth - normalMiniWidth - margin).coerceAtLeast(margin) - val normalMaxY = (screenHeight - normalMiniHeight - bottomNavPad - margin).coerceAtLeast(minY) - val normalTargetX = cornerTargetX(corner, minX = minX, maxX = normalMaxX) + val normalMaxY = (screenHeight - normalMiniHeight - restingBottomNavPad - margin).coerceAtLeast(minY) + val normalTargetX = + clearDockedBar( + x = cornerTargetX(corner, minX = minX, maxX = normalMaxX), + corner = corner, + width = normalMiniWidth, + screenWidth = screenWidth, + clearance = dockedSideClearance, + barOnLeft = dockedOnLeft, + ) val normalTargetY = cornerTargetY(corner, minY = minY, maxY = normalMaxY) val stableWideWidth = miniBoxWidthFor(maxWideWidth, clampedAspect) val stablePhoneCenteredX = ((screenWidth - stableWideWidth) / 2f).coerceAtLeast(margin) val stableWideHeight = stableWideWidth / clampedAspect - val stableWideMaxY = (screenHeight - stableWideHeight - bottomNavPad - margin).coerceAtLeast(minY) + val stableWideMaxY = (screenHeight - stableWideHeight - wideBottomNavPad - margin).coerceAtLeast(minY) val stableWideTargetY = cornerTargetY(corner, minY = minY, maxY = stableWideMaxY) val targetMiniX = @@ -138,7 +167,7 @@ internal fun computeDraggablePlayerGeometry( screenHeight = screenHeight, statusBarHeight = statusBarHeight, margin = margin, - bottomNavPad = bottomNavPad, + bottomNavPad = restingBottomNavPad, clampedAspect = clampedAspect, baseMiniWidth = baseMiniWidth, maxWideWidth = maxWideWidth, diff --git a/app/src/main/java/io/github/aedev/flow/ui/screens/player/VideoPlayerHost.kt b/app/src/main/java/io/github/aedev/flow/ui/screens/player/VideoPlayerHost.kt index 8989db093a..faaa7ed3f3 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/screens/player/VideoPlayerHost.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/screens/player/VideoPlayerHost.kt @@ -22,6 +22,7 @@ import io.github.aedev.flow.player.GlobalPlayerState import io.github.aedev.flow.player.dlna.DlnaCastManager import io.github.aedev.flow.ui.components.layout.flowWindowAdaptiveInfo import io.github.aedev.flow.ui.components.videoplayer.DraggablePlayerLayout +import io.github.aedev.flow.ui.components.videoplayer.MiniPlayerDock import io.github.aedev.flow.ui.components.videoplayer.PlayerDraggableState import io.github.aedev.flow.ui.components.videoplayer.PlayerSheetValue import io.github.aedev.flow.ui.components.videoplayer.isImmersivePlayer @@ -60,6 +61,7 @@ fun VideoPlayerHost( playerSheetState: PlayerDraggableState, bottomPadding: androidx.compose.ui.unit.Dp = 0.dp, startInset: androidx.compose.ui.unit.Dp = 0.dp, + miniDock: MiniPlayerDock? = null, miniPlayerScale: Float = 0.45f, miniPlayerShowSkipControls: Boolean = false, miniPlayerShowNextPrevControls: Boolean = false, @@ -482,6 +484,7 @@ fun VideoPlayerHost( isTwoPaneWindow = isTwoPaneWindow, detailPaneWidth = detailPaneWidth, startInset = startInset, + miniDock = miniDock, tapToExpand = true, statusBarGlow = { PlayerAmbientStatusBar(stageSession, it) }, onDismiss = onClose, diff --git a/app/src/main/java/io/github/aedev/flow/ui/screens/playon/RemoteMiniBar.kt b/app/src/main/java/io/github/aedev/flow/ui/screens/playon/RemoteMiniBar.kt index 851756c439..46c75a5306 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/screens/playon/RemoteMiniBar.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/screens/playon/RemoteMiniBar.kt @@ -27,9 +27,11 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.layout import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -60,6 +62,7 @@ internal fun RemoteMiniBar( bounds: MediaMiniBarBounds, containerHeightPx: Float, restingBottomPx: () -> Float, + dockShiftPx: () -> Float, ) { val playOn = LocalPlayOn.current ?: return val elsewhere by playOn.elsewhere.collectAsStateWithLifecycle() @@ -68,14 +71,21 @@ internal fun RemoteMiniBar( val other = offered when { driven != null -> { - RemoteBarFrame(bounds, containerHeightPx, restingBottomPx, onClick = { playOn.open.value = true }) { + RemoteBarFrame(bounds, containerHeightPx, restingBottomPx, dockShiftPx, onClick = { playOn.open.value = true }) { DrivenContent(playOn, driven) } } other != null -> { val label = stringResource(R.string.play_on_control_device, other.name) - RemoteBarFrame(bounds, containerHeightPx, restingBottomPx, onClick = { playOn.drive(other) }, onClickLabel = label) { + RemoteBarFrame( + bounds, + containerHeightPx, + restingBottomPx, + dockShiftPx, + onClick = { playOn.drive(other) }, + onClickLabel = label, + ) { OfferedContent(playOn, other) } } @@ -87,6 +97,7 @@ private fun RemoteBarFrame( bounds: MediaMiniBarBounds, containerHeightPx: Float, restingBottomPx: () -> Float, + dockShiftPx: () -> Float, onClick: () -> Unit, onClickLabel: String? = null, content: @Composable RowScope.() -> Unit, @@ -99,9 +110,17 @@ private fun RemoteBarFrame( color = MaterialTheme.colorScheme.surfaceContainerHigh, modifier = Modifier - .offset { IntOffset(bounds.start.roundToInt(), (containerHeightPx - restingBottomPx() - spacerPx - heightPx).roundToInt()) } - .size(with(density) { bounds.width.toDp() }, MediaMiniBarDefaults.Height) - .clickable(onClickLabel = onClickLabel, onClick = onClick), + .offset { + IntOffset( + (bounds.start + dockShiftPx()).roundToInt(), + (containerHeightPx - restingBottomPx() - spacerPx - heightPx).roundToInt(), + ) + }.layout { measurable, _ -> + val width = (bounds.width - dockShiftPx()).roundToInt().coerceAtLeast(0) + val height = heightPx.roundToInt() + val placeable = measurable.measure(Constraints.fixed(width, height)) + layout(width, height) { placeable.place(0, 0) } + }.clickable(onClickLabel = onClickLabel, onClick = onClick), ) { Row(Modifier.padding(horizontal = 10.dp), verticalAlignment = Alignment.CenterVertically, content = content) } diff --git a/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/AppearanceViewModel.kt b/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/AppearanceViewModel.kt index d57c7dfcf7..6df9506f92 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/AppearanceViewModel.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/AppearanceViewModel.kt @@ -11,6 +11,7 @@ import io.github.aedev.flow.data.local.HomeFeedColumns import io.github.aedev.flow.data.local.HomeViewMode import io.github.aedev.flow.data.local.LocalDataManager import io.github.aedev.flow.data.local.NavBarLabels +import io.github.aedev.flow.data.local.NavBarScroll import io.github.aedev.flow.data.local.NavBarStyle import io.github.aedev.flow.data.local.PlayerPreferences import io.github.aedev.flow.platform.AppIconController @@ -74,6 +75,10 @@ class AppearanceViewModel val hideNavOnScroll = preferences.bottomNavHideOnScroll.asState(true) val navLabels = preferences.bottomNavLabels.asState(NavBarLabels.ALWAYS) val navStyle = preferences.bottomNavStyle.asState(NavBarStyle.STANDARD) + val navScrub = preferences.bottomNavScrub.asState(true) + val navIconPop = preferences.bottomNavIconPop.asState(false) + val navScroll = preferences.bottomNavScroll.asState(NavBarScroll.SHRINK) + val navMiniBeside = preferences.bottomNavMiniBeside.asState(false) val searchShowsNavBar = preferences.searchShowsNavBar.asState(false) val innerPagesShowNavBar = preferences.innerPagesShowNavBar.asState(false) val navTabOrder = preferences.navTabOrder.asState(DEFAULT_NAV_TAB_ORDER) @@ -154,6 +159,14 @@ class AppearanceViewModel fun setNavStyle(style: NavBarStyle) = write { preferences.setBottomNavStyle(style) } + fun setNavScrub(enabled: Boolean) = write { preferences.setBottomNavScrub(enabled) } + + fun setNavIconPop(enabled: Boolean) = write { preferences.setBottomNavIconPop(enabled) } + + fun setNavScroll(scroll: NavBarScroll) = write { preferences.setBottomNavScroll(scroll) } + + fun setNavMiniBeside(enabled: Boolean) = write { preferences.setBottomNavMiniBeside(enabled) } + fun setSearchShowsNavBar(enabled: Boolean) = write { preferences.setSearchShowsNavBar(enabled) } fun setInnerPagesShowNavBar(enabled: Boolean) = write { preferences.setInnerPagesShowNavBar(enabled) } diff --git a/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/NavigationBarScreen.kt b/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/NavigationBarScreen.kt index d049aa2634..d0d3c95901 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/NavigationBarScreen.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/screens/settings/appearance/NavigationBarScreen.kt @@ -3,13 +3,16 @@ package io.github.aedev.flow.ui.screens.settings.appearance import androidx.compose.foundation.background import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Animation import androidx.compose.material.icons.outlined.CallToAction import androidx.compose.material.icons.outlined.Download import androidx.compose.material.icons.outlined.Explore import androidx.compose.material.icons.outlined.Home import androidx.compose.material.icons.outlined.MusicNote +import androidx.compose.material.icons.outlined.PictureInPictureAlt import androidx.compose.material.icons.outlined.Search import androidx.compose.material.icons.outlined.Slideshow +import androidx.compose.material.icons.outlined.Swipe import androidx.compose.material.icons.outlined.UnfoldLess import androidx.compose.material.icons.outlined.WebAsset import androidx.compose.material3.MaterialTheme @@ -22,6 +25,7 @@ import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import io.github.aedev.flow.R import io.github.aedev.flow.data.local.NavBarLabels +import io.github.aedev.flow.data.local.NavBarScroll import io.github.aedev.flow.data.local.NavBarStyle import io.github.aedev.flow.ui.components.layout.navigation.resolveDefaultFlowTab import io.github.aedev.flow.ui.components.layout.navigation.visibleFlowTabs @@ -43,6 +47,10 @@ internal fun NavigationBarScreen( val hideOnScroll by viewModel.hideNavOnScroll.collectAsStateWithLifecycle() val labels by viewModel.navLabels.collectAsStateWithLifecycle() val style by viewModel.navStyle.collectAsStateWithLifecycle() + val scrub by viewModel.navScrub.collectAsStateWithLifecycle() + val iconPop by viewModel.navIconPop.collectAsStateWithLifecycle() + val scroll by viewModel.navScroll.collectAsStateWithLifecycle() + val miniBeside by viewModel.navMiniBeside.collectAsStateWithLifecycle() val searchShowsBar by viewModel.searchShowsNavBar.collectAsStateWithLifecycle() val innerPagesShowBar by viewModel.innerPagesShowNavBar.collectAsStateWithLifecycle() val order by viewModel.navTabOrder.collectAsStateWithLifecycle() @@ -64,6 +72,12 @@ internal fun NavigationBarScreen( FlowToggleOption(NavBarLabels.NEVER, stringResource(R.string.settings_nav_labels_never)), ) + val scrollOptions = + listOf( + FlowToggleOption(NavBarScroll.HIDE, stringResource(R.string.settings_nav_scroll_hide)), + FlowToggleOption(NavBarScroll.SHRINK, stringResource(R.string.settings_nav_scroll_shrink)), + ) + SettingsPage( title = stringResource(R.string.settings_navigation_bar_title), onBack = onBack, @@ -72,6 +86,26 @@ internal fun NavigationBarScreen( group(key = "navigation_bar.style", header = R.string.settings_section_style) { toggleGroup(NavigationBarIndex.style, styleOptions, style, viewModel::setNavStyle) toggleGroup(NavigationBarIndex.labels, labelOptions, labels, viewModel::setNavLabels) + if (style == NavBarStyle.FLOATING) { + toggleGroup( + NavigationBarIndex.scroll, + scrollOptions, + scroll, + viewModel::setNavScroll, + enabled = hideOnScroll, + ) + if (scroll == NavBarScroll.SHRINK) { + switch( + NavigationBarIndex.miniBeside, + miniBeside, + viewModel::setNavMiniBeside, + enabled = hideOnScroll, + icon = Icons.Outlined.PictureInPictureAlt, + ) + } + switch(NavigationBarIndex.scrub, scrub, viewModel::setNavScrub, icon = Icons.Outlined.Swipe) + switch(NavigationBarIndex.iconPop, iconPop, viewModel::setNavIconPop, icon = Icons.Outlined.Animation) + } } group(key = "navigation_bar.tabs", header = R.string.settings_section_tabs) { switch(NavigationBarIndex.home, visibility.home, viewModel::setHomeTab, icon = Icons.Outlined.Home) diff --git a/app/src/main/java/io/github/aedev/flow/ui/screens/settings/index/AppearanceIndex.kt b/app/src/main/java/io/github/aedev/flow/ui/screens/settings/index/AppearanceIndex.kt index ffd50f0df0..5b207efc74 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/screens/settings/index/AppearanceIndex.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/screens/settings/index/AppearanceIndex.kt @@ -251,6 +251,46 @@ internal object NavigationBarIndex { section = R.string.settings_section_style, destination = page, ) + val scroll = + SettingEntry( + key = "navigation_bar.scroll", + title = R.string.settings_nav_scroll_title, + summary = R.string.settings_nav_scroll_summary, + keywords = R.string.settings_keywords_nav_style, + section = R.string.settings_section_style, + destination = page, + revealVia = style.key, + ) + val miniBeside = + SettingEntry( + key = "navigation_bar.mini_beside", + title = R.string.settings_nav_mini_beside_title, + summary = R.string.settings_nav_mini_beside_summary, + keywords = R.string.settings_keywords_nav_style, + section = R.string.settings_section_style, + destination = page, + revealVia = style.key, + ) + val scrub = + SettingEntry( + key = "navigation_bar.scrub", + title = R.string.settings_nav_scrub_title, + summary = R.string.settings_nav_scrub_summary, + keywords = R.string.settings_keywords_nav_style, + section = R.string.settings_section_style, + destination = page, + revealVia = style.key, + ) + val iconPop = + SettingEntry( + key = "navigation_bar.icon_pop", + title = R.string.settings_nav_icon_pop_title, + summary = R.string.settings_nav_icon_pop_summary, + keywords = R.string.settings_keywords_nav_style, + section = R.string.settings_section_style, + destination = page, + revealVia = style.key, + ) val showOnOtherPages = SettingEntry( key = "navigation_bar.show_on_other_pages", @@ -269,7 +309,25 @@ internal object NavigationBarIndex { destination = page, ) - val all = listOf(style, labels, home, shorts, music, search, explore, downloads, hideOnScroll, showOnSearch, showOnOtherPages, order) + val all = + listOf( + style, + labels, + scroll, + miniBeside, + scrub, + iconPop, + home, + shorts, + music, + search, + explore, + downloads, + hideOnScroll, + showOnSearch, + showOnOtherPages, + order, + ) } internal object ThemeIndex { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4804fb3ee9..2ed21f42cd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4455,6 +4455,16 @@ Full width, or floating above the page Standard Floating + When you scroll + Hide the bar, or shrink it to the open tab + Hide + Shrink + Mini player beside the bubble + While the bar is shrunk, the mini player moves into its row + Drag to switch tabs + Slide along the floating bar to move between tabs + Icon pop + The tab icon bounces when you open it Apply Custom theme saved Use it diff --git a/app/src/test/java/io/github/aedev/flow/data/local/DevicePreferencesSplitTest.kt b/app/src/test/java/io/github/aedev/flow/data/local/DevicePreferencesSplitTest.kt index 707af1f83b..2c7e3ddd1b 100644 --- a/app/src/test/java/io/github/aedev/flow/data/local/DevicePreferencesSplitTest.kt +++ b/app/src/test/java/io/github/aedev/flow/data/local/DevicePreferencesSplitTest.kt @@ -25,7 +25,7 @@ class DevicePreferencesSplitTest { val device = keyNames("DeviceKeys") assertThat(device).hasSize(128) - assertThat(profile).hasSize(269) + assertThat(profile).hasSize(273) assertThat(device.toSet()).hasSize(device.size) assertThat(profile.toSet()).hasSize(profile.size) assertThat(device.intersect(profile.toSet())).isEmpty() diff --git a/app/src/test/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavGeometryTest.kt b/app/src/test/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavGeometryTest.kt new file mode 100644 index 0000000000..314250d68e --- /dev/null +++ b/app/src/test/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavGeometryTest.kt @@ -0,0 +1,100 @@ +package io.github.aedev.flow.ui.components.layout.navigation + +import com.google.common.truth.Truth.assertThat +import io.github.aedev.flow.data.local.NavBarLabels +import org.junit.Test + +class FloatingNavGeometryTest { + private val metrics = + FloatingNavMetrics( + iconItem = 48f, + icon = 24f, + labelledStart = 16f, + iconLabelGap = 8f, + labelledEnd = 20f, + namedItemMin = 64f, + namedItemPadding = 16f, + plainItem = 56f, + gap = 2f, + belowIndicatorWidth = 56f, + ) + + private fun geometry( + names: List = listOf(40f, 44f, 42f, 34f, 50f), + open: Int = 0, + labels: NavBarLabels = NavBarLabels.SELECTED, + maxWidth: Float = 320f, + collapsed: Boolean = false, + ) = floatingNavGeometry(names, open, labels, maxWidth, collapsed, metrics) + + @Test + fun `the open tab is named beside its icon and the rest stay icon sized`() { + val g = geometry(open = 1) + + assertThat(g.names).isEqualTo(FloatingNavNames.BESIDE_OPEN) + assertThat(g.widths).containsExactly(48f, 16f + 24f + 8f + 44f + 20f, 48f, 48f, 48f).inOrder() + assertThat(g.indicatorStart).isEqualTo(g.starts[1]) + assertThat(g.indicatorEnd).isEqualTo(g.starts[1] + g.widths[1]) + } + + @Test + fun `items are laid out in order with a gap between them`() { + val g = geometry(open = 0) + + assertThat(g.starts[0]).isEqualTo(0f) + assertThat(g.starts[1]).isEqualTo(g.widths[0] + 2f) + assertThat(g.width).isEqualTo(g.widths.sum() + 4 * 2f) + } + + @Test + fun `a name that does not fit drops every name and keeps the indicator on the open tab`() { + val g = geometry(open = 4, maxWidth = 280f) + + assertThat(g.names).isEqualTo(FloatingNavNames.NONE) + assertThat(g.widths.toSet()).containsExactly(48f) + assertThat(g.indicatorStart).isEqualTo(g.starts[4]) + } + + @Test + fun `icons only use the roomier item when it fits`() { + assertThat(geometry(labels = NavBarLabels.NEVER).widths.toSet()).containsExactly(56f) + assertThat(geometry(labels = NavBarLabels.NEVER, maxWidth = 250f).widths.toSet()).containsExactly(48f) + } + + @Test + fun `names under the icons put a fixed width indicator over the open icon`() { + val g = geometry(open = 2, labels = NavBarLabels.ALWAYS, maxWidth = 400f) + + assertThat(g.names).isEqualTo(FloatingNavNames.BELOW) + assertThat(g.widths).containsExactly(64f, 64f, 64f, 64f, 66f).inOrder() + val centre = g.starts[2] + g.widths[2] / 2f + assertThat(g.indicatorStart).isEqualTo(centre - 28f) + assertThat(g.indicatorEnd).isEqualTo(centre + 28f) + } + + @Test + fun `names under the icons share the width when they do not fit`() { + val g = geometry(labels = NavBarLabels.ALWAYS, maxWidth = 300f) + + assertThat(g.widths.toSet()).containsExactly((300f - 8f) / 5f) + } + + @Test + fun `collapsing folds the bar down to the open icon`() { + val g = geometry(open = 3, collapsed = true) + + assertThat(g.widths).containsExactly(0f, 0f, 0f, 48f, 0f).inOrder() + assertThat(g.width).isEqualTo(48f) + assertThat(g.indicatorStart).isEqualTo(g.starts[3]) + } + + @Test + fun `the item at a point is the one whose centre is nearest, skipping folded ones`() { + val g = geometry(open = 0) + + assertThat(g.itemAt(0f)).isEqualTo(0) + assertThat(g.itemAt(g.starts[2] + 10f)).isEqualTo(2) + assertThat(g.itemAt(g.width + 100f)).isEqualTo(4) + assertThat(geometry(open = 3, collapsed = true).itemAt(0f)).isEqualTo(3) + } +} diff --git a/app/src/test/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavLayoutTest.kt b/app/src/test/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavLayoutTest.kt deleted file mode 100644 index d58c4a8206..0000000000 --- a/app/src/test/java/io/github/aedev/flow/ui/components/layout/navigation/FloatingNavLayoutTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.aedev.flow.ui.components.layout.navigation - -import com.google.common.truth.Truth.assertThat -import io.github.aedev.flow.data.local.NavBarLabels -import org.junit.Test - -class FloatingNavLayoutTest { - private fun choose( - slots: Int, - labels: NavBarLabels = NavBarLabels.ALWAYS, - expanding: Int = 300, - pill: Int = 280, - maxWidth: Int = 336, - ) = chooseFloatingNavLayout(slots, labels, maxWidth, { expanding }, { pill }) - - @Test - fun `up to four tabs expand when the open name fits`() { - assertThat(choose(slots = 4)).isEqualTo(FloatingNavLayout.EXPANDING) - assertThat(choose(slots = 2, labels = NavBarLabels.SELECTED)).isEqualTo(FloatingNavLayout.EXPANDING) - } - - @Test - fun `five slots use the pill`() { - assertThat(choose(slots = 5)).isEqualTo(FloatingNavLayout.PILL) - } - - @Test - fun `an expanding bar too wide for the window falls back to the pill`() { - assertThat(choose(slots = 4, expanding = 400)).isEqualTo(FloatingNavLayout.PILL) - } - - @Test - fun `icons only never expands`() { - assertThat(choose(slots = 3, labels = NavBarLabels.NEVER)).isEqualTo(FloatingNavLayout.PILL) - } - - @Test - fun `a pill too wide stretches to the full width`() { - assertThat(choose(slots = 5, pill = 360)).isEqualTo(FloatingNavLayout.WIDE) - } - - @Test - fun `the expanding width is not measured when it can't be used`() { - var measured = false - val expanding = { - measured = true - 0 - } - chooseFloatingNavLayout(5, NavBarLabels.ALWAYS, 336, expanding, { 0 }) - assertThat(measured).isFalse() - } -} diff --git a/app/src/test/java/io/github/aedev/flow/ui/components/videoplayer/motion/ClearDockedBarTest.kt b/app/src/test/java/io/github/aedev/flow/ui/components/videoplayer/motion/ClearDockedBarTest.kt new file mode 100644 index 0000000000..5a214f8e35 --- /dev/null +++ b/app/src/test/java/io/github/aedev/flow/ui/components/videoplayer/motion/ClearDockedBarTest.kt @@ -0,0 +1,27 @@ +package io.github.aedev.flow.ui.components.videoplayer.motion + +import com.google.common.truth.Truth.assertThat +import io.github.aedev.flow.ui.components.videoplayer.MiniPlayerCorner +import org.junit.Test + +class ClearDockedBarTest { + private fun clear( + x: Float, + corner: MiniPlayerCorner, + clearance: Float = 84f, + barOnLeft: Boolean = true, + ) = clearDockedBar(x, corner, width = 160f, screenWidth = 400f, clearance = clearance, barOnLeft = barOnLeft) + + @Test + fun `the bottom corner on the bar's side moves in past the bar`() { + assertThat(clear(8f, MiniPlayerCorner.BottomLeft)).isEqualTo(84f) + assertThat(clear(232f, MiniPlayerCorner.BottomRight, barOnLeft = false)).isEqualTo(400f - 160f - 84f) + } + + @Test + fun `other corners and an undocked bar keep their place`() { + assertThat(clear(232f, MiniPlayerCorner.BottomRight)).isEqualTo(232f) + assertThat(clear(8f, MiniPlayerCorner.TopLeft)).isEqualTo(8f) + assertThat(clear(8f, MiniPlayerCorner.BottomLeft, clearance = 0f)).isEqualTo(8f) + } +}