import React, { ComponentType } from 'react'; import { View, TouchableOpacity, StyleSheet, Text, ViewStyle, StyleProp, TextStyle } from 'react-native'; import { useTheme } from './ThemeContext'; type WrapperProps = { readonly onPress?: () => void; readonly style?: StyleProp; readonly children: React.ReactNode; }; const Wrapper: ComponentType = ({ onPress, style, children }: WrapperProps) => { if (onPress === undefined) { return {children}; } return ( {children} ); }; export type Props = { readonly title?: string; readonly titleElement?: React.ReactElement; readonly subtitle?: string; readonly subtitleElement?: React.ReactElement; readonly onPress?: () => void; readonly leftElement?: React.ReactElement; readonly rightElement?: React.ReactElement; readonly wrapperStyle?: StyleProp; readonly titleStyle?: StyleProp; readonly subtitleStyle?: StyleProp; readonly testID?: string; }; const emptyStyle = {}; type TitleComponentProps = { titleElement?: React.ReactElement; title?: string; titleStyle?: StyleProp; }; const TitleComponent: ComponentType | null = ({ titleElement, title, titleStyle, }: TitleComponentProps) => { const theme = useTheme(); if (titleElement === undefined && title !== undefined) { return ( {title} ); } if (titleElement !== undefined) { return titleElement; } return null; }; type SubTitleComponentProps = { subtitleElement?: React.ReactElement; subtitle?: string; subtitleStyle?: StyleProp; }; const SubTitleComponent: ComponentType | null = ({ subtitleElement, subtitle, subtitleStyle, }: SubTitleComponentProps) => { const theme = useTheme(); if (subtitleElement === undefined && subtitle !== undefined) { return ( {subtitle} ); } else if (subtitleElement !== undefined) { return subtitleElement; } return null; }; const ListItem: ComponentType = ({ title, titleElement, subtitle, subtitleElement, onPress, leftElement, rightElement, wrapperStyle, titleStyle, subtitleStyle, testID, }: Props) => { const theme = useTheme(); return ( {leftElement !== undefined ? leftElement : null} {rightElement !== undefined ? rightElement : null} ); }; export default ListItem;