@cometchat/chat-uikit-react-native 5.2.4 → 5.2.6

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.
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useEffect, useReducer, useRef, useState, useMemo } from 'react';
2
- import { View, TextInput, TouchableOpacity, Text, ScrollView, Image } from 'react-native';
2
+ import { View, TextInput, TouchableOpacity, Text, Image, ImageBackground, FlatList, ImageSourcePropType } from 'react-native';
3
3
  import { CometChat } from '@cometchat/chat-sdk-react-native';
4
4
  import {
5
5
  CometChatAvatar,
@@ -15,8 +15,10 @@ import { Skeleton } from './Skeleton';
15
15
  import { SearchStyle, getSearchStyleLight, getSearchStyleDark } from './style';
16
16
  import { deepMerge } from '../shared/helper/helperFunctions';
17
17
  import { DeepPartial } from '../shared/helper/types';
18
- import Video from 'react-native-video';
19
18
  import { getCometChatTranslation } from '../shared/resources/CometChatLocalizeNew/LocalizationManager';
19
+ import { CommonUtils } from '../shared/utils/CommonUtils';
20
+ import { ExtensionConstants } from '../extensions/ExtensionConstants';
21
+ import { getExtensionData } from '../extensions/ExtensionModerator';
20
22
 
21
23
 
22
24
  // ERROR HANDLER
@@ -369,6 +371,224 @@ const LinkPreviewImage: React.FC<LinkPreviewImageProps> = ({ uri, mergedStyles,
369
371
  );
370
372
  };
371
373
 
374
+ // Helper function to check for extension-generated thumbnails
375
+ const checkThumbnail = (message: CometChat.MediaMessage): { uri: string } => {
376
+ let image: { uri: string } = { uri: "" };
377
+ const thumbnailData = getExtensionData(message, ExtensionConstants.thumbnailGeneration);
378
+
379
+ if (thumbnailData == undefined) {
380
+ // Fallback to attachment thumbnail for videos
381
+ if (message.getType() === "video") {
382
+ const attachment = message.getAttachment();
383
+ const thumbnailUrl = attachment && ((attachment as any).thumbnail || (attachment as any).url);
384
+ image = thumbnailUrl ? { uri: thumbnailUrl } : image;
385
+ }
386
+ } else {
387
+ // Extension-generated thumbnail exists
388
+ const attachmentData = thumbnailData["attachments"];
389
+ if (attachmentData && attachmentData.length) {
390
+ const dataObj = attachmentData[0];
391
+ if (!dataObj["error"]) {
392
+ const imageLink = dataObj?.["data"]?.["thumbnails"]?.["url_small"];
393
+ if (imageLink) {
394
+ image = { uri: dataObj["data"]["thumbnails"]["url_small"] };
395
+ }
396
+ }
397
+ }
398
+ }
399
+
400
+ return image;
401
+ };
402
+
403
+ interface VideoThumbnailProps {
404
+ thumbnailUrl: ImageSourcePropType;
405
+ mergedStyles: any;
406
+ }
407
+
408
+ const VideoThumbnail = React.memo(({ thumbnailUrl, mergedStyles, }: VideoThumbnailProps) => {
409
+
410
+ const [imageSource, setImageSource] = useState<ImageSourcePropType>(thumbnailUrl);
411
+
412
+ useEffect(() => {
413
+ if (thumbnailUrl && typeof thumbnailUrl === "object" && "uri" in thumbnailUrl) {
414
+ CommonUtils.prefetchThumbnail((thumbnailUrl as any).uri).then((success) => {
415
+ if (success) {
416
+ // console.log("success", thumbnailUrl);
417
+ setImageSource(thumbnailUrl);
418
+
419
+ }
420
+ }).catch((error) => {
421
+ console.log("error", error);
422
+ });
423
+ }
424
+ }, [thumbnailUrl]);
425
+
426
+ return (
427
+ <View
428
+ style={mergedStyles.messageItemStyle?.previewContainerStyle}
429
+ renderToHardwareTextureAndroid={true}
430
+ shouldRasterizeIOS={true}
431
+ >
432
+ <ImageBackground
433
+ source={imageSource}
434
+ style={mergedStyles.messageItemStyle?.previewVideoStyle}
435
+ resizeMode="cover"
436
+ progressiveRenderingEnabled={true}
437
+ fadeDuration={0}
438
+ >
439
+ <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
440
+ <View style={mergedStyles.messageItemStyle?.videoPlayIconStyle}>
441
+ <Icon
442
+ name='play-arrow'
443
+ size={16}
444
+ height={16}
445
+ width={16}
446
+ color="white"
447
+ />
448
+ </View>
449
+ </View>
450
+ </ImageBackground>
451
+ </View>
452
+ );
453
+ },
454
+
455
+ /** Custom comparison function */
456
+ (prev, next) => {
457
+ const prevUri = (prev.thumbnailUrl as any)?.uri;
458
+ const nextUri = (next.thumbnailUrl as any)?.uri;
459
+
460
+ return prevUri === nextUri;
461
+ }
462
+ );
463
+
464
+ // Memoized Conversation Item Component
465
+ interface ConversationItemProps {
466
+ conversation: CometChat.Conversation;
467
+ searchText: string;
468
+ onPress: (conversation: CometChat.Conversation, searchText: string) => void;
469
+ mergedStyles: any;
470
+ theme: any;
471
+ conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
472
+ }
473
+
474
+ const ConversationItem = React.memo<ConversationItemProps>((
475
+ { conversation, searchText, onPress, mergedStyles, theme, conversationItemView }
476
+ ) => {
477
+ const getStatusIndicator = () => {
478
+ const withObj = conversation.getConversationWith();
479
+
480
+ if (withObj instanceof CometChat.Group) {
481
+ if (withObj.getType() === GroupTypeConstants.password) return "password";
482
+ if (withObj.getType() === GroupTypeConstants.private) return "private";
483
+ } else if (withObj instanceof CometChat.User) {
484
+ if (withObj.getStatus() === 'online' && !withObj.getHasBlockedMe() && !withObj.getBlockedByMe()) {
485
+ return "online";
486
+ }
487
+ return "offline";
488
+ }
489
+ return undefined;
490
+ };
491
+
492
+ const renderLeadingView = () => {
493
+ const withObj = conversation.getConversationWith();
494
+ const avatarURL = withObj instanceof CometChat.User ? withObj.getAvatar() : withObj.getIcon();
495
+ const name = withObj.getName();
496
+
497
+ return (
498
+ <View style={{ position: 'relative' }}>
499
+ <View style={{ height: 48, width: 48 }}>
500
+ <CometChatAvatar
501
+ image={{ uri: avatarURL }}
502
+ name={name}
503
+ />
504
+ <View style={{
505
+ position: 'absolute',
506
+ bottom: 0,
507
+ right: 0,
508
+ }}>
509
+ <CometChatStatusIndicator
510
+ type={getStatusIndicator()}
511
+ />
512
+ </View>
513
+ </View>
514
+ </View>
515
+ );
516
+ };
517
+
518
+ const renderTrailingView = () => {
519
+ const timestamp = conversation.getLastMessage()?.getSentAt();
520
+ if (!timestamp) return null;
521
+
522
+ return (
523
+ <View style={mergedStyles.conversationItemStyle?.trailingContainerStyle}>
524
+ <CometChatDate
525
+ timeStamp={timestamp * 1000}
526
+ pattern={"conversationDate"}
527
+ />
528
+ <CometChatBadge
529
+ count={conversation.getUnreadMessageCount()}
530
+ />
531
+ </View>
532
+ );
533
+ };
534
+
535
+ const formatMentionsInText = (rawText: any, message?: CometChat.BaseMessage) => {
536
+ if (typeof rawText !== 'string') return rawText;
537
+
538
+ let text = rawText.replace(/<@all:(.*?)>/g, '@$1');
539
+
540
+ try {
541
+ const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
542
+ if (mentionedUsers && mentionedUsers.length > 0) {
543
+ mentionedUsers.forEach((u: CometChat.User) => {
544
+ const uid = u.getUid();
545
+ const name = u.getName();
546
+ if (uid && name) {
547
+ const uidRegex = new RegExp(`<@uid:${uid}>`, 'g');
548
+ text = text.replace(uidRegex, `@${name}`);
549
+ }
550
+ });
551
+ }
552
+ } catch (e) {
553
+ console.log(e)
554
+ }
555
+
556
+ return text;
557
+ };
558
+
559
+ if (conversationItemView) {
560
+ return (
561
+ <TouchableOpacity onPress={() => onPress(conversation, searchText)}>
562
+ {conversationItemView(conversation, searchText)}
563
+ </TouchableOpacity>
564
+ );
565
+ }
566
+
567
+ return (
568
+ <TouchableOpacity
569
+ style={mergedStyles.conversationItemStyle?.containerStyle}
570
+ onPress={() => onPress(conversation, searchText)}
571
+ >
572
+ {renderLeadingView()}
573
+ <View style={mergedStyles.conversationItemStyle?.contentStyle}>
574
+ <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
575
+ {conversation.getConversationWith().getName()}
576
+ </Text>
577
+ <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
578
+ {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
579
+ </Text>
580
+ </View>
581
+ {renderTrailingView()}
582
+ </TouchableOpacity>
583
+ );
584
+ }, (prevProps, nextProps) => {
585
+ // Only re-render if conversation ID or search text changes
586
+ return prevProps.conversation.getConversationId() === nextProps.conversation.getConversationId() &&
587
+ prevProps.searchText === nextProps.searchText;
588
+ });
589
+
590
+ ConversationItem.displayName = 'ConversationItem';
591
+
372
592
  /**
373
593
  * CometChatSearch component for searching conversations and messages in CometChat
374
594
  */
@@ -461,7 +681,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
461
681
  const handleClearSearch = useCallback(() => {
462
682
  setSearchValue("");
463
683
  dispatch({ type: "setSearchText", searchText: "" });
464
- dispatch({ type: "resetActiveFilters" });
465
684
  dispatch({ type: "clearResults" });
466
685
  }, []);
467
686
 
@@ -1304,6 +1523,8 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1304
1523
  source={{ uri: imageUrl }}
1305
1524
  style={mergedStyles.messageItemStyle?.previewImageStyle}
1306
1525
  resizeMode="cover"
1526
+ progressiveRenderingEnabled={true}
1527
+ fadeDuration={0}
1307
1528
  />
1308
1529
  </View>
1309
1530
  );
@@ -1313,26 +1534,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1313
1534
 
1314
1535
  case 'video': {
1315
1536
  const videoMessage = message as CometChat.MediaMessage;
1316
- const attachment = videoMessage.getAttachment();
1317
- const thumbnailUrl = attachment && ((attachment as any).thumbnail || (attachment as any).url);
1318
- if (thumbnailUrl) {
1537
+ const thumbnailImage = checkThumbnail(videoMessage);
1538
+
1539
+ if (thumbnailImage.uri) {
1319
1540
  return (
1320
- <View style={mergedStyles.messageItemStyle?.previewContainerStyle}>
1321
- <Video
1322
- source={{ uri: thumbnailUrl }}
1323
- style={mergedStyles.messageItemStyle?.previewVideoStyle}
1324
- resizeMode="cover"
1325
- />
1326
- <View style={mergedStyles.messageItemStyle?.videoPlayIconStyle}>
1327
- <Icon
1328
- name='play-arrow'
1329
- size={16}
1330
- height={16}
1331
- width={16}
1332
- color="white"
1333
- />
1334
- </View>
1335
- </View>
1541
+ <VideoThumbnail
1542
+ thumbnailUrl={thumbnailImage}
1543
+ mergedStyles={mergedStyles}
1544
+ />
1336
1545
  );
1337
1546
  }
1338
1547
  break;
@@ -1363,6 +1572,12 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1363
1572
  );
1364
1573
  };
1365
1574
 
1575
+ // Memoized trailing view component
1576
+ const MemoizedTrailingView = React.memo(({ message }: { message: CometChat.BaseMessage }) =>
1577
+ renderMessageTrailingView(message),
1578
+ (prev, next) => prev.message.getId() === next.message.getId()
1579
+ );
1580
+
1366
1581
  // Render conversations section
1367
1582
  const renderConversationsSection = () => {
1368
1583
  const { conversationList, fetchState } = conversationState;
@@ -1403,50 +1618,60 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1403
1618
  return (
1404
1619
  <View>
1405
1620
  <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>
1406
- {conversationList.map((conversation) => {
1407
- // Use custom conversation item view if provided
1408
- if (conversationItemView) {
1621
+ <FlatList
1622
+ data={conversationList}
1623
+ keyExtractor={(item) => item.getConversationId()}
1624
+ scrollEnabled={false}
1625
+ initialNumToRender={10}
1626
+ maxToRenderPerBatch={5}
1627
+ windowSize={5}
1628
+ removeClippedSubviews={true}
1629
+ updateCellsBatchingPeriod={50}
1630
+ renderItem={({ item: conversation }) => {
1631
+ // Use custom conversation item view if provided
1632
+ if (conversationItemView) {
1633
+ return (
1634
+ <TouchableOpacity
1635
+ onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1636
+ >
1637
+ {conversationItemView(conversation, searchState.searchText)}
1638
+ </TouchableOpacity>
1639
+ );
1640
+ }
1641
+
1642
+ // Default conversation item rendering
1409
1643
  return (
1410
1644
  <TouchableOpacity
1411
- key={conversation.getConversationId()}
1645
+ style={mergedStyles.conversationItemStyle?.containerStyle}
1412
1646
  onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1413
1647
  >
1414
- {conversationItemView(conversation, searchState.searchText)}
1648
+ {renderConversationLeadingView(conversation)}
1649
+ <View style={mergedStyles.conversationItemStyle?.contentStyle}>
1650
+ <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
1651
+ {conversation.getConversationWith().getName()}
1652
+ </Text>
1653
+ <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
1654
+ {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
1655
+ </Text>
1656
+ </View>
1657
+ {renderConversationTrailingView(conversation)}
1415
1658
  </TouchableOpacity>
1416
1659
  );
1417
- }
1418
-
1419
- // Default conversation item rendering
1420
- return (
1421
- <TouchableOpacity
1422
- key={conversation.getConversationId()}
1423
- style={mergedStyles.conversationItemStyle?.containerStyle}
1424
- onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1425
- >
1426
- {renderConversationLeadingView(conversation)}
1427
- <View style={mergedStyles.conversationItemStyle?.contentStyle}>
1428
- <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
1429
- {conversation.getConversationWith().getName()}
1430
- </Text>
1431
- <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
1432
- {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
1660
+ }}
1661
+ ListFooterComponent={
1662
+ conversationState.hasMoreResults ? (
1663
+ <TouchableOpacity
1664
+ style={mergedStyles.seeMoreButtonStyle}
1665
+ onPress={loadMoreConversations}
1666
+ disabled={isConversationMoreResultsLoading.current}
1667
+ >
1668
+ <Text style={mergedStyles.seeMoreTextStyle}>
1669
+ {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1433
1670
  </Text>
1434
- </View>
1435
- {renderConversationTrailingView(conversation)}
1436
- </TouchableOpacity>
1437
- );
1438
- })}
1439
- {conversationState.hasMoreResults && (
1440
- <TouchableOpacity
1441
- style={mergedStyles.seeMoreButtonStyle}
1442
- onPress={loadMoreConversations}
1443
- disabled={isConversationMoreResultsLoading.current}
1444
- >
1445
- <Text style={mergedStyles.seeMoreTextStyle}>
1446
- {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1447
- </Text>
1448
- </TouchableOpacity>
1449
- )}
1671
+ </TouchableOpacity>
1672
+ ) : null
1673
+ }
1674
+ />
1450
1675
  </View>
1451
1676
  );
1452
1677
  };
@@ -1496,7 +1721,287 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1496
1721
  return (
1497
1722
  <View>
1498
1723
  <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>
1499
- {messageList.map((message, index) => {
1724
+ <FlatList
1725
+ data={messageList}
1726
+ keyExtractor={(item, index) => `${item.getId()}-${index}`}
1727
+ initialNumToRender={10}
1728
+ maxToRenderPerBatch={5}
1729
+ windowSize={5}
1730
+ removeClippedSubviews={true}
1731
+ updateCellsBatchingPeriod={50}
1732
+ renderItem={({ item: message, index }) => {
1733
+ const messageType = message.getType();
1734
+
1735
+ // Date header logic for media items
1736
+ let dateHeader: React.ReactNode = null;
1737
+ if (['image', 'video'].includes(messageType)) {
1738
+ const sentAt = message.getSentAt();
1739
+ const currentDateStr = getDateHeaderDate(sentAt);
1740
+ const prevMessage = index > 0 ? messageList[index - 1] : null;
1741
+ const prevDateStr = prevMessage ? getDateHeaderDate(prevMessage.getSentAt()) : null;
1742
+
1743
+ if (currentDateStr !== prevDateStr) {
1744
+ dateHeader = (
1745
+ <CometChatDate
1746
+ timeStamp={sentAt * 1000}
1747
+ customDateString={currentDateStr}
1748
+ style={{
1749
+ textStyle: mergedStyles.sectionTitleStyle
1750
+ }}
1751
+ />
1752
+ );
1753
+ }
1754
+ }
1755
+
1756
+ // Check if message is a text message with link preview
1757
+ const isLinkMessage = messageType === 'text' && (() => {
1758
+ const textMessage = message as CometChat.TextMessage;
1759
+ const metadata = textMessage.getMetadata();
1760
+ return metadata && (metadata as any)['@injected'] && (metadata as any)['@injected']['extensions'] && (metadata as any)['@injected']['extensions']['link-preview'];
1761
+ })();
1762
+
1763
+ // Determine which custom view to use based on message type
1764
+ let customView: (() => React.ReactElement) | undefined;
1765
+
1766
+ if (isLinkMessage && linkMessageItemView) {
1767
+ customView = () => linkMessageItemView(message, searchState.searchText);
1768
+ } else if (messageType === 'text' && textMessageItemView) {
1769
+ customView = () => textMessageItemView(message, searchState.searchText);
1770
+ } else if (messageType === 'image' && imageMessageItemView) {
1771
+ customView = () => imageMessageItemView(message, searchState.searchText);
1772
+ } else if (messageType === 'video' && videoMessageItemView) {
1773
+ customView = () => videoMessageItemView(message, searchState.searchText);
1774
+ } else if (messageType === 'audio' && audioMessageItemView) {
1775
+ customView = () => audioMessageItemView(message, searchState.searchText);
1776
+ } else if (messageType === 'file' && documentMessageItemView) {
1777
+ customView = () => documentMessageItemView(message, searchState.searchText);
1778
+ }
1779
+
1780
+ // Use custom view if available
1781
+ if (customView) {
1782
+ return (
1783
+ <View>
1784
+ {dateHeader}
1785
+ <TouchableOpacity
1786
+ onPress={() => onMessageClicked?.(message, searchState.searchText)}
1787
+ >
1788
+ {customView()}
1789
+ </TouchableOpacity>
1790
+ </View>
1791
+ );
1792
+ }
1793
+
1794
+ // Default message item rendering
1795
+ return (
1796
+ <View>
1797
+ {dateHeader}
1798
+ <TouchableOpacity
1799
+ style={mergedStyles.messageItemStyle?.containerStyle}
1800
+ onPress={() => onMessageClicked?.(message, searchState.searchText)}
1801
+ >
1802
+ {renderMessageLeadingView(message)}
1803
+ <View style={[
1804
+ mergedStyles.messageItemStyle?.contentStyle,
1805
+ (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
1806
+ ]}>
1807
+ <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
1808
+ {message.getSender().getName()}
1809
+ </Text>
1810
+ <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
1811
+ {(() => {
1812
+ const messageType = message.getType();
1813
+
1814
+ // For media messages (image, video, file, audio), show file name
1815
+ if (['image', 'video', 'file', 'audio'].includes(messageType)) {
1816
+ const mediaMessage = message as CometChat.MediaMessage;
1817
+ const attachment = mediaMessage.getAttachment?.();
1818
+ return attachment?.getName?.() || messageType;
1819
+ }
1820
+
1821
+ // For text messages, show the text content
1822
+ if (messageType === 'text') {
1823
+ const raw = (message as CometChat.TextMessage).getText?.();
1824
+ const formatted = formatMentionsInText(raw, message);
1825
+ return formatted || messageType || 'Message';
1826
+ }
1827
+
1828
+ // For custom messages, try to localize the type
1829
+ const customTypeKey = `CUSTOM_MESSAGE_${messageType.toUpperCase()}`;
1830
+ const localizedType = t(customTypeKey);
1831
+
1832
+ // If localization exists and is different from key, use it
1833
+ if (localizedType && localizedType !== customTypeKey) {
1834
+ return localizedType;
1835
+ }
1836
+
1837
+ // Handle specific extension types mapping to existing keys
1838
+ if (messageType === 'extension_poll') return t("CUSTOM_MESSAGE_POLL") || "Poll";
1839
+ if (messageType === 'extension_sticker') return t("CUSTOM_MESSAGE_STICKER") || "Sticker";
1840
+ if (messageType === 'extension_whiteboard') return t("CUSTOM_MESSAGE_WHITEBOARD") || "Whiteboard";
1841
+ if (messageType === 'extension_document') return t("CUSTOM_MESSAGE_DOCUMENT") || "Document";
1842
+ if (messageType === 'meeting') return t("meeting") || "Meeting";
1843
+
1844
+ return messageType || 'Message';
1845
+ })()}
1846
+ </Text>
1847
+ </View>
1848
+ <MemoizedTrailingView message={message} />
1849
+ </TouchableOpacity>
1850
+ </View>
1851
+ );
1852
+ }}
1853
+ />
1854
+ </View>
1855
+ );
1856
+ };
1857
+
1858
+ const renderResults = () => {
1859
+ const conversationsRendered = shouldRenderConversations();
1860
+ const messagesRendered = shouldRenderMessages();
1861
+
1862
+ // Initial empty state - no search text and no filters
1863
+ if ((!searchState.searchText || searchState.searchText.trim() === "") && searchState.activeFilters.length === 0) {
1864
+ if (emptyView) {
1865
+ return emptyView();
1866
+ }
1867
+
1868
+ return (
1869
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1870
+ <Icon
1871
+ name="empty-search"
1872
+ size={120}
1873
+ height={120}
1874
+ width={120}
1875
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1876
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1877
+ />
1878
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1879
+ {t("SEARCH_NO_RESULTS_TITLE") || "No Results"}
1880
+ </Text>
1881
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1882
+ {t("SEARCH_NO_RESULTS_SUBTITLE") || "Start typing to search for messages and conversations"}
1883
+ </Text>
1884
+ </View>
1885
+ );
1886
+ }
1887
+
1888
+ // Show loading shimmer if we have search/filters active and both sections are loading
1889
+ if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1890
+ (conversationState.fetchState === States.loading || messageState.fetchState === States.loading) &&
1891
+ conversationState.conversationList.length === 0 &&
1892
+ messageState.messageList.length === 0) {
1893
+ return loadingView ? loadingView() : <Skeleton />;
1894
+ }
1895
+
1896
+ // Check if we have search text or filters but no actual results
1897
+ if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1898
+ conversationState.conversationList.length === 0 &&
1899
+ messageState.messageList.length === 0 &&
1900
+ conversationState.fetchState !== States.loading &&
1901
+ messageState.fetchState !== States.loading &&
1902
+ conversationState.fetchState !== States.error &&
1903
+ messageState.fetchState !== States.error) {
1904
+ // No results found state
1905
+ if (emptyView) {
1906
+ return emptyView();
1907
+ }
1908
+
1909
+ return (
1910
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1911
+ <Icon
1912
+ name="empty-search"
1913
+ size={120}
1914
+ height={120}
1915
+ width={120}
1916
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1917
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1918
+ />
1919
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1920
+ {t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
1921
+ </Text>
1922
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1923
+ {t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
1924
+ </Text>
1925
+ </View>
1926
+ );
1927
+ }
1928
+
1929
+ // Show search results with actual item lists - USING SINGLE FLATLIST FOR VIRTUALIZATION
1930
+ // Create combined data array with section headers
1931
+ type ListItem =
1932
+ | { type: 'conversation-header' }
1933
+ | { type: 'conversation'; data: CometChat.Conversation }
1934
+ | { type: 'conversation-footer' }
1935
+ | { type: 'message-header' }
1936
+ | { type: 'message'; data: CometChat.BaseMessage; index: number }
1937
+ | { type: 'message-footer' };
1938
+
1939
+ const combinedData: ListItem[] = [];
1940
+
1941
+ // Add conversations section if needed
1942
+ if (conversationsRendered && conversationState.conversationList.length > 0) {
1943
+ combinedData.push({ type: 'conversation-header' });
1944
+ conversationState.conversationList.forEach(conv => {
1945
+ combinedData.push({ type: 'conversation', data: conv });
1946
+ });
1947
+ if (conversationState.hasMoreResults) {
1948
+ combinedData.push({ type: 'conversation-footer' });
1949
+ }
1950
+ }
1951
+
1952
+ // Add messages section if needed
1953
+ if (messagesRendered && messageState.messageList.length > 0) {
1954
+ combinedData.push({ type: 'message-header' });
1955
+ messageState.messageList.forEach((msg, index) => {
1956
+ combinedData.push({ type: 'message', data: msg, index });
1957
+ });
1958
+ }
1959
+
1960
+ const keyExtractor = (item: ListItem, index: number) => {
1961
+ if (item.type === 'conversation') {
1962
+ return `conversation-${item.data.getConversationId()}`;
1963
+ } else if (item.type === 'message') {
1964
+ return `message-${item.data.getId()}-${index}`;
1965
+ }
1966
+ return `${item.type}-${index}`;
1967
+ };
1968
+
1969
+ const renderCombinedItem = ({ item }: { item: ListItem }) => {
1970
+ switch (item.type) {
1971
+ case 'conversation-header':
1972
+ return <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>;
1973
+
1974
+ case 'conversation':
1975
+ return (
1976
+ <ConversationItem
1977
+ conversation={item.data}
1978
+ searchText={searchState.searchText}
1979
+ onPress={onConversationClicked || (() => {})}
1980
+ mergedStyles={mergedStyles}
1981
+ theme={theme}
1982
+ conversationItemView={conversationItemView}
1983
+ />
1984
+ );
1985
+
1986
+ case 'conversation-footer':
1987
+ return (
1988
+ <TouchableOpacity
1989
+ style={mergedStyles.seeMoreButtonStyle}
1990
+ onPress={loadMoreConversations}
1991
+ disabled={isConversationMoreResultsLoading.current}
1992
+ >
1993
+ <Text style={mergedStyles.seeMoreTextStyle}>
1994
+ {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1995
+ </Text>
1996
+ </TouchableOpacity>
1997
+ );
1998
+
1999
+ case 'message-header':
2000
+ return <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>;
2001
+
2002
+ case 'message': {
2003
+ const message = item.data;
2004
+ const messageIndex = item.index;
1500
2005
  const messageType = message.getType();
1501
2006
 
1502
2007
  // Date header logic for media items
@@ -1504,8 +2009,8 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1504
2009
  if (['image', 'video'].includes(messageType)) {
1505
2010
  const sentAt = message.getSentAt();
1506
2011
  const currentDateStr = getDateHeaderDate(sentAt);
1507
- const prevMessage = index > 0 ? messageList[index - 1] : null;
1508
- const prevDateStr = prevMessage ? getDateHeaderDate(prevMessage.getSentAt()) : null;
2012
+ const prevItem = messageIndex > 0 ? messageState.messageList[messageIndex - 1] : null;
2013
+ const prevDateStr = prevItem ? getDateHeaderDate(prevItem.getSentAt()) : null;
1509
2014
 
1510
2015
  if (currentDateStr !== prevDateStr) {
1511
2016
  dateHeader = (
@@ -1547,7 +2052,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1547
2052
  // Use custom view if available
1548
2053
  if (customView) {
1549
2054
  return (
1550
- <View key={`${message.getId()}-${index}`}>
2055
+ <View>
1551
2056
  {dateHeader}
1552
2057
  <TouchableOpacity
1553
2058
  onPress={() => onMessageClicked?.(message, searchState.searchText)}
@@ -1560,7 +2065,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1560
2065
 
1561
2066
  // Default message item rendering
1562
2067
  return (
1563
- <View key={`${message.getId()}-${index}`}>
2068
+ <View>
1564
2069
  {dateHeader}
1565
2070
  <TouchableOpacity
1566
2071
  style={mergedStyles.messageItemStyle?.containerStyle}
@@ -1576,24 +2081,24 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1576
2081
  </Text>
1577
2082
  <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
1578
2083
  {(() => {
1579
- const messageType = message.getType();
2084
+ const msgType = message.getType();
1580
2085
 
1581
2086
  // For media messages (image, video, file, audio), show file name
1582
- if (['image', 'video', 'file', 'audio'].includes(messageType)) {
2087
+ if (['image', 'video', 'file', 'audio'].includes(msgType)) {
1583
2088
  const mediaMessage = message as CometChat.MediaMessage;
1584
2089
  const attachment = mediaMessage.getAttachment?.();
1585
- return attachment?.getName?.() || messageType;
2090
+ return attachment?.getName?.() || msgType;
1586
2091
  }
1587
2092
 
1588
2093
  // For text messages, show the text content
1589
- if (messageType === 'text') {
2094
+ if (msgType === 'text') {
1590
2095
  const raw = (message as CometChat.TextMessage).getText?.();
1591
2096
  const formatted = formatMentionsInText(raw, message);
1592
- return formatted || messageType || 'Message';
2097
+ return formatted || msgType || 'Message';
1593
2098
  }
1594
2099
 
1595
2100
  // For custom messages, try to localize the type
1596
- const customTypeKey = `CUSTOM_MESSAGE_${messageType.toUpperCase()}`;
2101
+ const customTypeKey = `CUSTOM_MESSAGE_${msgType.toUpperCase()}`;
1597
2102
  const localizedType = t(customTypeKey);
1598
2103
 
1599
2104
  // If localization exists and is different from key, use it
@@ -1602,107 +2107,48 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1602
2107
  }
1603
2108
 
1604
2109
  // Handle specific extension types mapping to existing keys
1605
- if (messageType === 'extension_poll') return t("CUSTOM_MESSAGE_POLL") || "Poll";
1606
- if (messageType === 'extension_sticker') return t("CUSTOM_MESSAGE_STICKER") || "Sticker";
1607
- if (messageType === 'extension_whiteboard') return t("CUSTOM_MESSAGE_WHITEBOARD") || "Whiteboard";
1608
- if (messageType === 'extension_document') return t("CUSTOM_MESSAGE_DOCUMENT") || "Document";
1609
- if (messageType === 'meeting') return t("meeting") || "Meeting";
2110
+ if (msgType === 'extension_poll') return t("CUSTOM_MESSAGE_POLL") || "Poll";
2111
+ if (msgType === 'extension_sticker') return t("CUSTOM_MESSAGE_STICKER") || "Sticker";
2112
+ if (msgType === 'extension_whiteboard') return t("CUSTOM_MESSAGE_WHITEBOARD") || "Whiteboard";
2113
+ if (msgType === 'extension_document') return t("CUSTOM_MESSAGE_DOCUMENT") || "Document";
2114
+ if (msgType === 'meeting') return t("meeting") || "Meeting";
1610
2115
 
1611
- return messageType || 'Message';
2116
+ return msgType || 'Message';
1612
2117
  })()}
1613
2118
  </Text>
1614
2119
  </View>
1615
- {renderMessageTrailingView(message)}
2120
+ <MemoizedTrailingView message={message} />
1616
2121
  </TouchableOpacity>
1617
2122
  </View>
1618
2123
  );
1619
- })}
1620
- </View>
1621
- );
1622
- };
1623
-
1624
- const renderResults = () => {
1625
- const conversationsRendered = shouldRenderConversations();
1626
- const messagesRendered = shouldRenderMessages();
1627
-
1628
- // Initial empty state - no search text and no filters
1629
- if ((!searchState.searchText || searchState.searchText.trim() === "") && searchState.activeFilters.length === 0) {
1630
- if (emptyView) {
1631
- return emptyView();
1632
- }
1633
-
1634
- return (
1635
- <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1636
- <Icon
1637
- name="empty-search"
1638
- size={120}
1639
- height={120}
1640
- width={120}
1641
- imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1642
- containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1643
- />
1644
- <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1645
- {t("SEARCH_NO_RESULTS_TITLE") || "No Results"}
1646
- </Text>
1647
- <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1648
- {t("SEARCH_NO_RESULTS_SUBTITLE") || "Start typing to search for messages and conversations"}
1649
- </Text>
1650
- </View>
1651
- );
1652
- }
1653
-
1654
- // Show loading shimmer if we have search/filters active and both sections are loading
1655
- if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1656
- (conversationState.fetchState === States.loading || messageState.fetchState === States.loading) &&
1657
- conversationState.conversationList.length === 0 &&
1658
- messageState.messageList.length === 0) {
1659
- return loadingView ? loadingView() : <Skeleton />;
1660
- }
1661
-
1662
- // Check if we have search text or filters but no actual results
1663
- if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1664
- conversationState.conversationList.length === 0 &&
1665
- messageState.messageList.length === 0 &&
1666
- conversationState.fetchState !== States.loading &&
1667
- messageState.fetchState !== States.loading &&
1668
- conversationState.fetchState !== States.error &&
1669
- messageState.fetchState !== States.error) {
1670
- // No results found state
1671
- if (emptyView) {
1672
- return emptyView();
2124
+ }
2125
+
2126
+ default:
2127
+ return null;
1673
2128
  }
2129
+ };
1674
2130
 
1675
- return (
1676
- <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1677
- <Icon
1678
- name="empty-search"
1679
- size={120}
1680
- height={120}
1681
- width={120}
1682
- imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1683
- containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1684
- />
1685
- <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1686
- {t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
1687
- </Text>
1688
- <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1689
- {t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
1690
- </Text>
1691
- </View>
1692
- );
1693
- }
1694
-
1695
- // Show search results with actual item lists
1696
2131
  return (
1697
- <ScrollView
2132
+ <FlatList
2133
+ data={combinedData}
2134
+ keyExtractor={keyExtractor}
2135
+ renderItem={renderCombinedItem}
1698
2136
  style={[mergedStyles.resultsContainerStyle]}
1699
2137
  contentContainerStyle={{ paddingHorizontal: theme.spacing.padding.p4 }}
1700
2138
  showsVerticalScrollIndicator={false}
1701
- onMomentumScrollEnd={handleScrollEnd}
1702
- >
1703
- {conversationsRendered && renderConversationsSection()}
1704
- {messagesRendered && renderMessagesSection()}
1705
- </ScrollView>
2139
+ initialNumToRender={10}
2140
+ maxToRenderPerBatch={10}
2141
+ windowSize={10}
2142
+ removeClippedSubviews={true}
2143
+ updateCellsBatchingPeriod={100}
2144
+ onEndReached={() => {
2145
+ // Load more messages if we're at the end and messages section is visible
2146
+ if (messagesRendered && messageState.hasMoreResults) {
2147
+ loadMoreMessages();
2148
+ }
2149
+ }}
2150
+ onEndReachedThreshold={0.5}
2151
+ />
1706
2152
  );
1707
2153
  };
1708
2154