import React from 'react'; import { View, Pressable, ViewStyle } from 'react-native'; import Popup from '../popup'; import Icon from '../icon'; import Node from '../node'; import SafeFilling from '../safe-filling'; import Theme from '../style/theme'; import styles from './style'; const prefixCls = 'action-sheet'; export interface ActionSheetActionGridProps { value?: string | number; name?: React.ReactNode; icon?: string; disabled?: boolean; } export interface ActionSheetActionDefaultProps { value?: string | number; text?: React.ReactNode | ActionSheetActionGridProps[]; type?: string; mode?: string; disabled?: boolean; } export type ActionSheetAction = ActionSheetActionDefaultProps | ActionSheetActionGridProps; export interface ActionSheetProps { open?: boolean; title?: React.ReactNode; actions?: ActionSheetActionDefaultProps[]; cancelText?: React.ReactNode; cover?: boolean; children?: React.ReactNode; maskClosable?: boolean; itemStyle?: ViewStyle; itemTextStyle?: ViewStyle; onCancel?: (e?: any) => void; onChange?: (a: ActionSheetAction, g?: ActionSheetActionDefaultProps, e?: any) => void; } const ActionSheet: React.FC = props => { const { open, title, actions, cancelText = 'Cancel', cover, maskClosable = true, onCancel, onChange, } = props; const handleCancel = (e: any) => { onCancel?.(e); }; const handleChange = ( action: ActionSheetAction, grid?: ActionSheetActionDefaultProps, e?: any, ) => { onChange?.(action, grid, e); }; const handleCloseMask = () => { maskClosable && onCancel?.(); }; const renderAction = (action: ActionSheetActionDefaultProps, isLast: boolean) => ( handleChange(action, undefined, e)}> {/* Why you have the padding-bottom?? */} {action?.text} ); const renderGrid = (action: ActionSheetActionDefaultProps) => ( {(action.text as ActionSheetActionGridProps[])?.map((item: ActionSheetActionGridProps) => ( handleChange(item, action, e)} > {item.icon ? ( ) : ( item.name )} {item.name} ))} ); return ( {title ? ( {title} ) : null} {actions?.map((action, index) => action.mode === 'grid' ? renderGrid(action) : renderAction(action, index === actions.length - 1), )} {cancelText} ); }; export default ActionSheet;