Files
jellyfin-audio-player/src/components/Modal.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { useCallback } from 'react';
import styled, { css } from 'styled-components/native';
import { SafeAreaView, Pressable } from 'react-native';
2020-07-26 14:45:32 +02:00
import { colors } from './Colors';
import { useNavigation, StackActions } from '@react-navigation/native';
2020-06-17 14:58:04 +02:00
interface Props {
fullSize?: boolean;
}
const Background = styled(Pressable)`
2020-06-17 14:58:04 +02:00
padding: 100px 25px;
flex: 1;
justify-content: center;
2020-06-17 14:58:04 +02:00
`;
const Container = styled(Pressable)<Pick<Props, 'fullSize'>>`
2020-06-17 14:58:04 +02:00
border-radius: 20px;
margin: auto 0;
${props => props.fullSize && css`
flex: 1;
`}
2020-06-17 14:58:04 +02:00
`;
const Modal: React.FC<Props> = ({ children, fullSize = true }) => {
const navigation = useNavigation();
const closeModal = useCallback(() => {
navigation.dispatch(StackActions.popToTop());
}, [navigation]);
2020-06-17 14:58:04 +02:00
return (
<Background style={colors.modal} onPress={closeModal}>
2020-07-26 14:45:32 +02:00
<SafeAreaView style={{ flex: 1 }}>
<Container style={colors.view} fullSize={fullSize}>
2020-06-17 14:58:04 +02:00
{children}
</Container>
</SafeAreaView>
</Background>
);
};
export default Modal;