@@ -2,6 +2,8 @@ import React from 'react';
22import { ActivityIndicator , StyleSheet , Text , View } from 'react-native' ;
33import Svg , { Defs , LinearGradient , Rect , Stop } from 'react-native-svg' ;
44
5+ import type { ThreadState } from 'stream-chat' ;
6+
57import {
68 MessagesContextValue ,
79 useMessagesContext ,
@@ -12,6 +14,7 @@ import {
1214 useThreadContext ,
1315} from '../../../contexts/threadContext/ThreadContext' ;
1416import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext' ;
17+ import { useStateStore } from '../../../hooks' ;
1518import { useViewport } from '../../../hooks/useViewport' ;
1619import type { DefaultStreamChatGenerics } from '../../../types/types' ;
1720
@@ -42,7 +45,10 @@ const styles = StyleSheet.create({
4245type ThreadFooterComponentPropsWithContext <
4346 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
4447> = Pick < MessagesContextValue < StreamChatGenerics > , 'Message' > &
45- Pick < ThreadContextValue < StreamChatGenerics > , 'parentMessagePreventPress' | 'thread' > ;
48+ Pick <
49+ ThreadContextValue < StreamChatGenerics > ,
50+ 'parentMessagePreventPress' | 'thread' | 'threadInstance'
51+ > ;
4652
4753export const InlineLoadingMoreThreadIndicator = ( ) => {
4854 const { threadLoadingMore } = useThreadContext ( ) ;
@@ -63,12 +69,17 @@ export const InlineLoadingMoreThreadIndicator = () => {
6369 ) ;
6470} ;
6571
72+ const selector = ( nextValue : ThreadState ) =>
73+ ( {
74+ replyCount : nextValue . replyCount ,
75+ } ) as const ;
76+
6677const ThreadFooterComponentWithContext = <
6778 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
6879> (
6980 props : ThreadFooterComponentPropsWithContext < StreamChatGenerics > ,
7081) => {
71- const { Message, parentMessagePreventPress, thread } = props ;
82+ const { Message, parentMessagePreventPress, thread, threadInstance } = props ;
7283 const { t } = useTranslationContext ( ) ;
7384 const { vw } = useViewport ( ) ;
7485
@@ -87,12 +98,12 @@ const ThreadFooterComponentWithContext = <
8798 } ,
8899 } = useTheme ( ) ;
89100
101+ const { replyCount = thread ?. reply_count } = useStateStore ( threadInstance ?. state , selector ) ?? { } ;
102+
90103 if ( ! thread ) {
91104 return null ;
92105 }
93106
94- const replyCount = thread . reply_count ;
95-
96107 return (
97108 < View style = { styles . threadHeaderContainer } testID = 'thread-footer-component' >
98109 < View style = { styles . messagePadding } >
@@ -145,10 +156,16 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
145156 prevProps : ThreadFooterComponentPropsWithContext < StreamChatGenerics > ,
146157 nextProps : ThreadFooterComponentPropsWithContext < StreamChatGenerics > ,
147158) => {
148- const { parentMessagePreventPress : prevParentMessagePreventPress , thread : prevThread } =
149- prevProps ;
150- const { parentMessagePreventPress : nextParentMessagePreventPress , thread : nextThread } =
151- nextProps ;
159+ const {
160+ parentMessagePreventPress : prevParentMessagePreventPress ,
161+ thread : prevThread ,
162+ threadInstance : prevThreadInstance ,
163+ } = prevProps ;
164+ const {
165+ parentMessagePreventPress : nextParentMessagePreventPress ,
166+ thread : nextThread ,
167+ threadInstance : nextThreadInstance ,
168+ } = nextProps ;
152169
153170 if ( prevParentMessagePreventPress !== nextParentMessagePreventPress ) {
154171 return false ;
@@ -158,10 +175,15 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
158175 prevThread ?. id === nextThread ?. id &&
159176 prevThread ?. text === nextThread ?. text &&
160177 prevThread ?. reply_count === nextThread ?. reply_count ;
178+
161179 if ( ! threadEqual ) {
162180 return false ;
163181 }
164182
183+ if ( prevThreadInstance !== nextThreadInstance ) {
184+ return false ;
185+ }
186+
165187 const latestReactionsEqual =
166188 prevThread &&
167189 nextThread &&
@@ -195,7 +217,7 @@ export const ThreadFooterComponent = <
195217 props : ThreadFooterComponentProps < StreamChatGenerics > ,
196218) => {
197219 const { Message } = useMessagesContext < StreamChatGenerics > ( ) ;
198- const { parentMessagePreventPress, thread, threadLoadingMore } =
220+ const { parentMessagePreventPress, thread, threadInstance , threadLoadingMore } =
199221 useThreadContext < StreamChatGenerics > ( ) ;
200222
201223 return (
@@ -204,6 +226,7 @@ export const ThreadFooterComponent = <
204226 Message,
205227 parentMessagePreventPress,
206228 thread,
229+ threadInstance,
207230 threadLoadingMore,
208231 } }
209232 { ...props }
0 commit comments