@@ -15,8 +15,6 @@ import {
1515 FlatList ,
1616 NativeScrollEvent ,
1717 StyleProp ,
18- TouchableOpacity ,
19- View ,
2018 ViewStyle ,
2119} from 'react-native' ;
2220import type { IMessage } from 'react-native-gifted-chat' ;
@@ -25,6 +23,7 @@ import { appendSnapshot } from './utils/appendSnapshot';
2523import { prepareSnapshot } from './utils/prepareSnapshot' ;
2624import { isCloseToBottom } from './utils/isCloseToBottom' ;
2725import { isCloseToTop } from './utils/isCloseToTop' ;
26+ import { ChatFooter } from './components/ChatFooter/ChatFooter' ;
2827
2928interface CustomCuteChatProps {
3029 chatId : string ;
@@ -60,6 +59,8 @@ export function CuteChat(props: CuteChatProps) {
6059 const memoizedUser = useMemo ( ( ) => ( { _id : user . id , ...user } ) , [ user ] ) ;
6160 const startDate = useMemo ( ( ) => new Date ( ) , [ ] ) ;
6261
62+ const chatRef = useRef < FlatList < IMessage > > ( null ) ;
63+
6364 const setIsLoadingBool = useCallback (
6465 ( isLoading : boolean ) => {
6566 setIsLoading ?.( isLoading ) ;
@@ -296,12 +297,6 @@ export function CuteChat(props: CuteChatProps) {
296297
297298 console . log ( 'Close to top:' , closeToTop ) ;
298299
299- const chatRef = useRef < FlatList < IMessage > > ( null ) ;
300-
301- const scrollToBottom = ( ) => {
302- chatRef . current ?. scrollToOffset ( { offset : 0 , animated : true } ) ;
303- } ;
304-
305300 return (
306301 < GiftedChat
307302 { ...props }
@@ -310,55 +305,14 @@ export function CuteChat(props: CuteChatProps) {
310305 // - New messages banner
311306 renderChatFooter = { ( ) => (
312307 < >
313- < View
314- style = { {
315- display : 'flex' ,
316- position : 'absolute' ,
317- flexDirection : 'row' ,
318- justifyContent : 'flex-start' ,
319- backgroundColor : 'rgba(255, 255, 255, 0.8)' ,
320- width : '100%' ,
321- height : 100 ,
322- bottom : 0 ,
323- left : 0 ,
324- } }
325- >
326- < View style = { { display : 'flex' , flex : 1 } } > </ View >
327- < View style = { { display : 'flex' , flex : 1 } } >
328- { ! closeToTop && props . newMessagesBannerComponent && (
329- < TouchableOpacity
330- onPress = { scrollToBottom }
331- style = {
332- props . newMessagesBannerStyles ?? {
333- alignSelf : 'center' ,
334- backgroundColor : 'rgba(255, 255, 255, 0.8)' ,
335- padding : 10 ,
336- borderRadius : 100 ,
337- }
338- }
339- >
340- { props . newMessagesBannerComponent ( ) }
341- </ TouchableOpacity >
342- ) }
343- </ View >
344- < View style = { { display : 'flex' , flex : 1 } } >
345- { ! closeToTop && props . scrollToBottomComponent && (
346- < TouchableOpacity
347- onPress = { scrollToBottom }
348- style = {
349- props . scrollToBottomStyle ?? {
350- alignSelf : 'flex-end' ,
351- backgroundColor : 'rgba(255, 255, 255, 0.8)' ,
352- padding : 10 ,
353- borderRadius : 100 ,
354- }
355- }
356- >
357- { props . scrollToBottomComponent ( ) }
358- </ TouchableOpacity >
359- ) }
360- </ View >
361- </ View >
308+ < ChatFooter
309+ newMessagesBannerComponent = { props . newMessagesBannerComponent }
310+ newMessagesBannerStyles = { props . newMessagesBannerStyles }
311+ scrollToBottomComponent = { props . scrollToBottomComponent }
312+ scrollToBottomStyle = { props . scrollToBottomStyle }
313+ closeToTop = { closeToTop }
314+ chatRef = { chatRef }
315+ />
362316 { props . renderChatFooter ?.( ) }
363317 </ >
364318 ) }
0 commit comments