@cometchat/chat-uikit-react-native 5.5.1 → 5.5.3
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.
- package/android/build.gradle +35 -89
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +5 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +52 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +235 -4
- package/ios/FileManager.m +77 -3
- package/ios/RichTextEditorView.swift +234 -24
- package/package.json +7 -4
- package/react-native-cometchat-ui-kit.podspec +5 -19
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +31 -27
- package/src/CometChatConversations/CometChatConversations.tsx +4 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +35 -28
- package/src/CometChatMessageList/CometChatMessageList.tsx +20 -18
- package/src/CometChatRichTextEditor/index.tsx +2 -1
- package/src/CometChatSearch/CometChatSearch.tsx +10 -5
- package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +56 -17
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +12 -9
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -10
- package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +34 -27
- package/src/extensions/Polls/Polls.tsx +7 -7
- package/src/extensions/Polls/PollsBubble.tsx +2 -2
- package/src/globals.d.ts +6 -0
- package/src/shared/constants/textPatterns.ts +20 -2
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +22 -11
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +26 -14
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -0
- package/src/shared/formatters/codeElements.ts +21 -0
- package/src/shared/helper/types/index.ts +5 -0
- package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +4 -4
- package/src/shared/libs/ImageZoom/types/index.ts +2 -0
- package/src/shared/resources/CometChatSoundManager/sound.js +2 -3
- package/src/shared/services/UploadQueueService.ts +7 -0
- package/src/shared/utils/CometChatMessageHelper/index.ts +3 -0
- package/src/shared/utils/MarkdownUtils.ts +11 -4
- package/src/shared/utils/MessageUtils.tsx +7 -5
- package/src/shared/utils/groupMemberAddedRows.ts +28 -0
- package/src/shared/utils/linkPreviewSelection.ts +109 -0
- package/src/shared/utils/mentionTokens.ts +77 -0
- package/src/shared/utils/runAfterInteractions.ts +26 -0
- package/src/shared/utils/stripRichText.ts +2 -1
- package/src/shared/utils/tapGesture.ts +23 -0
- package/src/shared/utils/videoThumbnail.ts +74 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +21 -13
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +13 -15
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +1 -1
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +2 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +2 -1
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +3 -26
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +4 -2
- package/src/shared/views/CometChatList/Header.tsx +1 -1
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +2 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +28 -8
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -4
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +36 -4
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +2 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +57 -30
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
package/ios/FileManager.m
CHANGED
|
@@ -53,6 +53,16 @@ static NSString *const FIELD_SIZE = @"size";
|
|
|
53
53
|
hasListeners = YES;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// The pickers share one `callback` slot, so a picker must TAKE it the moment it finishes (and clear the
|
|
57
|
+
// slot) rather than read it later. Otherwise a slow pick (PHPicker loading several videos) fires whatever
|
|
58
|
+
// callback a NEWER pick stored in the meantime — invoking that block twice, which RN aborts on
|
|
59
|
+
// ("Callback arg cannot be called more than once").
|
|
60
|
+
- (RCTResponseSenderBlock)takeCallback {
|
|
61
|
+
RCTResponseSenderBlock cb = callback;
|
|
62
|
+
callback = nil;
|
|
63
|
+
return cb;
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
- (void)stopObserving {
|
|
57
67
|
hasListeners = NO;
|
|
58
68
|
}
|
|
@@ -372,6 +382,52 @@ RCT_EXPORT_METHOD(openFileChooser:(NSString *)type callback:(RCTResponseSenderBl
|
|
|
372
382
|
}
|
|
373
383
|
|
|
374
384
|
|
|
385
|
+
// Small JPEG of a local video's first frame, so a picked/sent video has a thumbnail without waiting for
|
|
386
|
+
// the server's thumbnail-generation extension (which publishes its URL before the image exists).
|
|
387
|
+
// Cached in Caches/ by source path, so repeat calls for the same file are instant.
|
|
388
|
+
RCT_EXPORT_METHOD(getVideoThumbnail:(NSString *)uri maxSize:(nonnull NSNumber *)maxSize resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
389
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
|
390
|
+
NSURL *videoURL = [uri hasPrefix:@"/"] ? [NSURL fileURLWithPath:uri] : [NSURL URLWithString:uri];
|
|
391
|
+
if (!videoURL) {
|
|
392
|
+
reject(@"invalid_uri", @"Invalid video uri", nil);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
NSString *dir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject
|
|
396
|
+
stringByAppendingPathComponent:@"cometchat-video-thumbnails"];
|
|
397
|
+
[[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
|
|
398
|
+
NSString *key = [NSString stringWithFormat:@"%lu_%lu_%@", (unsigned long)videoURL.path.hash,
|
|
399
|
+
(unsigned long)videoURL.path.length, maxSize];
|
|
400
|
+
NSString *thumbPath = [dir stringByAppendingPathComponent:[key stringByAppendingPathExtension:@"jpg"]];
|
|
401
|
+
if ([[NSFileManager defaultManager] fileExistsAtPath:thumbPath]) {
|
|
402
|
+
resolve([NSURL fileURLWithPath:thumbPath].absoluteString);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
|
|
407
|
+
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
|
|
408
|
+
generator.appliesPreferredTrackTransform = YES; // keep portrait videos upright
|
|
409
|
+
CGFloat side = maxSize.doubleValue > 0 ? maxSize.doubleValue : 320;
|
|
410
|
+
generator.maximumSize = CGSizeMake(side, side);
|
|
411
|
+
// Nearest keyframe is fine for a preview and much faster than an exact frame.
|
|
412
|
+
generator.requestedTimeToleranceBefore = kCMTimePositiveInfinity;
|
|
413
|
+
generator.requestedTimeToleranceAfter = kCMTimePositiveInfinity;
|
|
414
|
+
|
|
415
|
+
NSError *error = nil;
|
|
416
|
+
CGImageRef cgImage = [generator copyCGImageAtTime:CMTimeMakeWithSeconds(0.1, 600) actualTime:NULL error:&error];
|
|
417
|
+
if (!cgImage) {
|
|
418
|
+
reject(@"thumbnail_failed", error.localizedDescription ?: @"Could not read a video frame", error);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
NSData *jpeg = UIImageJPEGRepresentation([UIImage imageWithCGImage:cgImage], 0.8);
|
|
422
|
+
CGImageRelease(cgImage);
|
|
423
|
+
if (![jpeg writeToFile:thumbPath atomically:YES]) {
|
|
424
|
+
reject(@"thumbnail_failed", @"Could not write the thumbnail", nil);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
resolve([NSURL fileURLWithPath:thumbPath].absoluteString);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
375
431
|
RCT_EXPORT_METHOD(openFileChooserMulti:(NSString *)type maxSelection:(nonnull NSNumber *)maxSelection callback:(RCTResponseSenderBlock)call) {
|
|
376
432
|
callback = call;
|
|
377
433
|
UIViewController *presentedViewController = RCTPresentedViewController();
|
|
@@ -1104,6 +1160,11 @@ RCT_EXPORT_METHOD(clearSegments:(RCTResponseSenderBlock)callback) {
|
|
|
1104
1160
|
|
|
1105
1161
|
- (void)imagePickerController:(UIImagePickerController *)picker
|
|
1106
1162
|
didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
|
|
1163
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1164
|
+
if (!callback) {
|
|
1165
|
+
[picker dismissViewControllerAnimated:TRUE completion:nil];
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1107
1168
|
switch (picker.sourceType) {
|
|
1108
1169
|
case UIImagePickerControllerSourceTypeCamera: {
|
|
1109
1170
|
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
|
|
@@ -1180,7 +1241,12 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1180
1241
|
// PHPickerViewControllerDelegate — handles multi-select from Photos library (images and videos)
|
|
1181
1242
|
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results {
|
|
1182
1243
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
1244
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1245
|
+
if (!callback) {
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1183
1248
|
if (results.count == 0) {
|
|
1249
|
+
callback(@[@[]]);
|
|
1184
1250
|
return;
|
|
1185
1251
|
}
|
|
1186
1252
|
|
|
@@ -1229,9 +1295,7 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1229
1295
|
}
|
|
1230
1296
|
|
|
1231
1297
|
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
|
1232
|
-
|
|
1233
|
-
callback(@[fileInfoArray]);
|
|
1234
|
-
}
|
|
1298
|
+
callback(@[fileInfoArray]);
|
|
1235
1299
|
});
|
|
1236
1300
|
}
|
|
1237
1301
|
|
|
@@ -1248,6 +1312,11 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1248
1312
|
}
|
|
1249
1313
|
|
|
1250
1314
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
|
1315
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1316
|
+
if (!callback) {
|
|
1317
|
+
_multipleSelection = NO;
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1251
1320
|
if (_multipleSelection) {
|
|
1252
1321
|
_multipleSelection = NO;
|
|
1253
1322
|
NSMutableArray *results = [NSMutableArray array];
|
|
@@ -1273,6 +1342,11 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1273
1342
|
|
|
1274
1343
|
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
|
|
1275
1344
|
NSLog(@"document pick cancelled");
|
|
1345
|
+
if (_multipleSelection) {
|
|
1346
|
+
_multipleSelection = NO;
|
|
1347
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1348
|
+
if (callback) callback(@[@[]]);
|
|
1349
|
+
}
|
|
1276
1350
|
[controller dismissViewControllerAnimated:TRUE completion:nil];
|
|
1277
1351
|
}
|
|
1278
1352
|
|
|
@@ -1197,6 +1197,20 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1197
1197
|
/// True when the colour was cleared with the caret parked, so the next typed character is
|
|
1198
1198
|
/// `UIColor.label` rather than inheriting a neighbouring colour.
|
|
1199
1199
|
private var pendingExternalForegroundCleared: Bool = false
|
|
1200
|
+
/// The background equivalent. removeInlineStyle strips the background straight out of
|
|
1201
|
+
/// typingAttributes rather than arming a pending value, so there is no sentinel in
|
|
1202
|
+
/// `pendingStyles` to read — without this flag a keyboard replacing the word would lift the
|
|
1203
|
+
/// background back off the run it replaced and undo the clear. Reset wherever
|
|
1204
|
+
/// `pendingExternalForegroundCleared` is reset, so both decisions expire together.
|
|
1205
|
+
private var pendingExternalBackgroundCleared: Bool = false
|
|
1206
|
+
|
|
1207
|
+
/// Colour to re-apply to text a keyboard just inserted, with the range it landed in.
|
|
1208
|
+
/// Set in shouldChangeTextIn (before the text changes, while the old run is still
|
|
1209
|
+
/// readable) and consumed in textViewDidChange. Going through typingAttributes does not
|
|
1210
|
+
/// survive — many later sites in this file overwrite it before UIKit inserts.
|
|
1211
|
+
private var pendingInheritColour: UIColor? = nil
|
|
1212
|
+
private var pendingInheritBackground: UIColor? = nil
|
|
1213
|
+
private var pendingInheritRange: NSRange? = nil
|
|
1200
1214
|
|
|
1201
1215
|
/// Typing attributes to forcefully restore after all processing (including async
|
|
1202
1216
|
/// JS bridge callbacks like syncMentionRanges) completes. Set by autoContinueListOnEnter
|
|
@@ -1245,7 +1259,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1245
1259
|
return
|
|
1246
1260
|
}
|
|
1247
1261
|
pendingExternalForeground = color
|
|
1248
|
-
pendingExternalForegroundCleared = false
|
|
1262
|
+
pendingExternalForegroundCleared = false; pendingExternalBackgroundCleared = false
|
|
1249
1263
|
pendingStyles.insert(ExternalColorPendingKey)
|
|
1250
1264
|
}
|
|
1251
1265
|
|
|
@@ -1475,6 +1489,92 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1475
1489
|
return true
|
|
1476
1490
|
}
|
|
1477
1491
|
|
|
1492
|
+
/// Drops every armed, cleared or deferred inline-style decision and returns typingAttributes
|
|
1493
|
+
/// to plain. The composer is empty, so none of it has anything left to apply to.
|
|
1494
|
+
///
|
|
1495
|
+
/// Called from two places, and it has to be: `textDidChange` runs only for edits the USER
|
|
1496
|
+
/// made, because UIKit does not post `textDidChangeNotification` for a programmatic
|
|
1497
|
+
/// assignment. Clearing the composer after a send is programmatic — `setTextContent("")` —
|
|
1498
|
+
/// so relying on the notification left the colour armed and the NEXT message came out
|
|
1499
|
+
/// coloured without the user asking. Android resets here because its `setText` does run its
|
|
1500
|
+
/// TextWatcher; this is what gives iOS the same behaviour.
|
|
1501
|
+
private func resetInlineStateForEmptyComposer() {
|
|
1502
|
+
pendingStyles.removeAll()
|
|
1503
|
+
explicitlyOffStyles.removeAll()
|
|
1504
|
+
pendingStylesInsertPos = -1
|
|
1505
|
+
lastKnownTextLength = 0
|
|
1506
|
+
pendingExternalForeground = nil
|
|
1507
|
+
pendingExternalForegroundCleared = false
|
|
1508
|
+
pendingExternalBackgroundCleared = false
|
|
1509
|
+
deferredTypingAttrs = nil
|
|
1510
|
+
// A captured inheritance would otherwise be painted onto the first character of the
|
|
1511
|
+
// next message, which is the same leak by a different route.
|
|
1512
|
+
clearPendingInherit()
|
|
1513
|
+
// Reset typingAttributes to plain so next typed text has no ghost formatting
|
|
1514
|
+
let paragraphStyle = NSMutableParagraphStyle()
|
|
1515
|
+
paragraphStyle.lineHeightMultiple = RichTextEditorView.defaultLineHeightMultiple
|
|
1516
|
+
textView.typingAttributes = [
|
|
1517
|
+
.font: UIFont.systemFont(ofSize: 16),
|
|
1518
|
+
.foregroundColor: UIColor.label,
|
|
1519
|
+
.paragraphStyle: paragraphStyle
|
|
1520
|
+
]
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
private func clearPendingInherit() {
|
|
1524
|
+
pendingInheritColour = nil
|
|
1525
|
+
pendingInheritBackground = nil
|
|
1526
|
+
pendingInheritRange = nil
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/// Paints the colour captured in shouldChangeTextIn onto the text the keyboard just inserted.
|
|
1530
|
+
///
|
|
1531
|
+
/// Called from textDidChange rather than from a textViewDidChange delegate method. Two reasons,
|
|
1532
|
+
/// both learned the hard way:
|
|
1533
|
+
///
|
|
1534
|
+
/// - textView.insertText (list continuation) fires the delegate synchronously from inside an
|
|
1535
|
+
/// isInternalChange window, so a delegate implementation re-enters mid-edit and, by resetting
|
|
1536
|
+
/// the flag, makes the rest of that edit look like user typing. textDidChange already guards
|
|
1537
|
+
/// on isInternalChange, so it is re-entrancy-safe.
|
|
1538
|
+
/// - textDidChange owns saveToUndoStack and sendContentChange. Mutating here, ahead of both,
|
|
1539
|
+
/// means the inherited colour is in the text before it is emitted to JS or snapshotted for
|
|
1540
|
+
/// undo, rather than depending on UIKit's delegate/notification ordering.
|
|
1541
|
+
private func applyPendingInheritedColour() {
|
|
1542
|
+
guard let range = pendingInheritRange,
|
|
1543
|
+
let attrText = textView.attributedText,
|
|
1544
|
+
range.location >= 0, range.location + range.length <= attrText.length,
|
|
1545
|
+
range.length > 0,
|
|
1546
|
+
pendingInheritColour != nil || pendingInheritBackground != nil else {
|
|
1547
|
+
clearPendingInherit()
|
|
1548
|
+
return
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
// Add the attributes in place rather than assigning `textView.attributedText`.
|
|
1552
|
+
//
|
|
1553
|
+
// Assigning attributedText replaces the whole string, and UITextView ends any marked text
|
|
1554
|
+
// when it does — marked text being the uncommitted, underlined run an input method shows
|
|
1555
|
+
// while a word is still being composed. This method runs on every keystroke that inherits
|
|
1556
|
+
// a colour, so with a Japanese, Chinese or Korean keyboard the composition was torn down
|
|
1557
|
+
// character by character and the word could not be typed at all. Mutating textStorage
|
|
1558
|
+
// leaves the string, the composition and the caret untouched, so none of that arises and
|
|
1559
|
+
// the caret no longer has to be saved and restored either.
|
|
1560
|
+
let storage = textView.textStorage
|
|
1561
|
+
let wasInternal = isInternalChange
|
|
1562
|
+
isInternalChange = true
|
|
1563
|
+
storage.beginEditing()
|
|
1564
|
+
if let colour = pendingInheritColour {
|
|
1565
|
+
storage.addAttribute(ExternalForegroundKey, value: colour, range: range)
|
|
1566
|
+
storage.addAttribute(.foregroundColor, value: colour, range: range)
|
|
1567
|
+
}
|
|
1568
|
+
if let background = pendingInheritBackground {
|
|
1569
|
+
storage.addAttribute(ExternalBackgroundKey, value: background, range: range)
|
|
1570
|
+
storage.addAttribute(.backgroundColor, value: background, range: range)
|
|
1571
|
+
}
|
|
1572
|
+
storage.endEditing()
|
|
1573
|
+
isInternalChange = wasInternal
|
|
1574
|
+
|
|
1575
|
+
clearPendingInherit()
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1478
1578
|
func textViewDidChangeSelection(_ textView: UITextView) {
|
|
1479
1579
|
let range = textView.selectedRange
|
|
1480
1580
|
if range.length > 0 {
|
|
@@ -1498,8 +1598,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1498
1598
|
// to avoid emitting stale style state before typingAttributes are restored.
|
|
1499
1599
|
guard !isInternalChange else { return }
|
|
1500
1600
|
|
|
1501
|
-
// Invalidate pending styles if cursor moved away from insert position
|
|
1502
|
-
|
|
1601
|
+
// Invalidate pending styles if cursor moved away from insert position.
|
|
1602
|
+
// The cleared-colour flags count as pending decisions in their own right: a background
|
|
1603
|
+
// clear arms no sentinel and leaves both Sets empty, so without them in this condition it
|
|
1604
|
+
// would never expire.
|
|
1605
|
+
if pendingStylesInsertPos >= 0 && (!pendingStyles.isEmpty || !explicitlyOffStyles.isEmpty
|
|
1606
|
+
|| pendingExternalForegroundCleared || pendingExternalBackgroundCleared) {
|
|
1503
1607
|
// Typing advances the caret by however many characters actually landed: one for a plain
|
|
1504
1608
|
// keystroke, but several for autocorrect replacing a word, predictive text, a multi-scalar
|
|
1505
1609
|
// emoji, a paste, or an IME commit. Comparing against a hardcoded +1 classified all of
|
|
@@ -1516,7 +1620,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1516
1620
|
// Drop the caret-armed colour too — otherwise it leaks onto text typed at the
|
|
1517
1621
|
// new cursor position (the removeAll() above only drops the sentinel).
|
|
1518
1622
|
pendingExternalForeground = nil
|
|
1519
|
-
pendingExternalForegroundCleared = false
|
|
1623
|
+
pendingExternalForegroundCleared = false; pendingExternalBackgroundCleared = false
|
|
1520
1624
|
if hadCodeBlock {
|
|
1521
1625
|
pendingStyles.insert("codeBlock")
|
|
1522
1626
|
pendingStylesInsertPos = range.location
|
|
@@ -1773,6 +1877,93 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1773
1877
|
|
|
1774
1878
|
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
|
1775
1879
|
|
|
1880
|
+
// --- Inline formatting follows the user's intent, not the character range ---
|
|
1881
|
+
//
|
|
1882
|
+
// Measured on iOS 26: accepting a suggestion arrives as ONE replacement —
|
|
1883
|
+
// loc=0 len=3 text='Respect' (after typing "Res")
|
|
1884
|
+
// so the styled characters are destroyed in a single call and the replacement is
|
|
1885
|
+
// styled from typingAttributes, which knows nothing about them.
|
|
1886
|
+
//
|
|
1887
|
+
// This MUST run before the early returns further down (list prefixes, code blocks,
|
|
1888
|
+
// blockquotes). Placed at the end it never executed, which is why the colour was lost
|
|
1889
|
+
// even with the rules in place.
|
|
1890
|
+
if !isInternalChange, let attrText = textView.attributedText {
|
|
1891
|
+
// Reset first, unconditionally. Every `return false` path below handles its own text
|
|
1892
|
+
// and suppresses UIKit's insertion, so textDidChange never runs and never consumes
|
|
1893
|
+
// what we set here. Without this reset that stale range outlives the change and gets
|
|
1894
|
+
// painted onto whatever text later occupies it.
|
|
1895
|
+
clearPendingInherit()
|
|
1896
|
+
|
|
1897
|
+
var typing = textView.typingAttributes
|
|
1898
|
+
var inheritFrom: [NSAttributedString.Key: Any]? = nil
|
|
1899
|
+
|
|
1900
|
+
// Inline code and a code block own their own foreground, so a consumer colour
|
|
1901
|
+
// inherited from the neighbouring character would paint over the code styling the
|
|
1902
|
+
// user just armed. Android skips the same way.
|
|
1903
|
+
let codeArmed = pendingStyles.contains("code") || pendingStyles.contains("codeBlock")
|
|
1904
|
+
|
|
1905
|
+
if codeArmed {
|
|
1906
|
+
inheritFrom = nil
|
|
1907
|
+
} else if range.length > 0, !text.isEmpty, range.location < attrText.length {
|
|
1908
|
+
// A replacement: inherit from the run being replaced, read before it is gone.
|
|
1909
|
+
inheritFrom = attrText.attributes(at: range.location, effectiveRange: nil)
|
|
1910
|
+
} else if range.length == 0, !text.isEmpty, range.location > 0,
|
|
1911
|
+
range.location - 1 < attrText.length,
|
|
1912
|
+
!pendingStyles.contains(ExternalColorPendingKey),
|
|
1913
|
+
!pendingExternalForegroundCleared {
|
|
1914
|
+
// A plain insertion: inherit from the character before the caret, so text typed
|
|
1915
|
+
// after a frozen run joins it. An armed or just-cleared colour wins over this.
|
|
1916
|
+
inheritFrom = attrText.attributes(at: range.location - 1, effectiveRange: nil)
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
if let src = inheritFrom {
|
|
1920
|
+
// An explicit CLEAR outranks inheritance on both rules: the user turned the
|
|
1921
|
+
// colour off, so a keyboard replacing that word must not resurrect it.
|
|
1922
|
+
//
|
|
1923
|
+
// Only the clear, deliberately — not an armed colour. pendingStyles carries the
|
|
1924
|
+
// sentinel for armed and cleared alike, so testing it here also suppressed
|
|
1925
|
+
// inheritance while a colour was armed, and the armed colour alone does not
|
|
1926
|
+
// survive a replacement: typingAttributes is overwritten before UIKit inserts,
|
|
1927
|
+
// which is the whole reason this pendingInherit path exists. Measured on an
|
|
1928
|
+
// iPhone 17 Pro: colour "Doe", accept the "Doesn't" suggestion, and the word
|
|
1929
|
+
// came through black. explicitlyOffStyles is not consulted either — on iOS it
|
|
1930
|
+
// only ever holds bold/italic/underline/strikethrough/code.
|
|
1931
|
+
let colourCleared = pendingExternalForegroundCleared
|
|
1932
|
+
let backgroundCleared = pendingExternalBackgroundCleared
|
|
1933
|
+
|
|
1934
|
+
// Remember where the incoming text will land so textDidChange can style it.
|
|
1935
|
+
//
|
|
1936
|
+
// An ARMED colour beats the replaced run's: it is the user's newest intent. Before
|
|
1937
|
+
// this the run won, so arming red over a blue word and then accepting a suggestion
|
|
1938
|
+
// gave a blue replacement, while the armed red survived to colour the next
|
|
1939
|
+
// character — two colours in one word. Android has the same precedence at
|
|
1940
|
+
// RichTextEditorView.kt:525.
|
|
1941
|
+
pendingInheritColour = colourCleared
|
|
1942
|
+
? nil
|
|
1943
|
+
: (pendingExternalForeground ?? src[ExternalForegroundKey] as? UIColor)
|
|
1944
|
+
pendingInheritBackground = backgroundCleared ? nil : src[ExternalBackgroundKey] as? UIColor
|
|
1945
|
+
pendingInheritRange = (pendingInheritColour != nil || pendingInheritBackground != nil)
|
|
1946
|
+
? NSRange(location: range.location, length: (text as NSString).length)
|
|
1947
|
+
: nil
|
|
1948
|
+
|
|
1949
|
+
var changed = false
|
|
1950
|
+
// Marker and paint move together: the marker is what the serializer reads.
|
|
1951
|
+
// Read the already-filtered pending values, not `src`, so a cleared colour is not
|
|
1952
|
+
// re-armed here after being suppressed above.
|
|
1953
|
+
if let colour = pendingInheritColour {
|
|
1954
|
+
typing[ExternalForegroundKey] = colour
|
|
1955
|
+
typing[.foregroundColor] = colour
|
|
1956
|
+
changed = true
|
|
1957
|
+
}
|
|
1958
|
+
if let background = pendingInheritBackground {
|
|
1959
|
+
typing[ExternalBackgroundKey] = background
|
|
1960
|
+
typing[.backgroundColor] = background
|
|
1961
|
+
changed = true
|
|
1962
|
+
}
|
|
1963
|
+
if changed { textView.typingAttributes = typing }
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1776
1967
|
// --- Mention bleed-through prevention (iOS equivalent of Android SPAN_EXCLUSIVE_EXCLUSIVE) ---
|
|
1777
1968
|
// Check if typingAttributes carry mention styling and strip it before insertion.
|
|
1778
1969
|
do {
|
|
@@ -2431,6 +2622,10 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
2431
2622
|
}
|
|
2432
2623
|
|
|
2433
2624
|
if !isInternalChange {
|
|
2625
|
+
// Before anything reads or snapshots the text: give the characters the keyboard just
|
|
2626
|
+
// inserted the formatting they inherited (see applyPendingInheritedColour).
|
|
2627
|
+
applyPendingInheritedColour()
|
|
2628
|
+
|
|
2434
2629
|
// Clear pending styles after text was typed (typingAttributes already applied them).
|
|
2435
2630
|
// Preserve inline styles (bold, italic, underline, strikethrough) — they persist
|
|
2436
2631
|
// until the cursor moves to a different position (matching Android behavior where
|
|
@@ -2483,21 +2678,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
2483
2678
|
|
|
2484
2679
|
// Reset pending styles and typingAttributes when text becomes empty
|
|
2485
2680
|
if textView.text.isEmpty {
|
|
2486
|
-
|
|
2487
|
-
explicitlyOffStyles.removeAll()
|
|
2488
|
-
pendingStylesInsertPos = -1
|
|
2489
|
-
lastKnownTextLength = 0
|
|
2490
|
-
pendingExternalForeground = nil
|
|
2491
|
-
pendingExternalForegroundCleared = false
|
|
2492
|
-
deferredTypingAttrs = nil
|
|
2493
|
-
// Reset typingAttributes to plain so next typed text has no ghost formatting
|
|
2494
|
-
let paragraphStyle = NSMutableParagraphStyle()
|
|
2495
|
-
paragraphStyle.lineHeightMultiple = RichTextEditorView.defaultLineHeightMultiple
|
|
2496
|
-
textView.typingAttributes = [
|
|
2497
|
-
.font: UIFont.systemFont(ofSize: 16),
|
|
2498
|
-
.foregroundColor: UIColor.label,
|
|
2499
|
-
.paragraphStyle: paragraphStyle
|
|
2500
|
-
]
|
|
2681
|
+
resetInlineStateForEmptyComposer()
|
|
2501
2682
|
}
|
|
2502
2683
|
|
|
2503
2684
|
// Skip applyListIndentation/renumberNumberedLists during internal changes
|
|
@@ -3795,7 +3976,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
3795
3976
|
return
|
|
3796
3977
|
}
|
|
3797
3978
|
pendingExternalForeground = color
|
|
3798
|
-
pendingExternalForegroundCleared = false
|
|
3979
|
+
pendingExternalForegroundCleared = false; pendingExternalBackgroundCleared = false
|
|
3799
3980
|
pendingStyles.insert(ExternalColorPendingKey)
|
|
3800
3981
|
pendingStylesInsertPos = range.location
|
|
3801
3982
|
applyPendingStylesToTypingAttributes()
|
|
@@ -3825,6 +4006,18 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
3825
4006
|
guard attribute == .foregroundColor else {
|
|
3826
4007
|
textView.typingAttributes.removeValue(forKey: marker)
|
|
3827
4008
|
textView.typingAttributes.removeValue(forKey: attribute)
|
|
4009
|
+
// Stripping typingAttributes stops the next TYPED character carrying the
|
|
4010
|
+
// background, but a keyboard replacement reads the run it replaces, not
|
|
4011
|
+
// typingAttributes — so record the decision for the inheritance rules too.
|
|
4012
|
+
//
|
|
4013
|
+
// The anchor goes in with it. The caret-move invalidation needs one to compare
|
|
4014
|
+
// against, and this branch arms no sentinel, so without it a background-only
|
|
4015
|
+
// clear never expired: clear after one highlighted word, tap into another, accept
|
|
4016
|
+
// a suggestion there, and that second word silently lost its highlight.
|
|
4017
|
+
if attribute == .backgroundColor {
|
|
4018
|
+
pendingExternalBackgroundCleared = true
|
|
4019
|
+
pendingStylesInsertPos = range.location
|
|
4020
|
+
}
|
|
3828
4021
|
return
|
|
3829
4022
|
}
|
|
3830
4023
|
pendingExternalForeground = nil
|
|
@@ -4681,7 +4874,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
4681
4874
|
// inline style, so the consumer colour goes with them rather than surviving alone.
|
|
4682
4875
|
pendingStyles.remove(ExternalColorPendingKey)
|
|
4683
4876
|
pendingExternalForeground = nil
|
|
4684
|
-
pendingExternalForegroundCleared = false
|
|
4877
|
+
pendingExternalForegroundCleared = false; pendingExternalBackgroundCleared = false
|
|
4685
4878
|
explicitlyOffStyles.removeAll()
|
|
4686
4879
|
// Reset typingAttributes to plain so list prefix doesn't inherit code block styling
|
|
4687
4880
|
let plainParaStyle = NSMutableParagraphStyle()
|
|
@@ -5438,7 +5631,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
5438
5631
|
// Drop an armed consumer colour, or the first character typed into the empty block
|
|
5439
5632
|
// would come out coloured instead of the code block default.
|
|
5440
5633
|
pendingExternalForeground = nil
|
|
5441
|
-
pendingExternalForegroundCleared = false
|
|
5634
|
+
pendingExternalForegroundCleared = false; pendingExternalBackgroundCleared = false
|
|
5442
5635
|
pendingStyles.remove(ExternalColorPendingKey)
|
|
5443
5636
|
pendingStylesInsertPos = textView.selectedRange.location
|
|
5444
5637
|
isInternalChange = false
|
|
@@ -5507,7 +5700,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
5507
5700
|
// A colour armed for type-ahead would otherwise colour the next character typed
|
|
5508
5701
|
// inside the block.
|
|
5509
5702
|
pendingExternalForeground = nil
|
|
5510
|
-
pendingExternalForegroundCleared = false
|
|
5703
|
+
pendingExternalForegroundCleared = false; pendingExternalBackgroundCleared = false
|
|
5511
5704
|
pendingStyles.remove(ExternalColorPendingKey)
|
|
5512
5705
|
// Set pendingStyles + typingAttributes so newly typed characters
|
|
5513
5706
|
// inherit code block mode (matches empty-line activation path)
|
|
@@ -5670,6 +5863,15 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
5670
5863
|
|
|
5671
5864
|
placeholderLabel.isHidden = !text.isEmpty
|
|
5672
5865
|
isInternalChange = false
|
|
5866
|
+
|
|
5867
|
+
// The composer just became empty programmatically — a send, or a clear from JS. UIKit
|
|
5868
|
+
// posts no change notification for that, so textDidChange never runs and the reset it
|
|
5869
|
+
// owns would never happen: the colour stayed armed and the next message came out
|
|
5870
|
+
// coloured on its own. Reset here instead, matching Android.
|
|
5871
|
+
if (textView.text ?? "").isEmpty {
|
|
5872
|
+
resetInlineStateForEmptyComposer()
|
|
5873
|
+
}
|
|
5874
|
+
|
|
5673
5875
|
updateContentSize()
|
|
5674
5876
|
if force {
|
|
5675
5877
|
sendContentChange()
|
|
@@ -6323,8 +6525,16 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
6323
6525
|
guard j < chars.count else { return nil }
|
|
6324
6526
|
guard j + 1 < chars.count && chars[j + 1] == "(" else { return nil }
|
|
6325
6527
|
let urlStart = j + 2
|
|
6528
|
+
// Balanced: `(planet)` inside the address is kept and only an unmatched `)` closes the
|
|
6529
|
+
// link. Stopping at the first `)` turned a pasted [Mercury](…/Mercury_(planet)) into
|
|
6530
|
+
// "Mercury" linking to …/Mercury_(planet plus a stray ")".
|
|
6326
6531
|
var k = urlStart
|
|
6327
|
-
|
|
6532
|
+
var depth = 0
|
|
6533
|
+
while k < chars.count {
|
|
6534
|
+
if chars[k] == "(" { depth += 1 }
|
|
6535
|
+
else if chars[k] == ")" { if depth == 0 { break }; depth -= 1 }
|
|
6536
|
+
k += 1
|
|
6537
|
+
}
|
|
6328
6538
|
guard k < chars.count else { return nil }
|
|
6329
6539
|
let linkText = String(chars[(from + 1)..<j])
|
|
6330
6540
|
let linkURL = String(chars[urlStart..<k])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.3",
|
|
4
4
|
"description": "Ready-to-use Chat UI Components for React Native",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"react-native-cometchat-ui-kit.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!android/build",
|
|
19
|
+
"!android/src/test",
|
|
19
20
|
"!ios/build",
|
|
20
21
|
"!**/__tests__",
|
|
21
22
|
"!**/__fixtures__",
|
|
@@ -23,6 +24,8 @@
|
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
25
26
|
"test": "jest",
|
|
27
|
+
"test:native:android": "cd ../../examples/masterapp/android && ./gradlew :cometchat_chat-uikit-react-native:testDebugUnitTest",
|
|
28
|
+
"test:native:ios": "cd ios-tests && UDID=$(xcrun simctl list devices available | grep -m1 iPhone | grep -oE '[0-9A-F-]{36}'); if [ -z \"$UDID\" ]; then echo \"No iPhone simulator is available. Install one via Xcode > Settings > Components.\" >&2; exit 1; fi; xcodebuild test -scheme RichTextEditorKit-Package -destination \"platform=iOS Simulator,id=$UDID\"",
|
|
26
29
|
"typescript": "tsc --noEmit",
|
|
27
30
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
28
31
|
"release": "release-it",
|
|
@@ -51,8 +54,8 @@
|
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|
|
53
56
|
"@babel/eslint-parser": "^7.27.0",
|
|
54
|
-
"@react-native/eslint-config": "0.
|
|
55
|
-
"@react-native/jest-preset": "
|
|
57
|
+
"@react-native/eslint-config": "0.87.1",
|
|
58
|
+
"@react-native/jest-preset": "0.87.1",
|
|
56
59
|
"@types/jest": "^29.5.13",
|
|
57
60
|
"@types/react": "*",
|
|
58
61
|
"commitlint": "^17.0.2",
|
|
@@ -87,7 +90,7 @@
|
|
|
87
90
|
"react-native-video": "*"
|
|
88
91
|
},
|
|
89
92
|
"jest": {
|
|
90
|
-
"preset": "react-native",
|
|
93
|
+
"preset": "@react-native/jest-preset",
|
|
91
94
|
"modulePathIgnorePatterns": [
|
|
92
95
|
"<rootDir>/lib/"
|
|
93
96
|
],
|
|
@@ -2,8 +2,6 @@ require "json"
|
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
|
-
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
6
|
-
|
|
7
5
|
Pod::Spec.new do |s|
|
|
8
6
|
s.name = "react-native-cometchat-ui-kit"
|
|
9
7
|
s.version = package["version"]
|
|
@@ -12,14 +10,13 @@ Pod::Spec.new do |s|
|
|
|
12
10
|
s.license = package["license"]
|
|
13
11
|
s.authors = package["author"].is_a?(Hash) ? [package["author"]] : package["author"]
|
|
14
12
|
|
|
15
|
-
s.platforms = { :ios =>
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
16
14
|
s.source = { :git => "https://github.com/cometchat/cometchat-uikit-react-native.git", :tag => "#{s.version}" }
|
|
17
15
|
|
|
18
16
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
19
17
|
|
|
20
18
|
s.static_framework = true # Set static_framework for the main spec if needed
|
|
21
19
|
s.frameworks = ["PhotosUI"]
|
|
22
|
-
s.dependency "React-Core"
|
|
23
20
|
|
|
24
21
|
s.subspec "Video" do |ss|
|
|
25
22
|
ss.source_files = "ios/Video/*.{h,m}"
|
|
@@ -33,19 +30,8 @@ Pod::Spec.new do |s|
|
|
|
33
30
|
ss.source_files = "ios/VideoCaching/**/*.{h,m}"
|
|
34
31
|
end
|
|
35
32
|
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Header/Public/**\"",
|
|
41
|
-
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
# s.dependency "React-Codegen"
|
|
45
|
-
# s.dependency "RCT-Folly"
|
|
46
|
-
# s.dependency "RCTRequired"
|
|
47
|
-
# s.dependency "RCTTypeSafety"
|
|
48
|
-
# s.dependency "ReactCommon/turbomodule/core"
|
|
49
|
-
# s.dependency "RCTSlider"
|
|
50
|
-
end
|
|
33
|
+
# React Native's own helper wires up React-Core and the New Architecture
|
|
34
|
+
# dependencies and flags (RN 0.71+). It replaces the hand-rolled
|
|
35
|
+
# RCT_NEW_ARCH_ENABLED block, which stopped meaning anything in RN 0.82.
|
|
36
|
+
install_modules_dependencies(s)
|
|
51
37
|
end
|