Files
jellyfin-audio-player/src/screens/modals/Player/components/Casting.ios.tsx

60 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-06-19 22:26:41 +02:00
import { Text } from '@/components/Typography';
import { THEME_COLOR } from '@/CONSTANTS';
2022-05-10 23:52:58 +02:00
import React, { useCallback } from 'react';
import { showRoutePicker, useAirplayRoutes } from 'react-airplay';
import { TouchableOpacity } from 'react-native';
import styled, { css } from 'styled-components/native';
2023-06-19 23:03:17 +02:00
import AirplayAudioIcon from '@/assets/icons/airplay-audio.svg';
2023-06-19 22:26:41 +02:00
import useDefaultStyles from '@/components/Colors';
import { t } from '@/localisation';
2021-03-21 22:42:04 +01:00
2022-05-10 23:52:58 +02:00
const Container = styled.View<{ active?: boolean }>`
display: flex;
flex-direction: row;
align-items: center;
flex: 1 1 auto;
${(props) => props.active && css`
padding: 8px;
margin: -8px 0;
border-radius: 8px;
`}
2021-03-21 22:42:04 +01:00
`;
2022-05-10 23:52:58 +02:00
const Label = styled(Text)<{ active?: boolean }>`
margin-left: 8px;
opacity: 0.5;
font-size: 13px;
${(props) => props.active && css`
color: ${THEME_COLOR};
opacity: 1;
`}
`;
function Casting() {
const defaultStyles = useDefaultStyles();
const routes = useAirplayRoutes();
const handleClick = useCallback(() => showRoutePicker({}), []);
2021-03-21 22:42:04 +01:00
return (
2022-05-10 23:52:58 +02:00
<TouchableOpacity onPress={handleClick} activeOpacity={0.6}>
<Container style={routes.length ? defaultStyles.activeBackground : undefined} active={routes.length > 0}>
<AirplayAudioIcon
width={20}
height={20}
fill={routes.length > 0 ? THEME_COLOR : defaultStyles.textHalfOpacity.color}
2021-03-21 22:42:04 +01:00
/>
2022-05-10 23:52:58 +02:00
<Label active={routes.length > 0} numberOfLines={1}>
{routes.length > 0
? `${t('playing-on')} ${routes.map((route) => route.portName).join(', ')}`
: t('local-playback')
2022-05-10 23:52:58 +02:00
}
</Label>
</Container>
</TouchableOpacity>
2021-03-21 22:42:04 +01:00
);
}
export default Casting;