@@ -17,22 +17,29 @@ import {
17
17
type ComposerProps ,
18
18
GiftedChat ,
19
19
type GiftedChatProps ,
20
+ Bubble ,
20
21
} from 'react-native-gifted-chat' ;
21
22
import TypingIndicator from 'react-native-gifted-chat/lib/TypingIndicator' ;
22
23
import { FirestoreServices } from '../services/firebase' ;
23
24
import { useChatContext , useChatSelector } from '../hooks' ;
25
+
26
+ import { formatMessageData } from '../utilities' ;
27
+ import { getConversation } from '../reducer/selectors' ;
28
+ import InputToolbar , { IInputToolbar } from './components/InputToolbar' ;
29
+ import { CameraView , CameraViewRef } from '../chat_obs/components/CameraView' ;
30
+ import SelectedBubbleModal from './components/SelectedBubbleModal' ;
31
+ import FileAttachmentModal , {
32
+ FileAttachmentModalRef ,
33
+ } from './components/FileAttachmentModal' ;
24
34
import type {
25
35
ConversationProps ,
26
36
CustomConversationInfo ,
27
37
IUserInfo ,
28
38
MessageProps ,
29
39
} from '../interfaces' ;
30
- import { formatMessageData } from '../utilities' ;
31
- import { getConversation } from '../reducer/selectors' ;
32
- import InputToolbar , { IInputToolbar } from './components/InputToolbar' ;
33
- import { CameraView , CameraViewRef } from '../chat_obs/components/CameraView' ;
34
- import SelectedImageModal from './components/SelectedImage' ;
35
40
import { useCameraPermission } from 'react-native-vision-camera' ;
41
+ import type { CustomImageVideoBubbleProps } from './components/bubble/CustomImageVideoBubble' ;
42
+ import { CustomBubble } from './components/bubble' ;
36
43
37
44
interface ChatScreenProps extends GiftedChatProps {
38
45
style ?: StyleProp < ViewStyle > ;
@@ -46,6 +53,7 @@ interface ChatScreenProps extends GiftedChatProps {
46
53
hasGallery ?: boolean ;
47
54
onPressCamera ?: ( ) => void ;
48
55
customConversationInfo ?: CustomConversationInfo ;
56
+ customImageVideoBubbleProps : CustomImageVideoBubbleProps ;
49
57
}
50
58
51
59
export const ChatScreen : React . FC < ChatScreenProps > = ( {
@@ -58,6 +66,7 @@ export const ChatScreen: React.FC<ChatScreenProps> = ({
58
66
renderComposer,
59
67
inputToolbarProps,
60
68
customConversationInfo,
69
+ customImageVideoBubbleProps,
61
70
...props
62
71
} ) => {
63
72
const { userInfo } = useChatContext ( ) ;
@@ -70,10 +79,15 @@ export const ChatScreen: React.FC<ChatScreenProps> = ({
70
79
const firebaseInstance = useRef ( FirestoreServices . getInstance ( ) ) . current ;
71
80
const [ messagesList , setMessagesList ] = useState < MessageProps [ ] > ( [ ] ) ;
72
81
const [ hasMoreMessages , setHasMoreMessages ] = useState ( false ) ;
82
+
73
83
const isLoadingRef = useRef ( false ) ;
74
84
const cameraViewRef = useRef < CameraViewRef > ( null ) ;
75
- const [ isImgVideoUrl , setImgVideoUrl ] = useState ( '' ) ;
85
+ const fileAttachmentRef = useRef < FileAttachmentModalRef > ( null ) ;
86
+
76
87
const { hasPermission, requestPermission } = useCameraPermission ( ) ;
88
+ const [ selectedMessage , setSelectedMessage ] = useState < MessageProps | null > (
89
+ null
90
+ ) ;
77
91
78
92
const conversationRef = useRef < ConversationProps | undefined > (
79
93
conversationInfo
@@ -205,6 +219,7 @@ export const ChatScreen: React.FC<ChatScreenProps> = ({
205
219
hasCamera = { props . hasCamera }
206
220
hasGallery = { props . hasGallery }
207
221
{ ...inputToolbarProps }
222
+ documentRef = { fileAttachmentRef . current }
208
223
/>
209
224
) ;
210
225
} ,
@@ -218,6 +233,18 @@ export const ChatScreen: React.FC<ChatScreenProps> = ({
218
233
]
219
234
) ;
220
235
236
+ const renderBubble = ( bubble : Bubble < MessageProps > [ 'props' ] ) => {
237
+ if ( props . renderBubble ) return props . renderBubble ( bubble ) ;
238
+ return (
239
+ < CustomBubble
240
+ bubbleMessage = { bubble }
241
+ onSelectedMessage = { setSelectedMessage }
242
+ customImageVideoBubbleProps = { customImageVideoBubbleProps }
243
+ position = { bubble . position }
244
+ />
245
+ ) ;
246
+ } ;
247
+
221
248
return (
222
249
< View style = { [ styles . container , style ] } >
223
250
< KeyboardAvoidingView style = { styles . container } >
@@ -234,14 +261,20 @@ export const ChatScreen: React.FC<ChatScreenProps> = ({
234
261
renderChatFooter = { ( ) => < TypingIndicator /> }
235
262
onLoadEarlier = { onLoadEarlier }
236
263
renderComposer = { inputToolbar }
264
+ renderBubble = { renderBubble }
237
265
{ ...props }
238
266
/>
239
267
</ KeyboardAvoidingView >
240
- < SelectedImageModal
241
- imageUrl = { isImgVideoUrl }
242
- onClose = { ( ) => setImgVideoUrl ( '' ) }
268
+ < SelectedBubbleModal
269
+ message = { selectedMessage }
270
+ onClose = { ( ) => setSelectedMessage ( null ) }
243
271
/>
244
272
< CameraView onSend = { onSend } userInfo = { userInfo } ref = { cameraViewRef } />
273
+ < FileAttachmentModal
274
+ userInfo = { userInfo }
275
+ ref = { fileAttachmentRef }
276
+ onSend = { onSend }
277
+ />
245
278
</ View >
246
279
) ;
247
280
} ;
0 commit comments