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

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
  */
@@ -1304,6 +1524,8 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1304
1524
  source={{ uri: imageUrl }}
1305
1525
  style={mergedStyles.messageItemStyle?.previewImageStyle}
1306
1526
  resizeMode="cover"
1527
+ progressiveRenderingEnabled={true}
1528
+ fadeDuration={0}
1307
1529
  />
1308
1530
  </View>
1309
1531
  );
@@ -1313,26 +1535,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1313
1535
 
1314
1536
  case 'video': {
1315
1537
  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) {
1538
+ const thumbnailImage = checkThumbnail(videoMessage);
1539
+
1540
+ if (thumbnailImage.uri) {
1319
1541
  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>
1542
+ <VideoThumbnail
1543
+ thumbnailUrl={thumbnailImage}
1544
+ mergedStyles={mergedStyles}
1545
+ />
1336
1546
  );
1337
1547
  }
1338
1548
  break;
@@ -1363,6 +1573,12 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1363
1573
  );
1364
1574
  };
1365
1575
 
1576
+ // Memoized trailing view component
1577
+ const MemoizedTrailingView = React.memo(({ message }: { message: CometChat.BaseMessage }) =>
1578
+ renderMessageTrailingView(message),
1579
+ (prev, next) => prev.message.getId() === next.message.getId()
1580
+ );
1581
+
1366
1582
  // Render conversations section
