@@ -2,6 +2,8 @@ import React from 'react';
2
2
import { ActivityIndicator , StyleSheet , Text , View } from 'react-native' ;
3
3
import Svg , { Defs , LinearGradient , Rect , Stop } from 'react-native-svg' ;
4
4
5
+ import type { ThreadState } from 'stream-chat' ;
6
+
5
7
import {
6
8
MessagesContextValue ,
7
9
useMessagesContext ,
@@ -12,6 +14,7 @@ import {
12
14
useThreadContext ,
13
15
} from '../../../contexts/threadContext/ThreadContext' ;
14
16
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext' ;
17
+ import { useStateStore } from '../../../hooks' ;
15
18
import { useViewport } from '../../../hooks/useViewport' ;
16
19
import type { DefaultStreamChatGenerics } from '../../../types/types' ;
17
20
@@ -42,7 +45,10 @@ const styles = StyleSheet.create({
42
45
type ThreadFooterComponentPropsWithContext <
43
46
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
44
47
> = Pick < MessagesContextValue < StreamChatGenerics > , 'Message' > &
45
- Pick < ThreadContextValue < StreamChatGenerics > , 'parentMessagePreventPress' | 'thread' > ;
48
+ Pick <
49
+ ThreadContextValue < StreamChatGenerics > ,
50
+ 'parentMessagePreventPress' | 'thread' | 'threadInstance'
51
+ > ;
46
52
47
53
export const InlineLoadingMoreThreadIndicator = ( ) => {
48
54
const { threadLoadingMore } = useThreadContext ( ) ;
@@ -63,12 +69,17 @@ export const InlineLoadingMoreThreadIndicator = () => {
63
69
) ;
64
70
} ;
65
71
72
+ const selector = ( nextValue : ThreadState ) =>
73
+ ( {
74
+ replyCount : nextValue . replyCount ,
75
+ } ) as const ;
76
+
66
77
const ThreadFooterComponentWithContext = <
67
78
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
68
79
> (
69
80
props : ThreadFooterComponentPropsWithContext < StreamChatGenerics > ,
70
81
) => {
71
- const { Message, parentMessagePreventPress, thread } = props ;
82
+ const { Message, parentMessagePreventPress, thread, threadInstance } = props ;
72
83
const { t } = useTranslationContext ( ) ;
73
84
const { vw } = useViewport ( ) ;
74
85
@@ -87,12 +98,12 @@ const ThreadFooterComponentWithContext = <
87
98
} ,
88
99
} = useTheme ( ) ;
89
100
101
+ const { replyCount = thread ?. reply_count } = useStateStore ( threadInstance ?. state , selector ) ?? { } ;
102
+
90
103
if ( ! thread ) {
91
104
return null ;
92
105
}
93
106
94
- const replyCount = thread . reply_count ;
95
-
96
107
return (
97
108
< View style = { styles . threadHeaderContainer } testID = 'thread-footer-component' >
98
109
< View style = { styles . messagePadding } >
@@ -145,10 +156,16 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
145
156
prevProps : ThreadFooterComponentPropsWithContext < StreamChatGenerics > ,
146
157
nextProps : ThreadFooterComponentPropsWithContext < StreamChatGenerics > ,
147
158
) => {
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 ;
152
169
153
170
if ( prevParentMessagePreventPress !== nextParentMessagePreventPress ) {
154
171
return false ;
@@ -158,10 +175,15 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
158
175
prevThread ?. id === nextThread ?. id &&
159
176
prevThread ?. text === nextThread ?. text &&
160
177
prevThread ?. reply_count === nextThread ?. reply_count ;
178
+
161
179
if ( ! threadEqual ) {
162
180
return false ;
163
181
}
164
182
183
+ if ( prevThreadInstance !== nextThreadInstance ) {
184
+ return false ;
185
+ }
186
+
165
187
const latestReactionsEqual =
166
188
prevThread &&
167
189
nextThread &&
@@ -195,7 +217,7 @@ export const ThreadFooterComponent = <
195
217
props : ThreadFooterComponentProps < StreamChatGenerics > ,
196
218
) => {
197
219
const { Message } = useMessagesContext < StreamChatGenerics > ( ) ;
198
- const { parentMessagePreventPress, thread, threadLoadingMore } =
220
+ const { parentMessagePreventPress, thread, threadInstance , threadLoadingMore } =
199
221
useThreadContext < StreamChatGenerics > ( ) ;
200
222
201
223
return (
@@ -204,6 +226,7 @@ export const ThreadFooterComponent = <
204
226
Message,
205
227
parentMessagePreventPress,
206
228
thread,
229
+ threadInstance,
207
230
threadLoadingMore,
208
231
} }
209
232
{ ...props }
0 commit comments