@cometchat/chat-uikit-react-native 5.5.1 → 5.5.2

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.
Files changed (66) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/7.4/gc.properties +0 -0
  5. package/android/.gradle/vcs-1/gc.properties +0 -0
  6. package/android/build.gradle +23 -89
  7. package/android/gradle.properties +5 -5
  8. package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +5 -1
  9. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +52 -0
  10. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +17 -4
  11. package/ios/FileManager.m +77 -3
  12. package/ios/RichTextEditorView.swift +9 -1
  13. package/package.json +4 -4
  14. package/react-native-cometchat-ui-kit.podspec +5 -19
  15. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +31 -27
  16. package/src/CometChatConversations/CometChatConversations.tsx +4 -0
  17. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +35 -28
  18. package/src/CometChatMessageList/CometChatMessageList.tsx +20 -18
  19. package/src/CometChatRichTextEditor/index.tsx +2 -1
  20. package/src/CometChatSearch/CometChatSearch.tsx +10 -5
  21. package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +56 -17
  22. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +12 -9
  23. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -10
  24. package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +34 -27
  25. package/src/extensions/Polls/Polls.tsx +7 -7
  26. package/src/extensions/Polls/PollsBubble.tsx +2 -2
  27. package/src/globals.d.ts +6 -0
  28. package/src/shared/constants/textPatterns.ts +20 -2
  29. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +22 -11
  30. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +26 -14
  31. package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -0
  32. package/src/shared/formatters/codeElements.ts +21 -0
  33. package/src/shared/helper/types/index.ts +5 -0
  34. package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +4 -4
  35. package/src/shared/libs/ImageZoom/types/index.ts +2 -0
  36. package/src/shared/resources/CometChatSoundManager/sound.js +2 -3
  37. package/src/shared/services/UploadQueueService.ts +7 -0
  38. package/src/shared/utils/CometChatMessageHelper/index.ts +3 -0
  39. package/src/shared/utils/MarkdownUtils.ts +11 -4
  40. package/src/shared/utils/MessageUtils.tsx +7 -5
  41. package/src/shared/utils/groupMemberAddedRows.ts +28 -0
  42. package/src/shared/utils/linkPreviewSelection.ts +109 -0
  43. package/src/shared/utils/mentionTokens.ts +77 -0
  44. package/src/shared/utils/runAfterInteractions.ts +26 -0
  45. package/src/shared/utils/stripRichText.ts +2 -1
  46. package/src/shared/utils/tapGesture.ts +23 -0
  47. package/src/shared/utils/videoThumbnail.ts +74 -0
  48. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +21 -13
  49. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +13 -15
  50. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +1 -1
  51. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +2 -1
  52. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +2 -1
  53. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +3 -26
  54. package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +4 -2
  55. package/src/shared/views/CometChatList/Header.tsx +1 -1
  56. package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +2 -1
  57. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +28 -8
  58. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -4
  59. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +36 -4
  60. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +2 -1
  61. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +57 -30
  62. package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
  63. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
  64. package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
  65. package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
  66. package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Mention markup a user TYPED or PASTED, as opposed to a mention picked from the suggestion list.
