Contextually disable previous and next buttons

This commit is contained in:
Lei Nelissen
2022-01-01 14:10:56 +01:00
parent 93c9ba7498
commit 9b41a0e62f
2 changed files with 22 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import { useCallback, useEffect, useState } from 'react';
import TrackPlayer, { Event, Track, useTrackPlayerEvents } from 'react-native-track-player';
import { useOnTrackAdded } from './AddedTrackEvents';
import useCurrentTrack from './useCurrentTrack';
/**
* This hook retrieves the current playing track from TrackPlayer
@@ -24,7 +25,19 @@ export default function useQueue(): Track[] {
/**
* Shorthand helper to determine whether a queue exists
*/
export function useHasQueue(): boolean {
export function useHasNextQueue(): boolean {
const { index } = useCurrentTrack();
const queue = useQueue();
return !!queue && queue.length > 1;
return queue?.length > 1 && (index || 0) < (queue.length - 1);
}
/**
* Shorthand helper to determine whether a queue exists
*/
export function useHasPreviousQueue(): boolean {
const { index } = useCurrentTrack();
const queue = useQueue();
return queue?.length > 1 && (index || 0) > 0;
}