mirror of
https://github.com/Jellify-Music/App.git
synced 2026-01-05 18:40:01 -06:00
Adds Google Cast Speaker Support! A new button is now present in the bottom left of the player screen. Pressing this button will prompt the user to pick a Cast enabled speaker. Once a speaker is selected, the player controls in Jellify will control the playback of the Cast speaker.
85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import React, { useCallback, useMemo, useState } from 'react'
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
import { YStack, useTheme, ZStack, useWindowDimensions, View, getTokenValue } from 'tamagui'
|
|
import Scrubber from './components/scrubber'
|
|
import Controls from './components/controls'
|
|
import Toast from 'react-native-toast-message'
|
|
import JellifyToastConfig from '../../constants/toast.config'
|
|
import { useFocusEffect } from '@react-navigation/native'
|
|
import Footer from './components/footer'
|
|
import BlurredBackground from './components/blurred-background'
|
|
import PlayerHeader from './components/header'
|
|
import SongInfo from './components/song-info'
|
|
import { usePerformanceMonitor } from '../../hooks/use-performance-monitor'
|
|
import { Platform } from 'react-native'
|
|
import { useNowPlaying } from '../../providers/Player/hooks/queries'
|
|
|
|
export default function PlayerScreen(): React.JSX.Element {
|
|
const performanceMetrics = usePerformanceMonitor('PlayerScreen', 5)
|
|
|
|
const [showToast, setShowToast] = useState(true)
|
|
|
|
const { data: nowPlaying } = useNowPlaying()
|
|
|
|
const theme = useTheme()
|
|
|
|
useFocusEffect(
|
|
useCallback(() => {
|
|
setShowToast(true)
|
|
return () => setShowToast(false)
|
|
}, []),
|
|
)
|
|
|
|
const isAndroid = Platform.OS === 'android'
|
|
|
|
const { width, height } = useWindowDimensions()
|
|
|
|
const { top, bottom } = useSafeAreaInsets()
|
|
|
|
/**
|
|
* Styling for the top layer of Player ZStack
|
|
*
|
|
* Android Modals extend into the safe area, so we
|
|
* need to account for that
|
|
*
|
|
* Apple devices get a small amount of margin
|
|
*/
|
|
const mainContainerStyle = useMemo(
|
|
() => ({
|
|
marginTop: isAndroid ? top : getTokenValue('$4'),
|
|
marginBottom: bottom * 2,
|
|
}),
|
|
[top, bottom, isAndroid],
|
|
)
|
|
|
|
return (
|
|
<View flex={1}>
|
|
{nowPlaying && (
|
|
<ZStack fullscreen>
|
|
<BlurredBackground width={width} height={height} />
|
|
|
|
<YStack
|
|
justifyContent='center'
|
|
flex={1}
|
|
marginHorizontal={'$5'}
|
|
{...mainContainerStyle}
|
|
>
|
|
{/* flexGrow 1 */}
|
|
<PlayerHeader />
|
|
|
|
<YStack justifyContent='flex-start' gap={'$4'} flexShrink={1}>
|
|
<SongInfo />
|
|
|
|
<Scrubber />
|
|
{/* playback progress goes here */}
|
|
<Controls />
|
|
<Footer />
|
|
</YStack>
|
|
</YStack>
|
|
</ZStack>
|
|
)}
|
|
{showToast && <Toast config={JellifyToastConfig(theme)} />}
|
|
</View>
|
|
)
|
|
}
|