import React from 'react';
import {View, StyleSheet} from 'react-native';
import PlayyText from '../PlayyText/PlayyText';
import {SwipeableListItemContentProps} from './types';
import {useTheme, ColorsScheme} from '../../theme/ThemeContext';
import {GLYPHS} from '../Glyphs';
import {SwipeableListItemTitle} from './SwipeableListItemTitle';
import {SwipeableListItemSubTitle} from './SwipeableListItemSubTitle';
/**
* Content section of SwipeableListItem (name + message preview)
* Can use children for full customization or props for convenience
*
* @example
* ```tsx
* // With children (composable)
*
* John Doe
* Hey, how are you?
*
*
* // With props (legacy convenience)
*
* ```
*/
export const SwipeableListItemContent: React.FC = ({
children,
name,
message,
messageIcon,
messageIconColor,
isTyping,
isDeleted,
}) => {
const {colors} = useTheme();
const styles = themedStyle(colors);
// If custom children provided with Title/SubTitle components, use that
if (children) {
const hasComposableChildren = React.Children.toArray(children).some(child =>
React.isValidElement(child) && (
child.type === SwipeableListItemTitle ||
child.type === SwipeableListItemSubTitle
)
);
if (hasComposableChildren) {
return {children};
}
// Otherwise treat as legacy custom content
return {children};
}
// Legacy prop-based rendering
return (
{/* Name */}
{name && (
{name}
)}
{/* Message preview */}
{isDeleted ? (
{GLYPHS.nosign.char}
This message was deleted.
) : isTyping ? (
{name?.split(' ')[0]} is typing...
) : (
{messageIcon && (
{messageIcon}
)}
{message || ''}
)}
);
};
const themedStyle = (colors: ColorsScheme) =>
StyleSheet.create({
chatContent: {
flex: 1,
justifyContent: 'center',
marginRight: 8,
},
chatName: {
marginBottom: 2,
},
messagePreviewContainer: {
flex: 1,
},
messageWithIconContainer: {
flexDirection: 'row',
alignItems: 'flex-start',
},
messageIconText: {
marginRight: 2,
},
messageText: {
flex: 1,
},
});