import React from 'react'; import {TouchableOpacity, View, StyleSheet} from 'react-native'; import IconComponent from '../Icon/IconComponent'; import {icons} from '../Icon/Icons'; import {useSwipeableListItemContext} from './SwipeableListItemContext'; import {SwipeableListItemSelected} from './SwipeableListItemSelected'; import {SwipeableListItemUnselected} from './SwipeableListItemUnselected'; interface SwipeableListItemSelectionProps { children?: React.ReactNode; } /** * Selection component for SwipeableListItem * Supports custom Selected/Unselected states or renders default checkbox * Only renders when in selection mode * * @example * ```tsx * // Default checkbox * * * * * // Custom selected/unselected UI * * * * * * * * * * * ``` */ export const SwipeableListItemSelection: React.FC = ({children}) => { const context = useSwipeableListItemContext(); // Don't render if not in selection mode if (!context.isSelection) { return null; } // Extract Selected and Unselected components from children let selectedContent: React.ReactNode = null; let unselectedContent: React.ReactNode = null; if (children) { React.Children.forEach(children, child => { if (!React.isValidElement(child)) return; const childProps = child.props as any; if (child.type === SwipeableListItemSelected) { selectedContent = childProps.children; } else if (child.type === SwipeableListItemUnselected) { unselectedContent = childProps.children; } }); } // If custom content is provided, use it if (selectedContent || unselectedContent) { return ( context.onSelectChange?.(!context.selected)} style={styles.customContainer} accessibilityRole="button" accessibilityLabel={context.selected ? 'Deselect item' : 'Select item'} hitSlop={{top: 10, bottom: 10, left: 10, right: 10}}> {context.selected ? selectedContent : unselectedContent} ); } // Otherwise render default icon checkbox return ( context.onSelectChange?.(!context.selected)} accessibilityRole="button" accessibilityLabel={context.selected ? 'Deselect item' : 'Select item'} hitSlop={{top: 8, bottom: 8, left: 8, right: 8}} style={styles.container}> ); }; const styles = StyleSheet.create({ container: { height: 56, justifyContent: 'center', marginRight: 12.66, }, customContainer: { paddingRight: 12, justifyContent: 'center', alignItems: 'center', }, });