1367
1583
  const renderConversationsSection = () => {
1368
1584
  const { conversationList, fetchState } = conversationState;
@@ -1403,50 +1619,60 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1403
1619
  return (
1404
1620
  <View>
1405
1621
  <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>
1406
- {conversationList.map((conversation) => {
1407
- // Use custom conversation item view if provided
1408
- if (conversationItemView) {
1622
+ <FlatList
1623
+ data={conversationList}
1624
+ keyExtractor={(item) => item.getConversationId()}
1625
+ scrollEnabled={false}
1626
+ initialNumToRender={10}
1627
+ maxToRenderPerBatch={5}
1628
+ windowSize={5}
1629
+ removeClippedSubviews={true}
1630
+ updateCellsBatchingPeriod={50}
1631
+ renderItem={({ item: conversation }) => {
1632
+ // Use custom conversation item view if provided
1633
+ if (conversationItemView) {
1634
+ return (
1635
+ <TouchableOpacity
1636
+ onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1637
+ >
1638
+ {conversationItemView(conversation, searchState.searchText)}
1639
+ </TouchableOpacity>
1640
+ );
1641
+ }
1642
+
1643
+ // Default conversation item rendering
1409
1644
  return (
1410
1645
  <TouchableOpacity
1411
- key={conversation.getConversationId()}
1646
+ style={mergedStyles.conversationItemStyle?.containerStyle}
1412
1647
  onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1413
1648
  >
1414
- {conversationItemView(conversation, searchState.searchText)}
1649
+ {renderConversationLeadingView(conversation)}
1650
+ <View style={mergedStyles.conversationItemStyle?.contentStyle}>
1651
+ <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
1652
+ {conversation.getConversationWith().getName()}
1653
+ </Text>
1654
+ <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
1655
+ {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
1656
+ </Text>
1657
+ </View>
1658
+ {renderConversationTrailingView(conversation)}
1415
1659
  </TouchableOpacity>
1416
1660
  );
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())}
1661
+ }}
1662
+ ListFooterComponent={
1663
+ conversationState.hasMoreResults ? (
1664
+ <TouchableOpacity
1665
+ style={mergedStyles.seeMoreButtonStyle}
1666
+ onPress={loadMoreConversations}
1667
+ disabled={isConversationMoreResultsLoading.current}
1668
+ >
1669
+ <Text style={mergedStyles.seeMoreTextStyle}>
1670
+ {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1433
1671
  </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
- )}
1672
+ </TouchableOpacity>
1673
+ ) : null
1674
+ }
1675
+ />
1450
1676
  </View>
1451
1677
  );
1452
1678
  };
@@ -1496,7 +1722,287 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1496
1722
  return (
1497
1723
  <View>
1498
1724
  <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>
1499
- {messageList.map((message, index) => {
1725
+ <FlatList
1726
+ data={messageList}
1727
+ keyExtractor={(item, index) => `${item.getId()}-${index}`}
1728
+ initialNumToRender={10}
1729
+ maxToRenderPerBatch={5}
1730
+ windowSize={5}
1731
+ removeClippedSubviews={true}
1732
+ updateCellsBatchingPeriod={50}
1733
+ renderItem={({ item: message, index }) => {
1734
+ const messageType = message.getType();
1735
+
1736
+ // Date header logic for media items
1737
+ let dateHeader: React.ReactNode = null;
1738
+ if (['image', 'video'].includes(messageType)) {
1739
+ const sentAt = message.getSentAt();
1740
+ const currentDateStr = getDateHeaderDate(sentAt);
1741
+ const prevMessage = index > 0 ? messageList[index - 1] : null;
1742
+ const prevDateStr = prevMessage ? getDateHeaderDate(prevMessage.getSentAt()) : null;
1743
+
1744
+ if (currentDateStr !== prevDateStr) {
1745
+ dateHeader = (
1746
+ <CometChatDate
1747
+ timeStamp={sentAt * 1000}
1748
+ customDateString={currentDateStr}
1749
+ style={{
1750
+ textStyle: mergedStyles.sectionTitleStyle
1751
+ }}
1752
+ />
1753
+ );
1754
+ }
1755
+ }
1756
+
1757
+ // Check if message is a text message with link preview
1758
+ const isLinkMessage = messageType === 'text' && (() => {
1759
+ const textMessage = message as CometChat.TextMessage;
1760
+ const metadata = textMessage.getMetadata();
1761
+ return metadata && (metadata as any)['@injected'] && (metadata as any)['@injected']['extensions'] && (metadata as any)['@injected']['extensions']['link-preview'];
1762
+ })();
1763
+
1764
+ // Determine which custom view to use based on message type
1765
+ let customView: (() => React.ReactElement) | undefined;
1766
+
1767
+ if (isLinkMessage && linkMessageItemView) {
1768
+ customView = () => linkMessageItemView(message, searchState.searchText);
1769
+ } else if (messageType === 'text' && textMessageItemView) {
1770
+ customView = () => textMessageItemView(message, searchState.searchText);
1771
+ } else if (messageType === 'image' && imageMessageItemView) {
1772
+ customView = () => imageMessageItemView(message, searchState.searchText);
1773
+ } else if (messageType === 'video' && videoMessageItemView) {
1774
+ customView = () => videoMessageItemView(message, searchState.searchText);
1775
+ } else if (messageType === 'audio' && audioMessageItemView) {
1776
+ customView = () => audioMessageItemView(message, searchState.searchText);
1777
+ } else if (messageType === 'file' && documentMessageItemView) {
1778
+ customView = () => documentMessageItemView(message, searchState.searchText);
1779
+ }
1780
+
1781
+ // Use custom view if available
1782
+ if (customView) {
1783
+ return (
1784
+ <View>
1785
+ {dateHeader}
1786
+ <TouchableOpacity
1787
+ onPress={() => onMessageClicked?.(message, searchState.searchText)}
1788
+ >
1789
+ {customView()}
1790
+ </TouchableOpacity>
1791
+ </View>
1792
+ );
1793
+ }
1794
+
1795
+ // Default message item rendering
1796
+ return (
1797
+ <View>
1798
+ {dateHeader}
1799
+ <TouchableOpacity
1800
+ style={mergedStyles.messageItemStyle?.containerStyle}
1801
+ onPress={() => onMessageClicked?.(message, searchState.searchText)}
1802
+ >
1803
+ {renderMessageLeadingView(message)}
1804
+ <View style={[
1805
+ mergedStyles.messageItemStyle?.contentStyle,
1806
+ (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
1807
+ ]}>
1808
+ <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
1809
+ {message.getSender().getName()}
1810
+ </Text>
1811
+ <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
1812
+ {(() => {
1813
+ const messageType = message.getType();
1814
+
1815
+ // For media messages (image, video, file, audio), show file name
1816
+ if (['image', 'video', 'file', 'audio'].includes(messageType)) {
1817
+ const mediaMessage = message as CometChat.MediaMessage;
1818
+ const attachment = mediaMessage.getAttachment?.();
1819
+ return attachment?.getName?.() || messageType;
1820
+ }
1821
+
1822
+ // For text messages, show the text content
1823
+ if (messageType === 'text') {
1824
+ const raw = (message as CometChat.TextMessage).getText?.();
1825
+ const formatted = formatMentionsInText(raw, message);
1826
+ return formatted || messageType || 'Message';
1827
+ }
1828
+
1829
+ // For custom messages, try to localize the type
1830
+ const customTypeKey = `CUSTOM_MESSAGE_${messageType.toUpperCase()}`;
1831
+ const localizedType = t(customTypeKey);
1832
+
1833
+ // If localization exists and is different from key, use it
1834
+ if (localizedType && localizedType !== customTypeKey) {
1835
+ return localizedType;
1836
+ }
1837
+
1838
+ // Handle specific extension types mapping to existing keys
1839
+ if (messageType === 'extension_poll') return t("CUSTOM_MESSAGE_POLL") || "Poll";
1840
+ if (messageType === 'extension_sticker') return t("CUSTOM_MESSAGE_STICKER") || "Sticker";
1841
+ if (messageType === 'extension_whiteboard') return t("CUSTOM_MESSAGE_WHITEBOARD") || "Whiteboard";
1842
+ if (messageType === 'extension_document') return t("CUSTOM_MESSAGE_DOCUMENT") || "Document";
1843
+ if (messageType === 'meeting') return t("meeting") || "Meeting";
1844
+
1845
+ return messageType || 'Message';
1846
+ })()}
1847
+ </Text>
1848
+ </View>
1849
+ <MemoizedTrailingView message={message} />
1850
+ </TouchableOpacity>
1851
+ </View>
1852
+ );
1853
+ }}
1854
+ />
1855
+ </View>
1856
+ );
1857
+ };
1858
+
1859
+ const renderResults = () => {
1860
+ const conversationsRendered = shouldRenderConversations();
1861
+ const messagesRendered = shouldRenderMessages();
1862
+
1863
+ // Initial empty state - no search text and no filters
1864
+ if ((!searchState.searchText || searchState.searchText.trim() === "") && searchState.activeFilters.length === 0) {
1865
+ if (emptyView) {
1866
+ return emptyView();
1867
+ }
1868
+
1869
+ return (
1870
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1871
+ <Icon
1872
+ name="empty-search"
1873
+ size={120}
1874
+ height={120}
1875
+ width={120}
1876
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1877
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1878
+ />
1879
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1880
+ {t("SEARCH_NO_RESULTS_TITLE") || "No Results"}
1881
+ </Text>
1882
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1883
+ {t("SEARCH_NO_RESULTS_SUBTITLE") || "Start typing to search for messages and conversations"}
1884
+ </Text>
1885
+ </View>
1886
+ );
1887
+ }
1888
+
1889
+ // Show loading shimmer if we have search/filters active and both sections are loading
1890
+ if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1891
+ (conversationState.fetchState === States.loading || messageState.fetchState === States.loading) &&
1892
+ conversationState.conversationList.length === 0 &&
1893
+ messageState.messageList.length === 0) {
1894
+ return loadingView ? loadingView() : <Skeleton />;
1895
+ }
1896
+
1897
+ // Check if we have search text or filters but no actual results
1898
+ if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1899
+ conversationState.conversationList.length === 0 &&
1900
+ messageState.messageList.length === 0 &&
1901
+ conversationState.fetchState !== States.loading &&
1902
+ messageState.fetchState !== States.loading &&
1903
+ conversationState.fetchState !== States.error &&
1904
+ messageState.fetchState !== States.error) {
1905
+ // No results found state
1906
+ if (emptyView) {
1907
+ return emptyView();
1908
+ }
1909
+
1910
+ return (
1911
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1912
+ <Icon
1913
+ name="empty-search"
1914
+ size={120}
1915
+ height={120}
1916
+ width={120}
1917
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1918
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1919
+ />
1920
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1921
+ {t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
1922
+ </Text>
1923
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1924
+ {t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
1925
+ </Text>
1926
+ </View>
1927
+ );
1928
+ }
1929
+
1930
+ // Show search results with actual item lists - USING SINGLE FLATLIST FOR VIRTUALIZATION
1931
+ // Create combined data array with section headers
1932
+ type ListItem =
1933
+ | { type: 'conversation-header' }
1934
+ | { type: 'conversation'; data: CometChat.Conversation }
1935
+ | { type: 'conversation-footer' }
1936
+ | { type: 'message-header' }
1937
+ | { type: 'message'; data: CometChat.BaseMessage; index: number }
1938
+ | { type: 'message-footer' };
1939
+
1940
+ const combinedData: ListItem[] = [];
1941
+
1942
+ // Add conversations section if needed
1943
+ if (conversationsRendered && conversationState.conversationList.length > 0) {
1944
+ combinedData.push({ type: 'conversation-header' });
1945
+ conversationState.conversationList.forEach(conv => {
1946
+ combinedData.push({ type: 'conversation', data: conv });
1947
+ });
1948
+ if (conversationState.hasMoreResults) {
1949
+ combinedData.push({ type: 'conversation-footer' });
1950
+ }
1951
+ }
1952
+
1953
+ // Add messages section if needed
1954
+ if (messagesRendered && messageState.messageList.length > 0) {
1955
+ combinedData.push({ type: 'message-header' });
1956
+ messageState.messageList.forEach((msg, index) => {
1957
+ combinedData.push({ type: 'message', data: msg, index });
1958
+ });
1959
+ }
1960
+
1961
+ const keyExtractor = (item: ListItem, index: number) => {
1962
+ if (item.type === 'conversation') {
1963
+ return `conversation-${item.data.getConversationId()}`;
1964
+ } else if (item.type === 'message') {
1965
+ return `message-${item.data.getId()}-${index}`;
1966
+ }
1967
+ return `${item.type}-${index}`;
1968
+ };
1969
+
1970
+ const renderCombinedItem = ({ item }: { item: ListItem }) => {
1971
+ switch (item.type) {
1972
+ case 'conversation-header':
1973
+ return <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>;
1974
+
1975
+ case 'conversation':
1976
+ return (
1977
+ <ConversationItem
1978
+ conversation={item.data}
1979
+ searchText={searchState.searchText}
1980
+ onPress={onConversationClicked || (() => {})}
1981
+ mergedStyles={mergedStyles}
1982
+ theme={theme}
1983
+ conversationItemView={conversationItemView}
1984
+ />
1985
+ );
1986
+
1987
+ case 'conversation-footer':
1988
+ return (
1989
+ <TouchableOpacity
1990
+ style={mergedStyles.seeMoreButtonStyle}
1991
+ onPress={loadMoreConversations}
1992
+ disabled={isConversationMoreResultsLoading.current}
1993
+ >
1994
+ <Text style={mergedStyles.seeMoreTextStyle}>
1995
+ {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1996
+ </Text>
1997
+ </TouchableOpacity>
1998
+ );
1999
+
2000
+ case 'message-header':
2001
+ return <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>;
2002
+
2003
+ case 'message': {
2004
+ const message = item.data;
2005
+ const messageIndex = item.index;
1500
2006
  const messageType = message.getType();
1501
2007
 
1502
2008
  // Date header logic for media items
@@ -1504,8 +2010,8 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1504
2010
  if (['image', 'video'].includes(messageType)) {
1505
2011
  const sentAt = message.getSentAt();
1506
2012
  const currentDateStr = getDateHeaderDate(sentAt);
1507
- const prevMessage = index > 0 ? messageList[index - 1] : null;
1508
- const prevDateStr = prevMessage ? getDateHeaderDate(prevMessage.getSentAt()) : null;
2013
+ const prevItem = messageIndex > 0 ? messageState.messageList[messageIndex - 1] : null;
2014
+ const prevDateStr = prevItem ? getDateHeaderDate(prevItem.getSentAt()) : null;
1509
2015
 
1510
2016
  if (currentDateStr !== prevDateStr) {
1511
2017
  dateHeader = (
@@ -1547,7 +2053,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1547
2053
  // Use custom view if available
1548
2054
  if (customView) {
1549
2055
  return (
1550
- <View key={`${message.getId()}-${index}`}>
2056
+ <View>
1551
2057
  {dateHeader}
1552
2058
  <TouchableOpacity
1553
2059
  onPress={() => onMessageClicked?.(message, searchState.searchText)}
@@ -1560,7 +2066,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1560
2066
 
1561
2067
  // Default message item rendering
1562
2068
  return (
1563
- <View key={`${message.getId()}-${index}`}>
2069
+ <View>
1564
2070
  {dateHeader}
1565
2071
  <TouchableOpacity
1566
2072
  style={mergedStyles.messageItemStyle?.containerStyle}
@@ -1576,24 +2082,24 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1576
2082
  </Text>
1577
2083
  <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
1578
2084
  {(() => {
1579
- const messageType = message.getType();
2085
+ const msgType = message.getType();
1580
2086
 
1581
2087
  // For media messages (image, video, file, audio), show file name
1582
- if (['image', 'video', 'file', 'audio'].includes(messageType)) {
2088
+ if (['image', 'video', 'file', 'audio'].includes(msgType)) {
1583
2089
  const mediaMessage = message as CometChat.MediaMessage;
1584
2090
  const attachment = mediaMessage.getAttachment?.();
1585
- return attachment?.getName?.() || messageType;
2091
+ return attachment?.getName?.() || msgType;
1586
2092
  }
1587
2093
 
1588
2094
  // For text messages, show the text content
1589
- if (messageType === 'text') {
2095
+ if (msgType === 'text') {
1590
2096
  const raw = (message as CometChat.TextMessage).getText?.();
1591
2097
  const formatted = formatMentionsInText(raw, message);
1592
- return formatted || messageType || 'Message';
2098
+ return formatted || msgType || 'Message';
1593
2099
  }
1594
2100
 
1595
2101
  // For custom messages, try to localize the type
1596
- const customTypeKey = `CUSTOM_MESSAGE_${messageType.toUpperCase()}`;
2102
+ const customTypeKey = `CUSTOM_MESSAGE_${msgType.toUpperCase()}`;
1597
2103
  const localizedType = t(customTypeKey);
1598
2104
 
1599
2105
  // If localization exists and is different from key, use it
@@ -1602,107 +2108,48 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1602
2108
  }
1603
2109
 
1604
2110
  // 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";
2111
+ if (msgType === 'extension_poll') return t("CUSTOM_MESSAGE_POLL") || "Poll";
2112
+ if (msgType === 'extension_sticker') return t("CUSTOM_MESSAGE_STICKER") || "Sticker";
2113
+ if (msgType === 'extension_whiteboard') return t("CUSTOM_MESSAGE_WHITEBOARD") || "Whiteboard";
2114
+ if (msgType === 'extension_document') return t("CUSTOM_MESSAGE_DOCUMENT") || "Document";
2115
+ if (msgType === 'meeting') return t("meeting") || "Meeting";
1610
2116
 
1611
- return messageType || 'Message';
2117
+ return msgType || 'Message';
1612
2118
  })()}
1613
2119
  </Text>
1614
2120
  </View>
1615
- {renderMessageTrailingView(message)}
2121
+ <MemoizedTrailingView message={message} />
1616
2122
  </TouchableOpacity>
1617
2123
  </View>
1618
2124
  );
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();
2125
+ }
2126
+
2127
+ default:
2128
+ return null;
1673
2129
  }
2130
+ };
1674
2131
 
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
2132
  return (
1697
- <ScrollView
2133
+ <FlatList
2134
+ data={combinedData}
2135
+ keyExtractor={keyExtractor}
2136
+ renderItem={renderCombinedItem}
1698
2137
  style={[mergedStyles.resultsContainerStyle]}
1699
2138
  contentContainerStyle={{ paddingHorizontal: theme.spacing.padding.p4 }}
1700
2139
  showsVerticalScrollIndicator={false}
1701
- onMomentumScrollEnd={handleScrollEnd}
1702
- >
1703
- {conversationsRendered && renderConversationsSection()}
1704
- {messagesRendered && renderMessagesSection()}
1705
- </ScrollView>
2140
+ initialNumToRender={10}
2141
+ maxToRenderPerBatch={10}
2142
+ windowSize={10}
2143
+ removeClippedSubviews={true}
2144
+ updateCellsBatchingPeriod={100}
2145
+ onEndReached={() => {
2146
+ // Load more messages if we're at the end and messages section is visible
2147
+ if (messagesRendered && messageState.hasMoreResults) {
2148
+ loadMoreMessages();
2149
+ }
2150
+ }}
2151
+ onEndReachedThreshold={0.5}
2152
+ />
1706
2153
  );
1707
2154
  };
1708
2155