2023-08-11 20:39:16 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import Touchable from '../../Touchable';
|
|
|
|
import { CustomIcon } from '../../../CustomIcon';
|
|
|
|
import { useTheme } from '../../../../theme';
|
|
|
|
import styles from './styles';
|
|
|
|
import Loading from './Loading';
|
|
|
|
|
|
|
|
interface IButton {
|
|
|
|
loading: boolean;
|
|
|
|
paused: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
onPress: () => void;
|
|
|
|
cached: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BUTTON_HIT_SLOP = { top: 12, right: 12, bottom: 12, left: 12 };
|
|
|
|
|
2023-08-23 19:03:20 +00:00
|
|
|
type TCustomIconName = 'arrow-down' | 'play-shape-filled' | 'pause-shape-filled';
|
|
|
|
|
2023-08-11 20:39:16 +00:00
|
|
|
const PlayButton = React.memo(({ loading, paused, onPress, disabled, cached }: IButton) => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
|
2023-08-23 19:03:20 +00:00
|
|
|
let customIconName: TCustomIconName = 'arrow-down';
|
2023-08-11 20:39:16 +00:00
|
|
|
if (cached) {
|
|
|
|
customIconName = paused ? 'play-shape-filled' : 'pause-shape-filled';
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Touchable
|
2023-08-23 19:03:20 +00:00
|
|
|
style={[styles.playPauseButton, { backgroundColor: colors.buttonBackgroundPrimaryDefault }]}
|
2023-08-11 20:39:16 +00:00
|
|
|
disabled={disabled}
|
|
|
|
onPress={onPress}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
background={Touchable.SelectableBackgroundBorderless()}
|
|
|
|
>
|
|
|
|
{loading ? (
|
|
|
|
<Loading />
|
|
|
|
) : (
|
2023-08-23 19:03:20 +00:00
|
|
|
<CustomIcon name={customIconName} size={24} color={disabled ? colors.tintDisabled : colors.buttonFontOnPrimary} />
|
2023-08-11 20:39:16 +00:00
|
|
|
)}
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PlayButton;
|