react-native-gifted-chat 2.8.0 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -220,21 +220,18 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
220
220
  return null
221
221
 
222
222
  return (
223
- <Animated.View
224
- style={[
225
- stylesCommon.centerItems,
226
- styles.scrollToBottomStyle,
227
- scrollToBottomStyle,
228
- scrollToBottomStyleAnim,
229
- ]}
230
- >
231
- <TouchableOpacity
232
- onPress={() => doScrollToBottom()}
233
- hitSlop={{ top: 5, left: 5, right: 5, bottom: 5 }}
223
+ <TouchableOpacity onPress={() => doScrollToBottom()}>
224
+ <Animated.View
225
+ style={[
226
+ stylesCommon.centerItems,
227
+ styles.scrollToBottomStyle,
228
+ scrollToBottomStyle,
229
+ scrollToBottomStyleAnim,
230
+ ]}
234
231
  >
235
232
  {renderScrollBottomComponent()}
236
- </TouchableOpacity>
237
- </Animated.View>
233
+ </Animated.View>
234
+ </TouchableOpacity>
238
235
  )
239
236
  }, [scrollToBottomStyle, renderScrollBottomComponent, doScrollToBottom, scrollToBottomStyleAnim, isScrollToBottomVisible])
240
237
 
@@ -267,9 +264,7 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
267
264
 
268
265
  const renderCell = useCallback((props: CellRendererProps<unknown>) => {
269
266
  const handleOnLayout = (event: LayoutChangeEvent) => {
270
- const prevMessage = messages[props.index + (inverted ? 1 : -1)]
271
- if (prevMessage && isSameDay(props.item as IMessage, prevMessage))
272
- return
267
+ props.onLayout?.(event)
273
268
 
274
269
  const { y, height } = event.nativeEvent.layout
275
270
 
@@ -282,6 +277,23 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
282
277
  daysPositions.modify(value => {
283
278
  'worklet'
284
279
 
280
+ const isSameDay = (date1: number, date2: number) => {
281
+ const d1 = new Date(date1)
282
+ const d2 = new Date(date2)
283
+
284
+ return (
285
+ d1.getDate() === d2.getDate() &&
286
+ d1.getMonth() === d2.getMonth() &&
287
+ d1.getFullYear() === d2.getFullYear()
288
+ )
289
+ }
290
+
291
+ for (const [key, item] of Object.entries(value))
292
+ if (isSameDay(newValue.createdAt, item.createdAt) && (inverted ? item.y <= newValue.y : item.y >= newValue.y)) {
293
+ delete value[key]
294
+ break
295
+ }
296
+
285
297
  // @ts-expect-error: https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue#remarks
286
298
  value[props.item._id] = newValue
287
299
  return value
@@ -289,12 +301,14 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
289
301
  }
290
302
 
291
303
  return (
292
- <Animated.View
304
+ <View
293
305
  {...props}
294
306
  onLayout={handleOnLayout}
295
- />
307
+ >
308
+ {props.children}
309
+ </View>
296
310
  )
297
- }, [daysPositions, messages, inverted])
311
+ }, [daysPositions, inverted])
298
312
 
299
313
  const scrollHandler = useAnimatedScrollHandler({
300
314
  onScroll: event => {
@@ -307,7 +321,7 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
307
321
  // removes unrendered days positions when messages are added/removed
308
322
  useEffect(() => {
309
323
  Object.keys(daysPositions.value).forEach(key => {
310
- const messageIndex = messages.findIndex(m => m._id === key)
324
+ const messageIndex = messages.findIndex(m => m._id.toString() === key)
311
325
  let shouldRemove = messageIndex === -1
312
326
 
313
327
  if (!shouldRemove) {
@@ -334,14 +348,14 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
334
348
  ]}
335
349
  >
336
350
  <AnimatedFlatList
351
+ extraData={extraData}
337
352
  ref={forwardRef as React.Ref<FlatList<unknown>>}
338
- extraData={[extraData, isTyping]}
339
353
  keyExtractor={keyExtractor}
340
- automaticallyAdjustContentInsets={false}
341
- inverted={inverted}
342
354
  data={messages}
343
- style={stylesCommon.fill}
344
355
  renderItem={renderItem}
356
+ inverted={inverted}
357
+ automaticallyAdjustContentInsets={false}
358
+ style={stylesCommon.fill}
345
359
  {...invertibleScrollViewProps}
346
360
  ListEmptyComponent={renderChatEmpty}
347
361
  ListFooterComponent={
@@ -140,13 +140,13 @@ export function MessageText<TMessage extends IMessage = IMessage> ({
140
140
  <View
141
141
  style={[
142
142
  styles[position].container,
143
- containerStyle && containerStyle[position],
143
+ containerStyle?.[position],
144
144
  ]}
145
145
  >
146
146
  <ParsedText
147
147
  style={[
148
148
  styles[position].text,
149
- textStyle && textStyle[position],
149
+ textStyle?.[position],
150
150
  customTextStyle,
151
151
  ]}
152
152
  parse={[
@@ -28,12 +28,7 @@ exports[`should render <MessageContainer /> and compare with snapshot 1`] = `
28
28
  automaticallyAdjustContentInsets={false}
29
29
  collapsable={false}
30
30
  data={[]}
31
- extraData={
32
- [
33
- null,
34
- false,
35
- ]
36
- }
31
+ extraData={null}
37
32
  getItem={[Function]}
38
33
  getItemCount={[Function]}
39
34
  invertStickyHeaders={true}