Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-16-feat-floating-nav-glide.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -1698,8 +1702,66 @@ class PlayerPreferences(
}
}

// Dragging along the floating bar moves between tabs.
val bottomNavScrub: Flow<Boolean> =
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<Boolean> =
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<NavBarScroll> =
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<Boolean> =
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<NavBarLook> =
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<Boolean> =
Expand Down Expand Up @@ -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,
Expand Down
74 changes: 15 additions & 59 deletions app/src/main/java/io/github/aedev/flow/ui/FlowApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
133 changes: 133 additions & 0 deletions app/src/main/java/io/github/aedev/flow/ui/FlowBottomChrome.kt
Original file line number Diff line number Diff line change
@@ -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)
}
Loading
Loading