import * as React from 'react'; import { Dialog, Divider, Surface, Text } from 'react-native-paper'; import { DialogType, ButtonDialogData } from './types'; import { StyleSheet, ViewStyle } from 'react-native'; import { useMemo } from 'react'; import PromptButton from './PromptButton'; import { themeStyle } from '../global-style'; interface Props { dialog: ButtonDialogData; containerStyle: ViewStyle; themeId: number; } const useStyles = (themeId: number, isMenu: boolean) => { return useMemo(() => { const theme = themeStyle(themeId); return StyleSheet.create({ dialogContent: { paddingBottom: theme.margin, paddingHorizontal: theme.margin, }, dialogActions: { paddingBottom: theme.margin, paddingHorizontal: theme.margin, paddingTop: isMenu ? 4 : theme.marginSmall, ...(isMenu ? { flexDirection: 'column', alignItems: 'stretch', gap: 1, } : { gap: theme.marginMedium, flexWrap: 'wrap', }), }, dialogLabel: isMenu ? { textAlign: 'center', } : {}, dialogTitle: isMenu ? {} : { fontWeight: 'bold', marginBottom: theme.margin, }, }); }, [isMenu, themeId]); }; const PromptDialog: React.FC = ({ dialog, containerStyle, themeId }) => { const isMenu = dialog.type === DialogType.Menu; const styles = useStyles(themeId, isMenu); const buttons = dialog.buttons.map((button, index) => { return ; }); const titleComponent = {dialog.title}; return ( {dialog.title ? titleComponent : null} {dialog.message} {isMenu ? : null} {buttons} ); }; export default PromptDialog;