import React, { useMemo } from 'react'; import { View } from 'react-native'; import type { GestureResponderEvent } from 'react-native'; import AlertButton from './AlertButton'; import styles from './AlertFooter.styles'; import type { AlertButtonT, CreateActionCallback, DefaultTheme } from '../../../types'; interface AlertFooterProps { buttons: AlertButtonT[]; createActionCallback: CreateActionCallback; theme: DefaultTheme; } function splitButtons(buttons: AlertButtonT[]): [AlertButtonT[], AlertButtonT[]] { return buttons.reduce<[AlertButtonT[], AlertButtonT[]]>( ([l, r], button) => (button.secondary ? [[...l, button], r] : [l, [...r, button]]), [[], []], ); } const AlertFooter: React.FC = ({ buttons, createActionCallback, theme }) => { const [left, right] = useMemo(() => splitButtons(buttons), [buttons]); const renderButton = (button: AlertButtonT) => ( {button.text} ); return ( {left.map(renderButton)} {right.map(renderButton)} ); }; export default AlertFooter;