11import React , { memo } from 'react' ;
2- import { View , StyleSheet } from 'react-native' ;
2+ import {
3+ View ,
4+ StyleSheet ,
5+ TouchableOpacity ,
6+ Text ,
7+ Platform ,
8+ } from 'react-native' ;
39import MarkdownComponent from './MarkdownComponent' ;
410import LlamaIcon from '../../assets/icons/llama_icon.svg' ;
5- import { MessageType } from 'react-native-executorch/lib/typescript/types/llm' ;
611import ColorPalette from '../colors' ;
12+ import { MessageType } from 'react-native-executorch/lib/typescript/types/llm' ;
713
814interface MessageItemProps {
915 message : MessageType ;
16+ deleteMessage : ( ) => void ;
1017}
1118
12- const MessageItem = memo ( ( { message } : MessageItemProps ) => {
19+ const MessageItem = memo ( ( { message, deleteMessage } : MessageItemProps ) => {
1320 return (
1421 < View
1522 style = {
@@ -22,28 +29,52 @@ const MessageItem = memo(({ message }: MessageItemProps) => {
2229 </ View >
2330 ) }
2431 < MarkdownComponent text = { message . content } />
32+ < CloseButton deleteMessage = { deleteMessage } role = { message . role } />
2533 </ View >
2634 ) ;
2735} ) ;
2836
37+ const CloseButton = ( {
38+ deleteMessage,
39+ role,
40+ } : {
41+ deleteMessage : ( ) => void ;
42+ role : string ;
43+ } ) => {
44+ return (
45+ < TouchableOpacity
46+ style = { [
47+ styles . closeButton ,
48+ role === 'assistant' ? styles . closeButtonRight : styles . closeButtonLeft ,
49+ ] }
50+ onPress = { deleteMessage }
51+ >
52+ < Text style = { styles . buttonText } > ✕</ Text >
53+ </ TouchableOpacity >
54+ ) ;
55+ } ;
56+
2957export default MessageItem ;
3058
3159const styles = StyleSheet . create ( {
3260 aiMessage : {
3361 flexDirection : 'row' ,
34- maxWidth : '80 %' ,
62+ maxWidth : '75 %' ,
3563 alignSelf : 'flex-start' ,
3664 marginVertical : 8 ,
65+ alignItems : 'center' ,
3766 } ,
3867 userMessage : {
68+ flexDirection : 'row-reverse' ,
3969 paddingHorizontal : 12 ,
4070 paddingVertical : 8 ,
4171 marginRight : 8 ,
4272 marginVertical : 8 ,
43- maxWidth : 220 ,
73+ maxWidth : '75%' ,
4474 borderRadius : 8 ,
4575 backgroundColor : ColorPalette . seaBlueLight ,
4676 alignSelf : 'flex-end' ,
77+ alignItems : 'center' ,
4778 } ,
4879 aiMessageIconContainer : {
4980 backgroundColor : ColorPalette . seaBlueLight ,
@@ -54,10 +85,22 @@ const styles = StyleSheet.create({
5485 borderRadius : 16 ,
5586 marginHorizontal : 7 ,
5687 } ,
57- messageText : {
58- fontSize : 14 ,
59- lineHeight : 19.6 ,
60- color : ColorPalette . primary ,
61- fontFamily : 'regular' ,
88+ closeButton : {
89+ borderRadius : 11 ,
90+ backgroundColor : ColorPalette . blueLight ,
91+ alignItems : 'center' ,
92+ justifyContent : 'center' ,
93+ width : 22 ,
94+ height : 22 ,
95+ } ,
96+ closeButtonRight : {
97+ marginLeft : 8 ,
98+ } ,
99+ closeButtonLeft : {
100+ marginRight : 8 ,
101+ } ,
102+ buttonText : {
103+ fontSize : Platform . OS === 'ios' ? 16 : 14 ,
104+ color : '#000' ,
62105 } ,
63106} ) ;
0 commit comments