Skip to content

Commit 31703bd

Browse files
committed
udpate add addUploadProgressListener in docs
1 parent 1f73283 commit 31703bd

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

document/API.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,21 @@ JMessage.removeMessageRetractListener(listener) // 移除监听(一般在 compon
11961196
- type: 'user_password_change' / 'user_logout' / 'user_deleted' / 'user_login_status_unexpected'
11971197
11981198
1199+
#### addUploadProgressListener
1200+
1201+
发送文件(图片、文件)进度回调,该回调会回调多次。
1202+
1203+
##### 示例
1204+
1205+
```javascript
1206+
var listener = (result) => { }
1207+
1208+
JMessage.addUploadProgressListener(listener) // 添加监听
1209+
JMessage.removeUploadProgressListener(listener) // 移除监听(一般在 componentWillUnmount 中调用)
1210+
```
1211+
1212+
##### 回调参数说明
1213+
1214+
- result
1215+
- messageId:消息 id。
1216+
- progress:上传进度,从 0-1 float 类型。

ios/RCTJMessageModule/RCTJMessageModule.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
488488

489489
if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) {
490490
JMSGImageContent *content = [[JMSGImageContent alloc] initWithImageData: [NSData dataWithContentsOfFile: mediaPath]];
491+
492+
content.uploadHandler = ^(float percent, NSString *msgID) {
493+
[self.bridge.eventDispatcher sendAppEventWithName:uploadProgressEvent body:@{@"messageId": msgID,
494+
@"progress": @(percent)}];
495+
};
496+
491497
JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]];
492498
if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) {
493499
NSDictionary *extras = param[@"extras"];
@@ -513,6 +519,13 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
513519

514520
} else if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) {
515521
JMSGImageContent *content = [[JMSGImageContent alloc] initWithImageData: [NSData dataWithContentsOfFile: mediaPath]];
522+
523+
content.uploadHandler = ^(float percent, NSString *msgID) {
524+
525+
[self.bridge.eventDispatcher sendAppEventWithName:uploadProgressEvent body:@{@"messageId": msgID,
526+
@"progress": @(percent)}];
527+
};
528+
516529
JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]];
517530
if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) {
518531
NSDictionary *extras = param[@"extras"];
@@ -794,6 +807,12 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
794807
if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) {
795808
// send single text message
796809
JMSGFileContent *content = [[JMSGFileContent alloc] initWithFileData:[NSData dataWithContentsOfFile: mediaPath] fileName: fileName];
810+
811+
content.uploadHandler = ^(float percent, NSString *msgID) {
812+
[self.bridge.eventDispatcher sendAppEventWithName:uploadProgressEvent body:@{@"messageId": msgID,
813+
@"progress": @(percent)}];
814+
};
815+
797816
JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]];
798817
if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) {
799818
NSDictionary *extras = param[@"extras"];
@@ -818,6 +837,12 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
818837
if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) {
819838
// send group text message
820839
JMSGFileContent *content = [[JMSGFileContent alloc] initWithFileData:[NSData dataWithContentsOfFile: mediaPath] fileName: fileName];
840+
841+
content.uploadHandler = ^(float percent, NSString *msgID) {
842+
[self.bridge.eventDispatcher sendAppEventWithName:uploadProgressEvent body:@{@"messageId": msgID,
843+
@"progress": @(percent)}];
844+
};
845+
821846
JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]];
822847
if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) {
823848
NSDictionary *extras = param[@"extras"];

0 commit comments

Comments
 (0)