import React from 'react'; import { StyleSheet, View } from 'react-native'; import ShouldRender from '../ShouldRender'; import { ModalProps, TextButtonProps } from './interface'; import TextButton from './TextButton'; import { joinElement } from './utils'; import Button from '../Button'; import { Fill } from '../Button/enum'; import createStyle from './styles/modal-footer.style'; import { useTheme } from '../Theme/Theme'; import { AutoLayout } from '../AutoLayout'; export interface ModalFooterProps extends Pick< ModalProps, | 'showConfirmButton' | 'showCancelButton' | 'actions' | 'solidButton' | 'buttonsDirection' > { confirmButtonProps: TextButtonProps; cancelButtonProps: TextButtonProps; } const ModalFooter: React.FC = ({ showConfirmButton, confirmButtonProps, showCancelButton, cancelButtonProps, actions, solidButton, buttonsDirection, }) => { const defaultButtonProps = [ showCancelButton && cancelButtonProps, showConfirmButton && confirmButtonProps, ].filter(Boolean) as TextButtonProps[]; const token = useTheme(); const styles = createStyle(token); const getFooterStyle = () => { if (solidButton) { return styles.solidButtonFooter; } return !actions ? styles.footerHorizontal : styles.footerVertical; }; return ( {/* 横向文本按钮 */} {joinElement( defaultButtonProps .map(({ style, ...restButtonProps }) => ({ style: StyleSheet.flatten([styles.buttonHorizontal, style]), ...restButtonProps, })) .map((props) => ), )} {/* 多按钮 */} {actions?.map(({ key, text, style, ...buttonProps }, index) => { return !solidButton ? ( ) : ( ); })} {cancelButtonProps.text} ) : null, showConfirmButton ? ( ) : null, ]} direction={buttonsDirection} /> ); }; export default ModalFooter;