import { useNavigation } from '@react-navigation/native' import { useAtomValue } from 'jotai/utils' import React from 'react' import { StatusBar, StyleSheet, Text, View } from 'react-native' import { State } from 'react-native-track-player' import { currentTrackAtom, playerStateAtom, queueNameAtom, useNext, usePause, usePlay, usePrevious, useProgress, } from '../state/trackplayer' import colors from '../styles/colors' import text, { Font } from '../styles/text' import { formatDuration } from '../util' import CoverArt from './common/CoverArt' import ImageGradientBackground from './common/ImageGradientBackground' import PressableImage from './common/PressableImage' const NowPlayingHeader = () => { const queueName = useAtomValue(queueNameAtom) const navigation = useNavigation() return ( navigation.goBack()} source={require('../../res/arrow_left-fill.png')} style={headerStyles.icons} tintColor="white" hitSlop={12} ripple={true} padding={18} /> {queueName || 'Nothing playing...'} {}} source={require('../../res/more_vertical.png')} style={headerStyles.icons} tintColor="white" hitSlop={12} ripple={true} padding={18} /> ) } const headerStyles = StyleSheet.create({ container: { height: 58, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', }, icons: { height: 42, width: 42, marginHorizontal: 8, }, queueName: { ...text.paragraph, }, }) const SongCoverArt = () => { const track = useAtomValue(currentTrackAtom) return ( } height={'100%'} width={'100%'} coverArtUri={track?.artwork as string} /> ) } const coverArtStyles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', padding: 20, }, }) const SongInfo = () => { const track = useAtomValue(currentTrackAtom) return ( {track?.title} {track?.artist} ) } const infoStyles = StyleSheet.create({ container: { width: '100%', alignItems: 'center', paddingHorizontal: 20, }, title: { ...text.songListTitle, fontSize: 22, textAlign: 'center', }, artist: { ...text.songListSubtitle, fontSize: 14, textAlign: 'center', }, }) const SeekBar = () => { const { position, duration } = useProgress() let progress = 0 if (duration > 0) { progress = position / duration } return ( {formatDuration(position)} {formatDuration(duration)} ) } const seekStyles = StyleSheet.create({ container: { width: '100%', marginTop: 26, paddingHorizontal: 20, }, barContainer: { flexDirection: 'row', alignItems: 'center', marginBottom: 6, }, bars: { backgroundColor: colors.text.primary, height: 4, }, barLeft: { marginRight: -6, }, barRight: { opacity: 0.3, marginLeft: -6, }, indicator: { height: 12, width: 12, borderRadius: 6, backgroundColor: colors.text.primary, elevation: 1, }, textContainer: { flexDirection: 'row', justifyContent: 'space-between', }, text: { fontFamily: Font.regular, fontSize: 15, color: colors.text.primary, }, }) const PlayerControls = () => { const state = useAtomValue(playerStateAtom) const play = usePlay() const pause = usePause() const next = useNext() const previous = usePrevious() let playPauseIcon: number let playPauseAction: undefined | (() => void) let disabled: boolean switch (state) { case State.Playing: case State.Buffering: case State.Connecting: disabled = false playPauseIcon = require('../../res/pause_circle-fill.png') playPauseAction = pause break case State.Paused: disabled = false playPauseIcon = require('../../res/play_circle-fill.png') playPauseAction = play break default: disabled = true playPauseIcon = require('../../res/play_circle-fill.png') playPauseAction = undefined break } return ( ) } const controlsStyles = StyleSheet.create({ container: { width: '100%', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', marginBottom: 75, }, skip: { height: 40, width: 40, marginHorizontal: 18, }, play: { height: 90, width: 90, }, }) const NowPlayingLayout = () => { const track = useAtomValue(currentTrackAtom) return ( ) } export default NowPlayingLayout