import * as React from "react"; import { StyleProp, StyleSheet, TextStyle, ViewStyle, } from "react-native"; import AlertDialog, { Props as BottomSheetProps} from "./AlertDialog"; import Surface from "../Surface"; import { DialogTitle, DialogContent, DialogActions } from "../Dialog"; import Button from "../Button"; import { ThemeContext } from "styled-components"; import Text from "../Text"; type RefProps = { close: () => void, } type TranslationProps = { cancelText: string, confirmText: string, } type Props = Omit & { innerRef: React.RefObject, mode?: "message" | "confirm" | "error", title?: string, message?: string, translations?: TranslationProps, dialogContentStyle?: StyleProp, messageStyle?: StyleProp, }; const defaultProps = { mode: "message", translations: { confirmText: "Ok", cancelText: "Cancel", }, }; const AlertDialogWithRef = ({ innerRef, children, mode, title, message, translations, dialogContentStyle, messageStyle, ...rest }: Props) => { const [ visible, setVisible ] = React.useState(false); const optionsRef = React.useRef({} as any); const { colors } = React.useContext(ThemeContext); React.useImperativeHandle(innerRef, () => ({ open: (options) => { optionsRef.current = { onConfirm: options?.onConfirm, onCancel: options?.onCancel, }; setVisible(true); }, close: () => { setVisible(false); }, })); const _handleConfirm = () => { if (optionsRef && optionsRef.current && optionsRef.current.onConfirm) { optionsRef.current.onConfirm(); } innerRef.current.close(); }; const _handleDismiss = () => { innerRef.current.close(); }; return ( {title ? {title} : null } {message ? {message} : children } {mode === "confirm" ? : null } ); }; AlertDialogWithRef.defaultProps = defaultProps; export default AlertDialogWithRef; const styles = StyleSheet.create({ dialogContentStyle: { paddingHorizontal: 16, }, errorMessage: { }, });