Hide player bar when queue is empty #4

Merged
joshuafhiggins merged 2 commits from t3code/hide-player-bar-empty-queue into mobile 2026-07-05 22:07:27 -04:00
6 changed files with 71 additions and 9 deletions

No files matched your search

+8 -3
View File
@@ -4,6 +4,7 @@ import { DynamicColorIOS, Platform, useColorScheme } from "react-native"
import { useMemo } from "react"
import { TabBottomAccessory } from "@/components/mini-player"
import { usePlayback } from "@/contexts/playback"
import { appleMusic, colors } from "@/lib/theme"
function useRouterTheme() {
@@ -75,6 +76,8 @@ function useNativeTabColors() {
export default function TabsLayout() {
const routerTheme = useRouterTheme()
const tabColors = useNativeTabColors()
const { currentSong, queueSongIds } = usePlayback()
const showBottomAccessory = Boolean(currentSong && queueSongIds.length > 0)
return (
<ThemeProvider value={routerTheme}>
@@ -90,9 +93,11 @@ export default function TabsLayout() {
tintColor={appleMusic.pink}
minimizeBehavior="onScrollDown"
>
<NativeTabs.BottomAccessory>
<TabBottomAccessory />
</NativeTabs.BottomAccessory>
{showBottomAccessory ? (
<NativeTabs.BottomAccessory>
<TabBottomAccessory />
</NativeTabs.BottomAccessory>
) : null}
<NativeTabs.Trigger name="home" disableTransparentOnScrollEdge>
<NativeTabs.Trigger.Icon sf="house.fill" md="home" />
+15 -2
View File
@@ -1,5 +1,5 @@
import { usePaginatedQuery, useQuery } from "convex/react"
import { Stack } from "expo-router"
import { Stack, useRouter } from "expo-router"
import { FlatList, Pressable, StyleSheet, Text, View } from "react-native"
import { Button, LoadingView } from "@/components/ui/primitives"
@@ -12,6 +12,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
const PAGE_SIZE = 50
export default function QueueScreen() {
const router = useRouter()
const colors = useThemeColors()
const {
queueSongIds,
@@ -42,6 +43,18 @@ export default function QueueScreen() {
void reorderQueue(next)
}
function handleClearQueue() {
if (router.canGoBack()) {
router.back()
setTimeout(() => {
void clearQueue()
}, 0)
return
}
void clearQueue()
}
if (queueSongs === undefined) {
return <LoadingView />
}
@@ -52,7 +65,7 @@ export default function QueueScreen() {
options={{
headerRight: () =>
queueSongIds.length > 0 ? (
<Button title="Clear" variant="ghost" onPress={() => void clearQueue()} />
<Button title="Clear" variant="ghost" onPress={handleClearQueue} />
) : null,
}}
/>
+13
View File
@@ -3,6 +3,7 @@ import Slider from "@react-native-community/slider"
import { BlurView } from "expo-blur"
import { useRouter } from "expo-router"
import * as Haptics from "expo-haptics"
import { useEffect, useRef } from "react"
import {
Platform,
Pressable,
@@ -26,6 +27,7 @@ import { appleMusic, radius, spacing, usePlayerTheme } from "@/lib/theme"
export default function PlayerScreen() {
const router = useRouter()
const hadSongRef = useRef(false)
const { push } = useAppNavigation()
const insets = useSafeAreaInsets()
const player = usePlayerTheme()
@@ -50,6 +52,17 @@ export default function PlayerScreen() {
skipPrevious,
} = usePlayback()
useEffect(() => {
if (currentSong) {
hadSongRef.current = true
return
}
if (hadSongRef.current) {
router.back()
}
}, [currentSong, router])
if (!currentSong || !config) {
return null
}
+16
View File
@@ -236,7 +236,15 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
autoPlayNextRef.current = true
isPlayingRef.current = true
setIsPlayingState(true)
return
}
autoPlayNextRef.current = false
isPlayingRef.current = false
void playerRef.current?.seekTo(0)
currentTimeRef.current = 0
setCurrentTime(0)
setIsPlayingState(false)
})
.catch(() => {
autoPlayNextRef.current = false
@@ -655,7 +663,15 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
await skipToQueueIndexMutation({ index })
},
skipNext: async () => {
const isFinishingQueue = repeatEnabled === "none" && queueLength <= 1
if (isFinishingQueue) {
setIsPlaying(false)
await seekTo(0)
}
await skipNextMutation()
if (isFinishingQueue) {
await seekTo(0)
}
},
skipPrevious: async () => {
if (currentTime > PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS) {
+16
View File
@@ -790,7 +790,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
autoPlayNextRef.current = true
isPlayingRef.current = true
setIsPlaying(true)
return
}
autoPlayNextRef.current = false
isPlayingRef.current = false
audio.currentTime = 0
setCurrentTime(0)
setIsPlaying(false)
})
.catch(() => {
autoPlayNextRef.current = false
@@ -1066,7 +1073,16 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
await skipToQueueIndexMutation({ index })
},
skipNext: async () => {
const isFinishingQueue =
repeatEnabled === "none" && queueSongIds.length <= 1
if (isFinishingQueue) {
setIsPlaying(false)
seekTo(0)
}
await skipNextMutation()
if (isFinishingQueue) {
seekTo(0)
}
},
skipPrevious: async () => {
if (currentTime > PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS) {
+3 -4
View File
@@ -511,17 +511,16 @@ export const skipNext = mutation({
return
}
const history = appendToQueueHistory(user.queueHistory ?? [], current)
if (rest.length === 0) {
await ctx.db.patch(userId, {
songQueue: [],
queueHistory: history,
songQueue: [current],
currentSongProgress: 0,
})
return
}
const history = appendToQueueHistory(user.queueHistory ?? [], current)
await ctx.db.patch(userId, {
songQueue: rest,
queueHistory: history,