import React from 'react'; import { StyleProp, Text, TextStyle, View } from 'react-native'; import Swipeout, { SwipeoutButtonProperties, SwipeoutProperties } from 'react-native-swipeout'; export interface SwipeActionProps extends SwipeoutProperties { left?: SwipeoutButtonProps[]; right?: SwipeoutButtonProps[]; } export interface SwipeoutButtonProps extends SwipeoutButtonProperties { style?: StyleProp & { backgroundColor: string }; } class SwipeAction extends React.Component { static defaultProps: SwipeActionProps = { autoClose: false, disabled: false, onOpen() {}, onClose() {}, }; renderCustomButton(button: SwipeoutButtonProps) { const buttonStyle = button.style; const bgColor = buttonStyle ? buttonStyle.backgroundColor : 'transparent'; const Component = ( {React.isValidElement(button.text) ? ( button.text ) : ( {button.text} )} ); return { text: button.text || 'Click', onPress: button.onPress, type: 'default', component: Component, backgroundColor: 'transparent', color: '#999', disabled: false, }; } render() { const { disabled, autoClose, style, left, right, onOpen, onClose, children, ...restProps } = this.props; const customLeft = left && left.map(btn => { return this.renderCustomButton(btn); }); const customRight = right && right.map(btn => { return this.renderCustomButton(btn); }); return customLeft || customRight ? ( {children} ) : ( {children} ); } } export default SwipeAction;