import React, { useCallback } from 'react'; import { Text, ScrollView, Dimensions, RefreshControl, StyleSheet, View } from 'react-native'; import { useGetImage } from 'utility/JellyfinApi'; import styled, { css } from 'styled-components/native'; import { useNavigation } from '@react-navigation/native'; import FastImage from 'react-native-fast-image'; import { useTypedSelector } from 'store'; import { THEME_COLOR } from 'CONSTANTS'; import TouchableHandler from 'components/TouchableHandler'; import useCurrentTrack from 'utility/useCurrentTrack'; import TrackPlayer from 'react-native-track-player'; import Play from 'assets/play.svg'; import Shuffle from 'assets/shuffle.svg'; import useDefaultStyles from 'components/Colors'; import usePlayTracks from 'utility/usePlayTracks'; import { EntityId } from '@reduxjs/toolkit'; import { WrappableButtonRow, WrappableButton } from 'components/WrappableButtonRow'; const Screen = Dimensions.get('screen'); const styles = StyleSheet.create({ name: { fontSize: 36, fontWeight: 'bold' }, artist: { fontSize: 24, opacity: 0.5, marginBottom: 12 }, index: { width: 20, opacity: 0.5, marginRight: 5 } }); const AlbumImage = styled(FastImage)` border-radius: 10px; width: ${Screen.width * 0.6}px; height: ${Screen.width * 0.6}px; margin: 10px auto; `; const TrackContainer = styled.View<{isPlaying: boolean}>` padding: 15px; border-bottom-width: 1px; flex-direction: row; ${props => props.isPlaying && css` background-color: ${THEME_COLOR}16; margin: 0 -20px; padding: 15px 35px; `} `; interface TrackListViewProps { title?: string; artist?: string; trackIds: EntityId[]; entityId: string; refresh: () => void; playButtonText: string; shuffleButtonText: string; listNumberingStyle?: 'album' | 'index'; } const TrackListView: React.FC = ({ trackIds, entityId, title, artist, refresh, playButtonText, shuffleButtonText, listNumberingStyle = 'album', }) => { const defaultStyles = useDefaultStyles(); // Retrieve state const tracks = useTypedSelector((state) => state.music.tracks.entities); const isLoading = useTypedSelector((state) => state.music.tracks.isLoading); // Retrieve helpers const getImage = useGetImage(); const playTracks = usePlayTracks(); const { track: currentTrack } = useCurrentTrack(); const navigation = useNavigation(); // Setup callbacks const playEntity = useCallback(() => { playTracks(trackIds); }, [playTracks, trackIds]); const shuffleEntity = useCallback(() => { playTracks(trackIds, true, true); }, [playTracks, trackIds]); const selectTrack = useCallback(async (index: number) => { await playTracks(trackIds, false); await TrackPlayer.skip(index); await TrackPlayer.play(); }, [playTracks, trackIds]); const longPressTrack = useCallback((index: number) => { navigation.navigate('TrackPopupMenu', { trackId: trackIds[index] }); }, [navigation, trackIds]); return ( } > {title} {artist} {trackIds.map((trackId, i) => {listNumberingStyle === 'index' ? i + 1 : tracks[trackId]?.IndexNumber} {tracks[trackId]?.Name} )} ); }; export default TrackListView;