3
+ *
4
+ * `<@uid:…>` / `<@all:…>` in a message's text is the only signal that a mention is real — there
5
+ * is no other metadata for `@all`. So text a user typed that happens to look like a token was
6
+ * sent verbatim and every platform rendered it as a live mention: `<@all:everyone> hi` became an
7
+ * @everyone chip. The cross-platform contract (shared with the React UI Kit) is to store a typed
8
+ * token's `<` as `&lt;` — `&lt;@all:everyone> hi` — and to show that as `<@all:everyone> hi`
9
+ * only after mentions have been resolved, so it can never turn back into a chip.
10
+ */
11
+
12
+ import React from "react";
13
+
14
+ const TYPED_TOKEN_REGEX = /<(@(?:uid|all):)/g;
15
+ const ESCAPED_TOKEN_REGEX = /&lt;(@(?:uid|all):)/g;
16
+
17
+ /** Escapes token-looking text a user typed: `<@all:x>` → `&lt;@all:x>`. */
18
+ export const escapeTypedMentionTokens = (text: string): string =>
19
+ text.indexOf("<@") < 0 ? text : text.replace(TYPED_TOKEN_REGEX, "&lt;$1");
20
+
21
+ /** Display form of an escaped typed token: `&lt;@all:x>` → `<@all:x>`. Run AFTER mention parsing. */
22
+ export const unescapeTypedMentionTokens = (text: string): string =>
23
+ text.indexOf("&lt;@") < 0 ? text : text.replace(ESCAPED_TOKEN_REGEX, "<$1");
24
+
25
+ const hasEscapedToken = (node: any): boolean => {
26
+ if (typeof node === "string") return node.indexOf("&lt;@") >= 0;
27
+ if (Array.isArray(node)) return node.some(hasEscapedToken);
28
+ if (React.isValidElement(node)) return hasEscapedToken((node as React.ReactElement<any>).props.children);
29
+ return false;
30
+ };
31
+
32
+ const unescapeTree = (node: any): any => {
33
+ if (typeof node === "string") return unescapeTypedMentionTokens(node);
34
+ if (Array.isArray(node)) return node.map(unescapeTree);
35
+ if (React.isValidElement(node) && hasEscapedToken(node)) {
36
+ const children = (node as React.ReactElement<any>).props.children;
37
+ return React.cloneElement(node as React.ReactElement<any>, {
38
+ children: Array.isArray(children) ? children.map(unescapeTree) : unescapeTree(children),
39
+ });
40
+ }
41
+ return node;
42
+ };
43
+
44
+ /**
45
+ * {@link unescapeTypedMentionTokens} over every string of a rendered tree. Only the branches
46
+ * holding an escaped token are rebuilt; any other tree — nearly every message — is returned as
47
+ * the same object, so rendering it costs nothing and changes nothing.
48
+ */
49
+ export const unescapeTypedMentionTokensInTree = (node: any): any =>
50
+ hasEscapedToken(node) ? unescapeTree(node) : node;
51
+
52
+ /**
53
+ * Builds the text to send: real mentions (character ranges `"start_end"` in `text`, from the
54
+ * composer's mention map) become their tokens, and everything the user typed between them is
55
+ * escaped. Ranges are applied in position order, whatever order the map holds them in.
56
+ */
57
+ export const insertMentionTokens = (
58
+ text: string,
59
+ mentions: Iterable<[string, { underlyingText: string }]>
60
+ ): string => {
61
+ const ranges = [...mentions]
62
+ .map(([key, value]) => {
63
+ const [start, end] = key.split("_").map(Number);
64
+ return { start, end, token: value.underlyingText };
65
+ })
66
+ .filter((r) => Number.isFinite(r.start) && Number.isFinite(r.end))
67
+ .sort((a, b) => a.start - b.start);
68
+
69
+ let out = "";
70
+ let last = 0;
71
+ for (const { start, end, token } of ranges) {
72
+ if (start < last) continue; // overlapping range — skip it rather than corrupt the text
73
+ out += escapeTypedMentionTokens(text.substring(last, start)) + token;
74
+ last = end;
75
+ }
76
+ return out + escapeTypedMentionTokens(text.substring(last));
77
+ };
@@ -0,0 +1,26 @@
1
+ import { Platform } from "react-native";
2
+
3
+ /**
4
+ * Stand-in for `InteractionManager.runAfterInteractions`, which React Native 0.87 removed
5
+ * (touching it throws in dev and is `undefined` in release).
6
+ *
7
+ * - RN < 0.82: `InteractionManager` still waits for running animations and navigation
8
+ * transitions, so it is used as before and apps on older RN keep the exact old timing.
9
+ * - RN >= 0.82: it had already stopped honouring interaction handles, so all it did was
10
+ * defer the callback past the current JS turn. That is what `setTimeout(task, 0)` does,
11
+ * without touching the removed module. `requestIdleCallback` is deliberately not used: it
12
+ * can hold the callback back for a long time, and these call sites move the caret or clear
13
+ * the input right after an edit.
14
+ */
15
+ const rnVersion = Platform.constants?.reactNativeVersion;
16
+ const hasLegacyInteractionManager =
17
+ !!rnVersion && rnVersion.major === 0 && rnVersion.minor < 82;
18
+
19
+ export function runAfterInteractions(task: () => void): void {
20
+ if (hasLegacyInteractionManager) {
21
+ // Required lazily: on RN 0.87 even reading this export throws.
22
+ require("react-native").InteractionManager.runAfterInteractions(task);
23
+ return;
24
+ }
25
+ setTimeout(task, 0);
26
+ }
@@ -7,6 +7,7 @@
7
7
  * as "make a <product>" or "5 < 10" is preserved.
8
8
  */
9
9
  import { stripColorTags } from "../formatters/richTextWireFormat";
10
+ import { markdownLinkPattern } from "../constants/textPatterns";
10
11
 
