Files
jellyfin-audio-player/src/components/TouchableHandler.tsx
Lei Nelissen c88158cf16 (1) Play whole album when selecting a single track
(2) Create popup window on track long-press in which the track can be added to the end or front of the queue
(3) Add Redux counter for added tracks so that the queue is properly updated
2020-08-28 16:28:49 +02:00

42 lines
1.1 KiB
TypeScript

import React, { useCallback } from 'react';
import { Pressable, ViewStyle } from 'react-native';
interface TouchableHandlerProps {
id: string;
onPress: (id: string) => void;
onLongPress?: (id: string) => void;
}
function TouchableStyles({ pressed }: { pressed: boolean }): ViewStyle {
if (pressed) {
return { opacity: 0.5 };
} else {
return { opacity: 1 };
}
}
/**
* This is a generic handler that accepts id as a prop, and return it when it is
* pressed. This comes in handy with lists in which albums / tracks need to be selected.
*/
const TouchableHandler: React.FC<TouchableHandlerProps> = ({ id, onPress, onLongPress, children }) => {
const handlePress = useCallback(() => {
return onPress(id);
}, [id, onPress]);
const handleLongPress = useCallback(() => {
return onLongPress ? onLongPress(id) : undefined;
}, [id, onLongPress]);
return (
<Pressable
onPress={handlePress}
onLongPress={handleLongPress}
style={TouchableStyles}
>
{children}
</Pressable>
);
};
export default TouchableHandler;