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

59 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-05-10 23:52:58 +02:00
import { Text } from 'components/Typography';
2021-03-21 22:42:04 +01:00
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';
import AirplayAudioIcon from 'assets/icons/airplay-audio.svg';
import useDefaultStyles from 'components/Colors';
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
? `Playing on ${routes.map((route) => route.portName).join(', ')}`
: 'Local Playback'
}
</Label>
</Container>
</TouchableOpacity>
2021-03-21 22:42:04 +01:00
);
}
export default Casting;