11
12
  export const stripRichText = (input?: string | null): string => {
12
13
  if (!input) return "";
@@ -41,7 +42,7 @@ export const stripRichText = (input?: string | null): string => {
41
42
  .replace(/(^|[^A-Za-z0-9_])_\s*(.+?)\s*_(?![A-Za-z0-9_])/g, "$1$2") // _italic_
42
43
  .replace(/~~(.+?)~~/g, "$1") // ~~strikethrough~~
43
44
  .replace(/`([^`]+)`/g, "$1") // `inline code`
44
- .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1"); // [label](url) -> label
45
+ .replace(new RegExp(markdownLinkPattern, "g"), "$1"); // [label](url) -> label
45
46
 
46
47
  // 3. Collapse leftover whitespace into a single clean line.
47
48
  return text.replace(/\s+/g, " ").trim();
@@ -0,0 +1,23 @@
1
+ import { GestureResponderEvent } from 'react-native';
2
+
3
+ // Same tolerances as React Native's Pressability: a touch is still a tap within 10pt of where it started.
4
+ export const TAP_SLOP = 10;
5
+ // A longer hold is a long-press (the bubble's message options), not a tap.
6
+ export const TAP_MAX_MS = 500;
7
+
8
+ export interface TouchStart {
9
+ x: number;
10
+ y: number;
11
+ at: number;
12
+ }
13
+
14
+ export const touchStartOf = (e: GestureResponderEvent, now = Date.now()): TouchStart => ({
15
+ x: e.nativeEvent.pageX,
16
+ y: e.nativeEvent.pageY,
17
+ at: now,
18
+ });
19
+
20
+ export const movedBeyondSlop = (start: TouchStart, e: GestureResponderEvent): boolean =>
21
+ Math.abs(e.nativeEvent.pageX - start.x) > TAP_SLOP || Math.abs(e.nativeEvent.pageY - start.y) > TAP_SLOP;
22
+
23
+ export const isTapDuration = (start: TouchStart, now = Date.now()): boolean => now - start.at < TAP_MAX_MS;
@@ -0,0 +1,74 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { NativeModules } from 'react-native';
3
+
4
+ const { FileManager } = NativeModules;
5
+
6
+ // Long edge of the generated JPEG — tray tiles and grid cells are at most ~200pt, so this stays sharp
7
+ // on 3x screens while keeping each file a few KB.
8
+ const THUMBNAIL_MAX_SIZE = 480;
9
+
10
+ // Local video uri → its thumbnail (in flight or done), so the tray tile and the bubble share one native call.
11
+ const byLocalUri = new Map<string, Promise<string | null>>();
12
+ // Resolved thumbnails, so a component can render the thumbnail on its first frame instead of after a tick.
13
+ const resolved = new Map<string, string>();
14
+ // Uploaded video url (without the signed query string) → the local file it came from.
15
+ const localUriByRemoteUrl = new Map<string, string>();
16
+
17
+ const withoutQuery = (url: string) => url.split('?')[0];
18
+
19
+ /** First-frame JPEG of a LOCAL video file, generated natively. Resolves null when unavailable. */
20
+ export function getLocalVideoThumbnail(localUri: string): Promise<string | null> {
21
+ const cached = byLocalUri.get(localUri);
22
+ if (cached) return cached;
23
+ const pending: Promise<string | null> = typeof FileManager?.getVideoThumbnail === 'function'
24
+ ? FileManager.getVideoThumbnail(localUri, THUMBNAIL_MAX_SIZE)
25
+ .then((thumbnailUri: string) => {
26
+ resolved.set(localUri, thumbnailUri);
27
+ return thumbnailUri;
28
+ })
29
+ .catch(() => null)
30
+ : Promise.resolve(null);
31
+ byLocalUri.set(localUri, pending);
32
+ return pending;
33
+ }
34
+
35
+ /**
36
+ * Remembers which local file an uploaded video came from, so the sender's bubble (which only knows the
37
+ * uploaded url) can show the local thumbnail straight away. Also starts generating it.
38
+ */
39
+ export function linkUploadedVideo(remoteUrl: string | undefined, localUri: string | undefined): void {
40
+ if (!remoteUrl || !localUri) return;
41
+ localUriByRemoteUrl.set(withoutQuery(remoteUrl), localUri);
42
+ getLocalVideoThumbnail(localUri);
43
+ }
44
+
45
+ function localUriFor(source: { localUri?: string; remoteUrl?: string }): string | undefined {
46
+ if (source.localUri) return source.localUri;
47
+ return source.remoteUrl ? localUriByRemoteUrl.get(withoutQuery(source.remoteUrl)) : undefined;
48
+ }
49
+
50
+ /**
51
+ * Local first-frame thumbnail for a video, by its local file uri (tray) or its uploaded url (a bubble
52
+ * this device sent). `undefined` while generating, `null` when there is none — no local file (e.g. a
53
+ * video received from someone else), generation failed, or the native method isn't available.
54
+ */
55
+ export function useLocalVideoThumbnail(source: { localUri?: string; remoteUrl?: string }): string | null | undefined {
56
+ const localUri = localUriFor(source);
57
+ const [thumbnail, setThumbnail] = useState<string | null | undefined>(() =>
58
+ localUri ? resolved.get(localUri) : null
59
+ );
60
+ useEffect(() => {
61
+ if (!localUri) {
62
+ setThumbnail(null);
63
+ return;
64
+ }
65
+ let active = true;
66
+ getLocalVideoThumbnail(localUri).then((uri) => {
67
+ if (active) setThumbnail(uri);
68
+ });
69
+ return () => {
70
+ active = false;
71
+ };
72
+ }, [localUri]);
73
+ return thumbnail;
74
+ }
@@ -22,6 +22,7 @@ import { deepMerge } from '../../helper/helperFunctions';
22
22
  import { SelectedAttachment } from '../../modals/SelectedAttachment';
23
23
  import { Icon } from '../../icons/Icon';
24
24
  import { getFileTypeIcon } from '../../constants/UIKitConstants';
25
+ import { useLocalVideoThumbnail } from '../../utils/videoThumbnail';
25
26
 
26
27
  const { SoundPlayer } = NativeModules;
27
28
 
@@ -459,6 +460,8 @@ export const CometChatAttachmentTile = ({
459
460
  style ?? {}
460
461
  );
461
462
  const { fileId, file, uploadState, uploadProgress } = attachment;
463
+ const isVideo = file.type.startsWith('video/');
464
+ const videoThumbnail = useLocalVideoThumbnail({ localUri: isVideo ? file.uri : undefined });
462
465
 
463
466
  // Audio (audio/*) renders as a player card (play/pause + seek + time), not the file card.
464
467
  if (file.type.startsWith('audio/')) {
@@ -670,24 +673,29 @@ export const CometChatAttachmentTile = ({
670
673
  borderColor: theme.color.error,
671
674
  }, s.mediaTileStyle]}
672
675
  >
673
- {file.type.startsWith('video/') ? (
674
- // A local video file can't render as an <Image>, so show its FIRST FRAME via a paused,
675
- // muted react-native-video (no controls, never plays) as the thumbnail. The dark scrim
676
- // sits behind it so the tile reads as a video before the frame decodes.
676
+ {isVideo ? (
677
+ // A local video file can't render as an <Image>: show its natively generated first-frame
678
+ // JPEG. Only if that isn't available, fall back to a paused, muted react-native-video
679
+ // (a full player per tile — heavy with several videos). The dark scrim sits behind so
680
+ // the tile reads as a video before either appears.
677
681
  <>
678
682
  <View
679
683
  pointerEvents="none"
680
684
  style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaScrim }}
681
685
  />
682
- <Video
683
- source={{ uri: file.uri }}
684
- paused
685
- muted
686
- repeat={false}
687
- controls={false}
688
- resizeMode="cover"
689
- style={styles.fill}
690
- />
686
+ {videoThumbnail ? (
687
+ <Image source={{ uri: videoThumbnail }} style={styles.fill} resizeMode="cover" />
688
+ ) : videoThumbnail === null ? (
689
+ <Video
690
+ source={{ uri: file.uri }}
691
+ paused
692
+ muted
693
+ repeat={false}
694
+ controls={false}
695
+ resizeMode="cover"
696
+ style={styles.fill}
697
+ />
698
+ ) : null}
691
699
  </>
692
700
  ) : (
693
701
  <Image
@@ -1,11 +1,11 @@
1
1
  import React, { JSX, useCallback, useEffect, useRef, useState } from "react";
2
2
  import {
3
3
  EmitterSubscription,
4
+ GestureResponderEvent,
4
5
  ImageSourcePropType,
5
6
  ImageStyle,
6
7
  NativeEventEmitter,
7
8
  NativeModules,
8
- Platform,
9
9
  StyleProp,
10
10
  Text,
11
11
  TextStyle,
@@ -15,6 +15,7 @@ import {
15
15
  import { Icon } from "../../icons/Icon";
16
16
  import { AnimatedAudioWaves } from "./AnimatedAudioWaves";
17
17
  import { audioPlaybackCoordinator } from "../../utils/audioPlaybackCoordinator";
18
+ import { TouchStart, isTapDuration, movedBeyondSlop, touchStartOf } from "../../utils/tapGesture";
18
19
 
19
20
  const { SoundPlayer } = NativeModules;
20
21
  const eventEmitter = new NativeEventEmitter(SoundPlayer);
@@ -128,7 +129,8 @@ export const CometChatAudioBubble = ({
128
129
  // Native fires soundPlayStatus on natural completion AND when a new play() replaces this clip.
129
130
  // Interrupt echo (we were interrupted) → ignore; genuine finish → reset to idle.
130
131
  useEffect(() => {
131
- subRef.current = eventEmitter.addListener("soundPlayStatus", (data) => {
132
+ subRef.current = eventEmitter.addListener("soundPlayStatus", (event) => {
133
+ const data = event as { url?: string };
132
134
  if (audioUrl !== data.url) return;
133
135
  if (wasInterruptedRef.current) return;
134
136
  setStatus("");
@@ -173,25 +175,21 @@ export const CometChatAudioBubble = ({
173
175
  if (audioUrl) play(currentTimeRef.current || 0);
174
176
  };
175
177
 
176
- const pressTime = useRef<number | null>(0);
178
+ // Raw touches (not a Touchable) so the bubble's long-press and the list's scroll keep working.
179
+ // A finger always moves a little during a tap: only a move past the slop cancels it (a scroll).
180
+ const press = useRef<TouchStart | null>(null);
177
181
 
178
- const handleTouchStart = () => {
179
- pressTime.current = Date.now();
182
+ const handleTouchStart = (e: GestureResponderEvent) => {
183
+ press.current = touchStartOf(e);
180
184
  };
181
185
 
182
186
  const handleTouchEnd = () => {
183
- if (pressTime.current === null && Platform.OS === "ios") return;
184
- const endTime = Date.now();
185
- const pressDuration = endTime - (pressTime.current ?? 0);
186
- if (pressDuration < 500) {
187
- playPauseAudio();
188
- }
187
+ if (press.current && isTapDuration(press.current)) playPauseAudio();
188
+ press.current = null;
189
189
  };
190
190
 
191
- const onTouchMove = () => {
192
- if (Platform.OS === "ios") {
193
- pressTime.current = null;
194
- }
191
+ const onTouchMove = (e: GestureResponderEvent) => {
192
+ if (press.current && movedBeyondSlop(press.current, e)) press.current = null;
195
193
  };
196
194
 
197
195
  const displayDuration = useCallback(
@@ -279,7 +279,7 @@ const CometChatEmojiKeyboard: React.FC<CometChatEmojiKeyboardProps> = ({
279
279
  showsVerticalScrollIndicator={false}
280
280
  style={styles.flatList}
281
281
  initialNumToRender={80}
282
- removeClippedSubviews={true}
282
+ removeClippedSubviews={Platform.OS !== 'android'} // ENG-40210: clipping crashes Fabric on Android
283
283
  />
284
284
  );
285
285
  };
@@ -87,7 +87,8 @@ export const CometChatFileBubble = ({
87
87
  if (Platform.OS == "android") {
88
88
  listener = eventEmitter.addListener(
89
89
  "downloadComplete",
90
- (data: { downloadId: number }) => {
90
+ (event) => {
91
+ const data = event as { downloadId: number };
91
92
  if (data.downloadId && downloadIdRef.current && data.downloadId == downloadIdRef.current) {
92
93
  setProcessing(false);
93
94
  setFileExists(true);
@@ -83,7 +83,8 @@ export function CometChatFilesBubble({
83
83
  const pendingOpensRef = useRef<Record<string, { url: string; name: string; key: string }>>({});
84
84
  useEffect(() => {
85
85
  if (Platform.OS !== 'android') return;
86
- const sub = fileEventEmitter.addListener('downloadComplete', (data: { downloadId: number }) => {
86
+ const sub = fileEventEmitter.addListener('downloadComplete', (event) => {
87
+ const data = event as { downloadId: number };
87
88
  const pending = pendingOpensRef.current[String(data?.downloadId)];
88
89
  if (pending) {
89
90
  FileManager?.openFile?.(pending.url, pending.name, () => {});
@@ -6,7 +6,6 @@ import { useTheme } from '../../../theme';
6
6
  import { useCompTheme } from '../../../theme/hook';
7
7
  import { deepMerge } from '../../helper/helperFunctions';
8
8
  import { CometChatUIKit } from '../../CometChatUiKit';
9
- import { CometChatMessageEvents } from '../../events/CometChatMessageEvents';
10
9
  import { CometChatMediaViewer } from '../CometChatMediaViewer';
11
10
  import { CometChatCaptionText } from '../CometChatCaptionText';
12
11
  import { Icon } from '../../icons/Icon';
@@ -81,14 +80,14 @@ const ImageCell = ({
81
80
  {showPlaceholder ? (
82
81
  <View
83
82
  testID="grid-cell-nopreview"
84
- style={[StyleSheet.absoluteFillObject, borderStyle, { backgroundColor: theme.color.neutral200, justifyContent: 'center', alignItems: 'center' }]}
83
+ style={[StyleSheet.absoluteFill, borderStyle, { backgroundColor: theme.color.neutral200, justifyContent: 'center', alignItems: 'center' }]}
85
84
  >
86
85
  <Icon name="unknown-file-type" size={theme.spacing.spacing.s12} />
87
86
  </View>
88
87
  ) : (
89
88
  <Image
90
89
  source={{ uri: attachment.getUrl() }}
91
- style={[StyleSheet.absoluteFillObject, borderStyle]}
90
+ style={[StyleSheet.absoluteFill, borderStyle]}
92
91
  resizeMode="cover"
93
92
  onError={() => setFailed(true)}
94
93
  />
@@ -98,7 +97,7 @@ const ImageCell = ({
98
97
  <View
99
98
  testID="grid-overflow"
100
99
  pointerEvents="none"
101
- style={[StyleSheet.absoluteFillObject, { backgroundColor: theme.color.mediaOverlay, justifyContent: 'center', alignItems: 'center' }, overflowOverlayStyle]}
100
+ style={[StyleSheet.absoluteFill, { backgroundColor: theme.color.mediaOverlay, justifyContent: 'center', alignItems: 'center' }, overflowOverlayStyle]}
102
101
  >
103
102
  {/* heading1.bold = { fontSize: 24, fontWeight: '700' }; letterSpacing -0.5 is a micro-adjust. */}
104
103
  <Text style={[{ ...theme.typography.heading1.bold, color: theme.color.staticWhite, letterSpacing: -0.5 }, overflowTextStyle]}>{`+${overflowCount}`}</Text>
@@ -244,28 +243,6 @@ export function CometChatImagesBubble({
244
243
  const caption = message.getCaption() ?? '';
245
244
  const isSentByMe = message.getSender()?.getUid() === CometChatUIKit.loggedInUser?.getUid();
246
245
 
247
- // §8.7 — refresh the local copy when the server edits the message in.
248
- useEffect(() => {
249
- const listenerId = `ImagesBubble_${message.getId?.() ?? message.getMuid?.() ?? Date.now()}`;
250
- CometChatMessageEvents.addListener(
251
- CometChatMessageEvents.messageEdited,
252
- listenerId,
253
- (edited: CometChat.BaseMessage) => {
254
- const editedId = edited.getId?.();
255
- const editedMuid = edited.getMuid?.();
256
- const myId = message.getId?.();
257
- const myMuid = message.getMuid?.();
258
- if (
259
- edited instanceof CometChat.MediaMessage &&
260
- ((myId && editedId && myId === editedId) || (myMuid && editedMuid && myMuid === editedMuid))
261
- ) {
262
- setMessage(edited);
263
- }
264
- }
265
- );
266
- return () => CometChatMessageEvents.removeListener(CometChatMessageEvents.messageEdited, listenerId);
267
- }, []);
268
-
269
246
  useEffect(() => {
270
247
  setMessage(initialMessage);
271
248
  }, [initialMessage]);
@@ -322,7 +322,8 @@ export function useAudioRecorder(): UseAudioRecorderReturn {
322
322
 
323
323
  if (reducerState.state === 'recording') {
324
324
  // Listen for native amplitude events
325
- subscription = FileManagerEmitter.addListener('audioAmplitude', (event: { amplitude: number }) => {
325
+ subscription = FileManagerEmitter.addListener('audioAmplitude', (data) => {
326
+ const event = data as { amplitude: number };
326
327
  const amplitude = event.amplitude;
327
328
 
328
329
  // WhatsApp-style amplitude processing:
@@ -371,7 +372,8 @@ export function useAudioRecorder(): UseAudioRecorderReturn {
371
372
 
372
373
  if (reducerState.state === 'playing') {
373
374
  // Listen for playback complete event from native
374
- statusSubscription = FileManagerEmitter.addListener('status', (event: { state: string }) => {
375
+ statusSubscription = FileManagerEmitter.addListener('status', (data) => {
376
+ const event = data as { state: string };
375
377
  // Ignore playback complete during seeking - it might be stale
376
378
  if (event.state === 'playbackComplete' && !isSeekingRef.current) {
377
379
  dispatch({ type: 'PLAYBACK_COMPLETE' });
@@ -176,7 +176,7 @@ export default function Header({
176
176
  }: HeaderProps) {
177
177
  const theme = useTheme();
178
178
  const { t } = useCometChatTranslation();
179
- const inputRef = useRef<TextInput>(null);
179
+ const inputRef = useRef<React.ComponentRef<typeof TextInput>>(null);
180
180
  // Callers that pass nothing used to get a hardcoded English "Search", which
181
181
  // is why the conversation list's search box stayed English in every locale.
182
182
  const searchPlaceholder = searchPlaceholderText ?? t("SEARCH");
@@ -80,7 +80,8 @@ export const CometChatAudioPreview = ({
80
80
  }, [audioUrl]);
81
81
 
82
82
  useEffect(() => {
83
- listener = eventEmitter.addListener("soundPlayStatus", (data) => {
83
+ listener = eventEmitter.addListener("soundPlayStatus", (event) => {
84
+ const data = event as { url?: string };
84
85
  if (audioUrl === data.url) {
85
86
  // playback ended for this url — reset to idle, clear interval and reset time
86
87
  setStatus("");
@@ -28,6 +28,7 @@ import Video from 'react-native-video';
28
28
  import { Icon } from '../../icons/Icon';
29
29
  import { useTheme } from '../../../theme';
30
30
  import { useCometChatTranslation } from '../../resources/CometChatLocalizeNew';
31
+ import { ReactNativeZoomableView } from '../../libs/ImageZoom';
31
32
  import { clampIndex, isImageMime, isVideoMime, nextIndexForSwipe } from './mediaViewerUtils';
32
33
 
33
34
  /** Default: an item is previewable if it's an image or a video. A per-kind bubble (ImagesBubble /
@@ -108,7 +109,14 @@ export const CometChatMediaViewer = ({
108
109
  mediaItemsRef.current = mediaItems;
109
110
  }, [mediaItems]);
110
111
 
112
+ // While an image is zoomed in, drags pan the image instead of paging.
113
+ const zoomedRef = useRef(false);
114
+ const onZoomChange = (_e: unknown, _gs: unknown, zoom: { zoomLevel: number }) => {
115
+ zoomedRef.current = zoom.zoomLevel > 1.01;
116
+ };
117
+
111
118
  const goTo = (idx: number) => {
119
+ zoomedRef.current = false;
112
120
  const clamped = clampIndex(idx, mediaItemsRef.current.length);
113
121
  currentIndexRef.current = clamped;
114
122
  setCurrentIndex(clamped);
@@ -122,7 +130,9 @@ export const CometChatMediaViewer = ({
122
130
  PanResponder.create({
123
131
  // Swipe-to-page only on IMAGE pages. On video pages the native controls own all gestures
124
132
  // (scrubbing is horizontal too), so we don't hijack them — page via the on-screen arrows (B3).
125
- onMoveShouldSetPanResponder: (_, gs) => {
133
+ onMoveShouldSetPanResponder: (evt, gs) => {
134
+ // Never page during a pinch or while zoomed in.
135
+ if (zoomedRef.current || evt.nativeEvent.touches.length > 1) return false;
126
136
  const it = mediaItemsRef.current[currentIndexRef.current];
127
137
  const onVideo = it ? isVideoMime(it.getMimeType?.() ?? '') : false;
128
138
  return !onVideo && Math.abs(gs.dx) > 10 && Math.abs(gs.dx) > Math.abs(gs.dy);
@@ -288,13 +298,23 @@ export const CometChatMediaViewer = ({
288
298
  )}
289
299
  </View>
290
300
  ) : (
291
- <Image
292
- source={{ uri: current.getUrl() }}
293
- style={styles.fullMedia}
294
- resizeMode="contain"
295
- onLoad={() => setMediaLoaded(true)}
296
- onError={() => { setMediaError(true); setMediaLoaded(true); }}
297
- />
301
+ // Pinch / double-tap to zoom. `key` resets the zoom on every page change. At 1x the zoom view
302
+ // hands a horizontal drag to the pager's PanResponder above; zoomed in, it keeps it to pan.
303
+ <ReactNativeZoomableView
304
+ key={currentIndex}
305
+ disablePanOnInitialZoom
306
+ onZoomAfter={onZoomChange}
307
+ onTransform={(z: { zoomLevel: number }) => onZoomChange(null, null, z)}
308
+ onPanResponderTerminationRequest={() => !zoomedRef.current}
309
+ >
310
+ <Image
311
+ source={{ uri: current.getUrl() }}
312
+ style={styles.fullMedia}
313
+ resizeMode="contain"
314
+ onLoad={() => setMediaLoaded(true)}
315
+ onError={() => { setMediaError(true); setMediaLoaded(true); }}
316
+ />
317
+ </ReactNativeZoomableView>
298
318
  )}
299
319
  </View>
300
320
 
@@ -1,9 +1,8 @@
1
1
  import React, { JSX, RefObject } from "react";
2
2
  import {
3
3
  ColorValue,
4
- NativeSyntheticEvent,
5
4
  TextInput,
6
- TextInputSelectionChangeEventData,
5
+ TextInputProps,
7
6
  TextStyle,
8
7
  View,
9
8
  ViewStyle,
@@ -79,9 +78,9 @@ export interface CometChatMessageInputInterface {
79
78
  /**
80
79
  * Callback for when the text selection changes.
81
80
  *
82
- * @param {NativeSyntheticEvent<TextInputSelectionChangeEventData>} event - The selection change event.
81
+ * @param {NativeSyntheticEvent} event - The selection change event.
83
82
  */
84
- onSelectionChange?: (e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => void;
83
+ onSelectionChange?: TextInputProps["onSelectionChange"];
85
84
  /**
86
85
  * Reference for the TextInput component.
87
86
  *
@@ -9,6 +9,7 @@ import {
9
9
  LayoutChangeEvent,
10
10
  TextLayoutEvent,
11
11
  Platform,
12
+ StyleSheet,
12
13
  } from "react-native";
13
14
  import {
14
15
  CometChatMentionsFormatter,
@@ -48,6 +49,32 @@ export const CometChatTextBubble = (props: CometChatTextBubbleInterface) => {
48
49
  );
49
50
  };
50
51
 
52
+ const FONT_METRIC_KEYS = ["fontWeight", "fontStyle", "fontFamily", "fontSize"] as const;
53
+
54
+ /** True when some element in the tree sets its own font (bold, italic, code, a mention chip…). */
55
+ function hasNestedFontStyle(node: React.ReactNode): boolean {
56
+ if (Array.isArray(node)) return node.some(hasNestedFontStyle);
57
+ if (!React.isValidElement(node)) return false;
58
+ const props: any = node.props;
59
+ const style = StyleSheet.flatten(props.style) as TextStyle | undefined;
60
+ if (style && FONT_METRIC_KEYS.some((key) => style[key] != null)) return true;
61
+ return hasNestedFontStyle(props.children);
62
+ }
63
+
64
+ /**
65
+ * On Android a lineHeight makes the text a wrapping (non-boring) layout, and with nested font
66
+ * styles React Native sizes the Text a fraction narrower than the styled text draws: the last
67
+ * word of `**Tom & Jerry**` wraps onto a line the bubble has no room for and "Jerry" disappears.
68
+ * Such content uses the font's own line spacing instead; plain text keeps the theme's lineHeight.
69
+ */
70
+ function withMeasurableLineHeight(
71
+ textStyle: StyleProp<TextStyle> | undefined,
72
+ content: React.ReactNode
73
+ ): StyleProp<TextStyle> | undefined {
74
+ if (Platform.OS !== "android" || !hasNestedFontStyle(content)) return textStyle;
75
+ return [textStyle, { lineHeight: undefined }];
76
+ }
77
+
51
78
  /**
52
79
  * Recursively apply textStyle to all Text elements within a tree.
53
80
  * Needed for View-based content (blockquotes, lists) where Text nodes
@@ -112,6 +139,11 @@ export const CometChatTextBubbleText = (
112
139
  return finalText as string | JSX.Element;
113
140
  }, [text, textFormatters]);
114
141
 
142
+ const contentTextStyle = useMemo(
143
+ () => withMeasurableLineHeight(textStyle, formattedText),
144
+ [textStyle, formattedText]
145
+ );
146
+
115
147
  // Reset state only when text actually changes
116
148
  useLayoutEffect(() => {
117
149
  if (lastTextRef.current !== text) {
@@ -192,9 +224,9 @@ export const CometChatTextBubbleText = (
192
224
  if (!viewChildren) return null;
193
225
  return viewChildren.map((child) => {
194
226
  if (!React.isValidElement(child)) return child;
195
- return applyTextStyleDeep(child as React.ReactElement<any>, textStyle);
227
+ return applyTextStyleDeep(child as React.ReactElement<any>, contentTextStyle);
196
228
  });
197
- }, [viewChildren, textStyle]);
229
+ }, [viewChildren, contentTextStyle]);
198
230
 
199
231
  // Only measure string content via onTextLayout — View-based uses child count instead
200
232
  const needsMeasurement = containerWidth !== null && !isViewBased && !measuredCacheRef.current[hiddenTextKey];
@@ -207,7 +239,7 @@ export const CometChatTextBubbleText = (
207
239
  key={hiddenTextKey}
208
240
  style={[
209
241
  { position: "absolute", left: 0, top: -10000, width: containerWidth!, opacity: 0 },
210
- textStyle as any,
242
+ contentTextStyle as any,
211
243
  ]}
212
244
  onTextLayout={onMeasuredTextLayout}
213
245
  accessible={false}
@@ -224,7 +256,7 @@ export const CometChatTextBubbleText = (
224
256
  </View>
225
257
  ) : (
226
258
  <Text
227
- style={textStyle}
259
+ style={contentTextStyle}
228
260
  numberOfLines={isExpanded ? undefined : collapseLines}
229
261
  ellipsizeMode='tail'
230
262
  >