@cometchat/chat-uikit-react-native 4.0.0 → 4.0.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 (134) hide show
  1. package/LICENSE.md +3 -0
  2. package/README.md +1 -1
  3. package/android/src/main/java/com/reactnativecometchatuikit/{RNSoundModule.java → CometChatSoundModule.java} +22 -22
  4. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -1
  5. package/ios/{RNSound.h → CometChatSoundModule.h} +1 -1
  6. package/ios/{RNSound.m → CometChatSoundModule.m} +2 -2
  7. package/package.json +3 -3
  8. package/src/AI/AIConversationStarter/AIConversationStarter.ts +33 -0
  9. package/src/AI/AIConversationStarter/AIConversationStarterDecorator.tsx +231 -0
  10. package/src/AI/AIConversationStarter/AIConversationStarterStyle.ts +8 -0
  11. package/src/AI/AIConversationStarter/configuration.ts +18 -0
  12. package/src/AI/AIConversationStarter/style.ts +76 -0
  13. package/src/AI/AIEnabler.ts +115 -0
  14. package/src/AI/AIEnablerDecorator.tsx +324 -0
  15. package/src/AI/AIExtensionDataSource.ts +12 -0
  16. package/src/AI/AISmartReplies/AISmartReplies.ts +28 -0
  17. package/src/AI/AISmartReplies/AISmartRepliesDecorator.ts +18 -0
  18. package/src/AI/AISmartReplies/AISmartRepliesStyle.ts +16 -0
  19. package/src/AI/AISmartReplies/configuration.ts +17 -0
  20. package/src/AI/CardView.tsx +81 -0
  21. package/src/AI/CardViewStyle.ts +37 -0
  22. package/src/AI/configuration.ts +17 -0
  23. package/src/AI/resources/ai-empty.png +0 -0
  24. package/src/AI/resources/ai-error.png +0 -0
  25. package/src/AI/resources/ai.png +0 -0
  26. package/src/AI/resources/index.ts +11 -0
  27. package/src/AI/resources/spineer.png +0 -0
  28. package/src/AI/style.ts +177 -0
  29. package/src/AI/utils.ts +39 -0
  30. package/src/CometChatConversations/CometChatConversations.tsx +56 -46
  31. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +13 -4
  32. package/src/CometChatMessageHeader/listners.ts +5 -4
  33. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +35 -35
  34. package/src/CometChatMessageList/CometChatMessageList.tsx +274 -158
  35. package/src/CometChatMessages/CometChatMessages.tsx +4 -3
  36. package/src/CometChatTabs/CometChatTabs.tsx +1 -1
  37. package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +4 -10
  38. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
  39. package/src/index.ts +61 -4
  40. package/src/shared/CometChatUiKit/CometChatUIKit.ts +108 -7
  41. package/src/shared/CometChatUiKit/UIKitSettings.ts +8 -0
  42. package/src/shared/constants/UIKitConstants.ts +81 -47
  43. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +46 -0
  44. package/src/shared/events/CometChatUIEventHandler/Listener.ts +66 -3
  45. package/src/shared/events/CometChatUIEvents.ts +1 -0
  46. package/src/shared/events/ListenerInitializer.ts +73 -0
  47. package/src/shared/events/messages.ts +14 -0
  48. package/src/shared/framework/DataSource.ts +12 -1
  49. package/src/shared/framework/DataSourceDecorator.tsx +37 -2
  50. package/src/shared/framework/MessageDataSource.tsx +85 -5
  51. package/src/shared/index.ts +44 -0
  52. package/src/shared/modals/InteractiveData/InteractiveActions/APIAction.ts +118 -0
  53. package/src/shared/modals/InteractiveData/InteractiveActions/CustomAction.ts +19 -0
  54. package/src/shared/modals/InteractiveData/InteractiveActions/URLNavigationAction.ts +34 -0
  55. package/src/shared/modals/InteractiveData/InteractiveActions/index.ts +3 -0
  56. package/src/shared/modals/InteractiveData/InteractiveData/InteractiveCardData.ts +69 -0
  57. package/src/shared/modals/InteractiveData/InteractiveData/InteractiveFormData.ts +119 -0
  58. package/src/shared/modals/InteractiveData/InteractiveData/index.ts +2 -0
  59. package/src/shared/modals/InteractiveData/InteractiveElements/BaseInputElement.ts +102 -0
  60. package/src/shared/modals/InteractiveData/InteractiveElements/BaseInteractiveElement.ts +45 -0
  61. package/src/shared/modals/InteractiveData/InteractiveElements/ButtonElement.ts +61 -0
  62. package/src/shared/modals/InteractiveData/InteractiveElements/CheckboxElement.ts +75 -0
  63. package/src/shared/modals/InteractiveData/InteractiveElements/DropdownElement.ts +83 -0
  64. package/src/shared/modals/InteractiveData/InteractiveElements/LabelElement.ts +32 -0
  65. package/src/shared/modals/InteractiveData/InteractiveElements/OptionElement.ts +39 -0
  66. package/src/shared/modals/InteractiveData/InteractiveElements/RadioButtonElement.ts +76 -0
  67. package/src/shared/modals/InteractiveData/InteractiveElements/SingleSelectElement.ts +76 -0
  68. package/src/shared/modals/InteractiveData/InteractiveElements/TextInputElement.ts +101 -0
  69. package/src/shared/modals/InteractiveData/InteractiveElements/index.ts +10 -0
  70. package/src/shared/modals/InteractiveData/InteractiveEntities/ActionEntity.ts +41 -0
  71. package/src/shared/modals/InteractiveData/InteractiveEntities/ElementEntity.ts +64 -0
  72. package/src/shared/modals/InteractiveData/InteractiveEntities/index.ts +2 -0
  73. package/src/shared/modals/InteractiveData/InteractiveMessage/CardMessage.ts +142 -0
  74. package/src/shared/modals/InteractiveData/InteractiveMessage/CustomInteractiveMessage.ts +38 -0
  75. package/src/shared/modals/InteractiveData/InteractiveMessage/FormMessage.ts +152 -0
  76. package/src/shared/modals/InteractiveData/InteractiveMessage/index.ts +3 -0
  77. package/src/shared/modals/InteractiveData/index.ts +28 -0
  78. package/src/shared/modals/index.ts +19 -0
  79. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +8 -1
  80. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +8 -1
  81. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +8 -1
  82. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +8 -1
  83. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +8 -1
  84. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +8 -1
  85. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +8 -1
  86. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +8 -1
  87. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +8 -1
  88. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +8 -1
  89. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +8 -1
  90. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +8 -1
  91. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +8 -1
  92. package/src/shared/resources/CometChatSoundManager/CometChatSoundManager.js +2 -2
  93. package/src/shared/resources/CometChatSoundManager/sound.js +35 -35
  94. package/src/shared/utils/InteractiveMessageUtils.ts +20 -0
  95. package/src/shared/utils/NetworkUtils.tsx +20 -0
  96. package/src/shared/utils/conversationUtils.ts +9 -6
  97. package/src/shared/views/CometChatButton/CometChatButton.tsx +32 -22
  98. package/src/shared/views/CometChatCardBubble/CardBubbleStyle.tsx +47 -0
  99. package/src/shared/views/CometChatCardBubble/CometChatCardBubble.tsx +173 -0
  100. package/src/shared/views/CometChatCardBubble/index.tsx +1 -0
  101. package/src/shared/views/CometChatCheckBox/CheckBoxStyle.tsx +43 -0
  102. package/src/shared/views/CometChatCheckBox/CometChatCheckBox.tsx +79 -0
  103. package/src/shared/views/CometChatDate/CometChatDate.tsx +2 -3
  104. package/src/shared/views/CometChatDropDown/CometChatDropDown.tsx +126 -0
  105. package/src/shared/views/CometChatDropDown/DropDownStyle.tsx +39 -0
  106. package/src/shared/views/CometChatDropDown/resources/downArrowIcon.png +0 -0
  107. package/src/shared/views/CometChatDropDown/resources/index.js +5 -0
  108. package/src/shared/views/CometChatFormBubble/CometChatFormBubble.tsx +464 -0
  109. package/src/shared/views/CometChatFormBubble/FormBubbleStyle.tsx +91 -0
  110. package/src/shared/views/CometChatFormBubble/index.tsx +1 -0
  111. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +13 -5
  112. package/src/shared/views/CometChatImageBubble/ImageBubbleStyle.ts +14 -3
  113. package/src/shared/views/CometChatLabel/CometChatLabel.tsx +27 -0
  114. package/src/shared/views/CometChatLabel/LabelStyle.ts +19 -0
  115. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +5 -4
  116. package/src/shared/views/CometChatQuickView/CometChatQuickView.tsx +66 -0
  117. package/src/shared/views/CometChatQuickView/QuickViewStyle.ts +55 -0
  118. package/src/shared/views/CometChatRadioButton/CometChatRadioButton.tsx +67 -0
  119. package/src/shared/views/CometChatRadioButton/RadioButtonStyle.tsx +38 -0
  120. package/src/shared/views/CometChatSingleSelect/CometChatSingleSelect.tsx +63 -0
  121. package/src/shared/views/CometChatSingleSelect/SingleStyle.tsx +35 -0
  122. package/src/shared/views/CometChatTextInput/CometChatTextInput.tsx +67 -0
  123. package/src/shared/views/CometChatTextInput/TextInputStyle.tsx +26 -0
  124. package/src/shared/views/index.ts +7 -1
  125. package/LICENSE +0 -21
  126. package/android/.idea/.gitignore +0 -3
  127. package/android/local.properties +0 -8
  128. package/src/.DS_Store +0 -0
  129. package/src/CometChatMessageInformation/.DS_Store +0 -0
  130. package/src/calls/CometChatCallHistory/.DS_Store +0 -0
  131. package/src/shared/framework/.DS_Store +0 -0
  132. package/src/shared/views/.DS_Store +0 -0
  133. package/src/shared/views/CometChatAudioBubble/.DS_Store +0 -0
  134. package/src/shared/views/CometChatFileBubble/.DS_Store +0 -0
@@ -1,9 +1,9 @@
1
1
  import { NativeModules, NativeEventEmitter } from 'react-native';
2
- const {RNSound} = NativeModules ;
3
- var IsAndroid = RNSound.IsAndroid;
4
- var IsWindows = RNSound.IsWindows;
2
+ const {CometChatSoundModule} = NativeModules ;
3
+ var IsAndroid = CometChatSoundModule.IsAndroid;
4
+ var IsWindows = CometChatSoundModule.IsWindows;
5
5
  import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
6
- var eventEmitter = new NativeEventEmitter(RNSound);
6
+ var eventEmitter = new NativeEventEmitter(CometChatSoundModule);
7
7
 
8
8
  var nextKey = 0;
9
9
 
@@ -23,14 +23,14 @@ function setAndroidVolumes(sound) {
23
23
  const relativeVolume = calculateRelativeVolume(sound._volume, sound._pan);
24
24
  if (sound._pan < 0) {
25
25
  // left is louder
26
- RNSound.setVolume(sound._key, sound._volume, relativeVolume);
26
+ CometChatSoundModule.setVolume(sound._key, sound._volume, relativeVolume);
27
27
  } else {
28
28
  // right is louder
29
- RNSound.setVolume(sound._key, relativeVolume, sound._volume);
29
+ CometChatSoundModule.setVolume(sound._key, relativeVolume, sound._volume);
30
30
  }
31
31
  } else {
32
32
  // no panning, same volume on both channels
33
- RNSound.setVolume(sound._key, sound._volume, sound._volume);
33
+ CometChatSoundModule.setVolume(sound._key, sound._volume, sound._volume);
34
34
  }
35
35
  }
36
36
 
@@ -60,7 +60,7 @@ class Sound {
60
60
  this._numberOfLoops = 0;
61
61
  this._speed = 1;
62
62
  this._pitch = 1;
63
- RNSound.prepare(this._filename, this._key, options || {}, (error, props) => {
63
+ CometChatSoundModule.prepare(this._filename, this._key, options || {}, (error, props) => {
64
64
  if (props) {
65
65
  if (typeof props.duration === 'number') {
66
66
  this._duration = props.duration;
@@ -101,31 +101,31 @@ class Sound {
101
101
  }
102
102
  };
103
103
  static enable(enabled) {
104
- RNSound.enable(enabled);
104
+ CometChatSoundModule.enable(enabled);
105
105
  }
106
106
  static enableInSilenceMode(enabled) {
107
107
  if (!IsAndroid && !IsWindows) {
108
- RNSound.enableInSilenceMode(enabled);
108
+ CometChatSoundModule.enableInSilenceMode(enabled);
109
109
  }
110
110
  }
111
111
  static setActive(value) {
112
112
  if (!IsAndroid && !IsWindows) {
113
- RNSound.setActive(value);
113
+ CometChatSoundModule.setActive(value);
114
114
  }
115
115
  }
116
116
  static setCategory(value, mixWithOthers = false) {
117
117
  if (!IsWindows) {
118
- RNSound.setCategory(value, mixWithOthers);
118
+ CometChatSoundModule.setCategory(value, mixWithOthers);
119
119
  }
120
120
  }
121
121
  static setMode(value) {
122
122
  if (!IsAndroid && !IsWindows) {
123
- RNSound.setMode(value);
123
+ CometChatSoundModule.setMode(value);
124
124
  }
125
125
  }
126
126
  static setSpeakerPhone(value) {
127
127
  if (!IsAndroid && !IsWindows) {
128
- RNSound.setSpeakerPhone(value);
128
+ CometChatSoundModule.setSpeakerPhone(value);
129
129
  }
130
130
  }
131
131
  isLoaded() {
@@ -133,7 +133,7 @@ class Sound {
133
133
  }
134
134
  play(onEnd) {
135
135
  if (this._loaded) {
136
- RNSound.play(this._key, (successfully) => onEnd && onEnd(successfully));
136
+ CometChatSoundModule.play(this._key, (successfully) => onEnd && onEnd(successfully));
137
137
  } else {
138
138
  onEnd && onEnd(false);
139
139
  }
@@ -141,7 +141,7 @@ class Sound {
141
141
  }
142
142
  pause(callback) {
143
143
  if (this._loaded) {
144
- RNSound.pause(this._key, () => {
144
+ CometChatSoundModule.pause(this._key, () => {
145
145
  this._playing = false;
146
146
  callback && callback();
147
147
  });
@@ -150,7 +150,7 @@ class Sound {
150
150
  }
151
151
  stop(callback) {
152
152
  if (this._loaded) {
153
- RNSound.stop(this._key, () => {
153
+ CometChatSoundModule.stop(this._key, () => {
154
154
  this._playing = false;
155
155
  callback && callback();
156
156
  });
@@ -159,14 +159,14 @@ class Sound {
159
159
  }
160
160
  reset() {
161
161
  if (this._loaded && IsAndroid) {
162
- RNSound.reset(this._key);
162
+ CometChatSoundModule.reset(this._key);
163
163
  this._playing = false;
164
164
  }
165
165
  return this;
166
166
  }
167
167
  release() {
168
168
  if (this._loaded) {
169
- RNSound.release(this._key);
169
+ CometChatSoundModule.release(this._key);
170
170
  this._loaded = false;
171
171
  if (!IsWindows) {
172
172
  if (this.onPlaySubscription != null) {
@@ -201,7 +201,7 @@ class Sound {
201
201
  if (IsAndroid) {
202
202
  setAndroidVolumes(this);
203
203
  } else {
204
- RNSound.setVolume(this._key, value);
204
+ CometChatSoundModule.setVolume(this._key, value);
205
205
  }
206
206
  }
207
207
  return this;
@@ -214,20 +214,20 @@ class Sound {
214
214
  } else if (IsAndroid) {
215
215
  setAndroidVolumes(this);
216
216
  } else {
217
- RNSound.setPan(this._key, value);
217
+ CometChatSoundModule.setPan(this._key, value);
218
218
  }
219
219
  }
220
220
  return this;
221
221
  }
222
222
  getSystemVolume(callback) {
223
223
  if (!IsWindows) {
224
- RNSound.getSystemVolume(callback);
224
+ CometChatSoundModule.getSystemVolume(callback);
225
225
  }
226
226
  return this;
227
227
  }
228
228
  setSystemVolume(value) {
229
229
  if (IsAndroid) {
230
- RNSound.setSystemVolume(value);
230
+ CometChatSoundModule.setSystemVolume(value);
231
231
  }
232
232
  return this;
233
233
  }
@@ -241,9 +241,9 @@ class Sound {
241
241
  this._numberOfLoops = value;
242
242
  if (this._loaded) {
243
243
  if (IsAndroid || IsWindows) {
244
- RNSound.setLooping(this._key, !!value);
244
+ CometChatSoundModule.setLooping(this._key, !!value);
245
245
  } else {
246
- RNSound.setNumberOfLoops(this._key, value);
246
+ CometChatSoundModule.setNumberOfLoops(this._key, value);
247
247
  }
248
248
  }
249
249
  return this;
@@ -252,7 +252,7 @@ class Sound {
252
252
  this._speed = value;
253
253
  if (this._loaded) {
254
254
  if (!IsWindows) {
255
- RNSound.setSpeed(this._key, value);
255
+ CometChatSoundModule.setSpeed(this._key, value);
256
256
  }
257
257
  }
258
258
  return this;
@@ -261,26 +261,26 @@ class Sound {
261
261
  this._pitch = value;
262
262
  if (this._loaded) {
263
263
  if (IsAndroid) {
264
- RNSound.setPitch(this._key, value);
264
+ CometChatSoundModule.setPitch(this._key, value);
265
265
  }
266
266
  }
267
267
  return this;
268
268
  }
269
269
  getCurrentTime(callback) {
270
270
  if (this._loaded) {
271
- RNSound.getCurrentTime(this._key, callback);
271
+ CometChatSoundModule.getCurrentTime(this._key, callback);
272
272
  }
273
273
  }
274
274
  setCurrentTime(value) {
275
275
  if (this._loaded) {
276
- RNSound.setCurrentTime(this._key, value);
276
+ CometChatSoundModule.setCurrentTime(this._key, value);
277
277
  }
278
278
  return this;
279
279
  }
280
280
  // android only
281
281
  setSpeakerphoneOn(value) {
282
282
  if (IsAndroid) {
283
- RNSound.setSpeakerphoneOn(this._key, value);
283
+ CometChatSoundModule.setSpeakerphoneOn(this._key, value);
284
284
  }
285
285
  }
286
286
  isPlaying() {
@@ -288,7 +288,7 @@ class Sound {
288
288
  }
289
289
  async checkOtherAudioPlaying() {
290
290
  try{
291
- return await RNSound.checkOtherAudioPlaying();
291
+ return await CometChatSoundModule.checkOtherAudioPlaying();
292
292
  }
293
293
  catch(error){
294
294
  return false;
@@ -328,9 +328,9 @@ Sound.prototype.setCategory = function(value) {
328
328
  Sound.setCategory(value, false);
329
329
  }
330
330
 
331
- Sound.MAIN_BUNDLE = RNSound.MainBundlePath;
332
- Sound.DOCUMENT = RNSound.NSDocumentDirectory;
333
- Sound.LIBRARY = RNSound.NSLibraryDirectory;
334
- Sound.CACHES = RNSound.NSCachesDirectory;
331
+ Sound.MAIN_BUNDLE = CometChatSoundModule.MainBundlePath;
332
+ Sound.DOCUMENT = CometChatSoundModule.NSDocumentDirectory;
333
+ Sound.LIBRARY = CometChatSoundModule.NSLibraryDirectory;
334
+ Sound.CACHES = CometChatSoundModule.NSCachesDirectory;
335
335
 
336
336
  export default Sound;
@@ -0,0 +1,20 @@
1
+ import { MessageTypeConstants } from "../constants/UIKitConstants";
2
+ import { CardMessage, CustomInteractiveMessage, FormMessage } from "../modals/InteractiveData";
3
+
4
+ export class InteractiveMessageUtils {
5
+
6
+ static convertInteractiveMessage(item: any): any {
7
+ if (item.getDeletedBy() != null) {
8
+ return item;
9
+ }
10
+ switch (item.getType()) {
11
+ case MessageTypeConstants.form:
12
+ return FormMessage.fromJSON(item);
13
+ case MessageTypeConstants.card:
14
+ return CardMessage.fromJSON(item);
15
+ default:
16
+ return CustomInteractiveMessage.fromJSON(item);
17
+ }
18
+ }
19
+
20
+ }
@@ -0,0 +1,20 @@
1
+ export class CometChatNetworkUtils {
2
+
3
+ static async fetcher({ url, method, body, headers }: { url: string, method: string, body: any, headers: any }) {
4
+ try {
5
+ const res = await fetch(url, {
6
+ method: method,
7
+ body: JSON.stringify(body),
8
+ headers: {
9
+ "Content-Type": "application/json",
10
+ ...headers,
11
+ },
12
+ });
13
+ const json = await res.json();
14
+ return res;
15
+ } catch (error) {
16
+ throw error;
17
+ }
18
+ }
19
+
20
+ }
@@ -14,7 +14,7 @@ export class CometChatConversationUtils {
14
14
  return options;
15
15
  }
16
16
 
17
- static getLastMessage(conversation : CometChat.Conversation): CometChat.BaseMessage {
17
+ static getLastMessage(conversation: CometChat.Conversation): CometChat.BaseMessage {
18
18
  let msg = conversation.getLastMessage();
19
19
  if (!msg) {
20
20
  return undefined;
@@ -36,12 +36,12 @@ export class CometChatConversationUtils {
36
36
 
37
37
 
38
38
 
39
- static getMessagePreview = ( lastMessage: CometChat.BaseMessage):string => {
39
+ static getMessagePreview = (lastMessage: CometChat.BaseMessage): string => {
40
40
 
41
- if (lastMessage!=undefined) {
41
+ if (lastMessage != undefined) {
42
42
 
43
43
  if (lastMessage.getDeletedAt() !== undefined) {
44
- return localize("THIS_MESSAGE_DELETED");
44
+ return localize("THIS_MESSAGE_DELETED");
45
45
  }
46
46
 
47
47
  let groupText = "", msgText = "";
@@ -66,8 +66,11 @@ export class CometChatConversationUtils {
66
66
  } else if (lastMessage.getCategory() == CometChat.CATEGORY_CUSTOM as CometChat.MessageCategory) {
67
67
  msgText = lastMessage.getType();
68
68
  } else if (lastMessage.getCategory() == CometChat.CATEGORY_ACTION as CometChat.MessageCategory) {
69
- msgText =(lastMessage as CometChat.Action).getMessage();
70
- } else {
69
+ msgText = (lastMessage as CometChat.Action).getMessage();
70
+ } else if (lastMessage.getCategory() === CometChat.CATEGORY_INTERACTIVE) {
71
+ msgText = lastMessage.getType() === "form" ? `${localize('FORM')} 📋` : `${localize('CARD')} 🪧`;
72
+ }
73
+ else {
71
74
  msgText = lastMessage['metaData']?.pushNotification;
72
75
  }
73
76
  return (msgText)
@@ -1,5 +1,5 @@
1
1
  import React, { useContext } from 'react';
2
- import { View, TouchableOpacity, Text, Image } from "react-native";
2
+ import { View, TouchableOpacity, Text, Image, ActivityIndicator } from "react-native";
3
3
  import { ImageType } from '../../base';
4
4
  import { ButtonStyle, ButtonStyleInterface } from './CometChatButtonStyle';
5
5
  import { CometChatContext } from '../../CometChatContext';
@@ -10,7 +10,7 @@ export interface CometChatButtonInterface {
10
10
  iconUrl?: ImageType,
11
11
  style?: ButtonStyleInterface,
12
12
  onPress?: () => void,
13
-
13
+ isLoading?: boolean,
14
14
  }
15
15
 
16
16
  export const CometChatButton = (props: CometChatButtonInterface) => {
@@ -18,7 +18,8 @@ export const CometChatButton = (props: CometChatButtonInterface) => {
18
18
  iconUrl,
19
19
  onPress,
20
20
  style,
21
- text
21
+ text,
22
+ isLoading
22
23
  } = props;
23
24
 
24
25
  const { theme } = useContext(CometChatContext);
@@ -41,25 +42,34 @@ export const CometChatButton = (props: CometChatButtonInterface) => {
41
42
  });
42
43
 
43
44
  return (
44
- <TouchableOpacity onPress={onPress} style={{alignItems: "center", backgroundColor, borderRadius}}>
45
- <View style={[Style.container, { backgroundColor: iconBackgroundColor, borderRadius: iconCornerRadius, ...border }]}>
46
- <Image
47
- source={iconUrl}
48
- resizeMode="contain"
49
- style={{
50
- height,
51
- width,
52
- backgroundColor: iconBackgroundColor,
53
- borderRadius: iconCornerRadius,
54
- tintColor: iconTint,
55
- ...iconBorder,
56
- }} />
57
- </View>
58
- {
59
- text && <Text style={{
60
- color: textColor,
61
- ...textFont
62
- }}>{text}</Text>
45
+ <TouchableOpacity onPress={onPress} style={[{ alignItems: "center", backgroundColor, borderRadius }, !iconUrl && {
46
+ height, width, justifyContent: "center",
47
+ }]}>
48
+ {!isLoading ? <>
49
+ {Boolean(iconUrl) && <View style={[Style.container, { backgroundColor: iconBackgroundColor, borderRadius: iconCornerRadius, ...border }]}>
50
+ <Image
51
+ source={iconUrl}
52
+ resizeMode="contain"
53
+ style={{
54
+ height,
55
+ width,
56
+ backgroundColor: iconBackgroundColor,
57
+ borderRadius: iconCornerRadius,
58
+ tintColor: iconTint,
59
+ ...iconBorder,
60
+ }} />
61
+ </View>}
62
+ {
63
+ Boolean(text) && <Text style={{
64
+ color: textColor,
65
+ ...textFont
66
+ }}>{text}</Text>
67
+ }
68
+ </>
69
+ :
70
+ <View style={{ position: "absolute", alignSelf: "center" }}>
71
+ <ActivityIndicator size="small" color={textColor} />
72
+ </View>
63
73
  }
64
74
  </TouchableOpacity>
65
75
  )
@@ -0,0 +1,47 @@
1
+ import { BaseStyle, FontStyle } from "../../base";
2
+ import { ButtonStyleInterface } from "../CometChatButton";
3
+ import { ImageBubbleStyleInterface } from "../CometChatImageBubble";
4
+
5
+ export interface CardBubbleStyleInterface extends BaseStyle {
6
+ textFont?: FontStyle;
7
+ textColor?: string;
8
+ padding?: number;
9
+ buttonStyle?: ButtonStyleInterface;
10
+ imageStyle?: ImageBubbleStyleInterface;
11
+ imageResizeMode?: "cover" | "contain" | "stretch" | "repeat" | "center";
12
+ }
13
+
14
+ export class CardBubbleStyle extends BaseStyle {
15
+ textFont?: FontStyle;
16
+ textColor?: string;
17
+ padding?: number;
18
+ buttonStyle?: ButtonStyleInterface;
19
+ imageStyle?: ImageBubbleStyleInterface;
20
+ imageResizeMode?: "cover" | "contain" | "stretch" | "repeat" | "center";
21
+
22
+ constructor({
23
+ height = "auto",
24
+ width = "auto",
25
+ backgroundColor,
26
+ borderRadius,
27
+ textFont,
28
+ textColor,
29
+ padding,
30
+ buttonStyle,
31
+ imageStyle,
32
+ imageResizeMode = "cover",
33
+ }: CardBubbleStyleInterface) {
34
+ super({
35
+ backgroundColor,
36
+ borderRadius,
37
+ height,
38
+ width
39
+ });
40
+ this.textFont = textFont;
41
+ this.textColor = textColor;
42
+ this.padding = padding;
43
+ this.buttonStyle = buttonStyle;
44
+ this.imageStyle = imageStyle;
45
+ this.imageResizeMode = imageResizeMode;
46
+ }
47
+ }
@@ -0,0 +1,173 @@
1
+ import { View, Text, NativeModules } from 'react-native'
2
+ import React, { useEffect, useContext } from 'react'
3
+ import { APIAction, ButtonElement, CardMessage, URLNavigationAction } from '../../modals/InteractiveData'
4
+ import { CometChatImageBubble } from '../CometChatImageBubble';
5
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
6
+ import { CometChatContextType } from '../../base';
7
+ import { CometChatContext } from '../../CometChatContext';
8
+ import { CometChatButton } from '../CometChatButton';
9
+ import { ButtonAction, HTTPSRequestMethods } from '../../constants/UIKitConstants';
10
+ import { CometChatNetworkUtils } from '../../utils/NetworkUtils';
11
+ import { CardBubbleStyle, CardBubbleStyleInterface } from './CardBubbleStyle';
12
+
13
+ const WebView = NativeModules['WebViewManager'];
14
+ export interface CometChatCardBubbleInterface {
15
+ message: CardMessage, // Expect JSON object
16
+ style?: CardBubbleStyleInterface,
17
+ onSubmitClick?: (data: any) => void
18
+ }
19
+
20
+ export const CometChatCardBubble = (props: CometChatCardBubbleInterface) => {
21
+ const {
22
+ message, onSubmitClick, style
23
+ } = props;
24
+
25
+ const { theme } = useContext<CometChatContextType>(CometChatContext);
26
+ const [loggedInUser, setLoggedInUser] = React.useState<CometChat.User>(null);
27
+
28
+ const [interactedElements, setInteractedElements] = React.useState<CometChat.Interaction[]>([]);
29
+
30
+ const _style = new CardBubbleStyle({
31
+ backgroundColor: theme.palette.getBackgroundColor(),
32
+ borderRadius: 5,
33
+ padding: 5,
34
+ imageStyle: {
35
+ aspectRatio: 16 / 9,
36
+ width: "100%",
37
+ borderRadius: 5,
38
+ },
39
+ imageResizeMode: 'cover',
40
+ buttonStyle: {
41
+ backgroundColor: theme.palette.getBackgroundColor(),
42
+ border: { borderWidth: 0 },
43
+ textColor: theme.palette.getPrimary(),
44
+ textFont: { fontSize: 14 },
45
+ height: 35,
46
+ borderRadius: 0,
47
+ },
48
+ textColor: theme.palette.getAccent600(),
49
+ ...style,
50
+ });
51
+
52
+ const {
53
+ backgroundColor,
54
+ borderRadius,
55
+ buttonStyle,
56
+ imageResizeMode,
57
+ imageStyle,
58
+ padding,
59
+ textColor,
60
+ textFont,
61
+ } = _style;
62
+
63
+ useEffect(() => {
64
+ CometChat.getLoggedinUser()
65
+ .then(u => {
66
+ setLoggedInUser(u);
67
+ })
68
+ .catch(e => {
69
+ console.log("Error while getting loggedInUser");
70
+ setLoggedInUser(null);
71
+ });
72
+ setInteractedElements(message.getInteractions() || []);
73
+ }, []);
74
+
75
+ const _renderButton = (data: ButtonElement, isSubmitElement?: boolean) => {
76
+ function onClick() {
77
+ _handleButtonClick(data.getAction(), data.getElementId(), isSubmitElement);
78
+ }
79
+
80
+ function isDisabled() {
81
+ let isSender = message.getSender()?.getUid() == loggedInUser?.['uid'];
82
+
83
+ let allowInteraction = isSender ? message?.["data"]?.["allowSenderInteraction"] : true;
84
+
85
+ let disableAfterInteracted: boolean;
86
+ if (data.getDisableAfterInteracted()) {
87
+ disableAfterInteracted = interactedElements?.some(
88
+ (element) => element.getElementId() === data.getElementId()
89
+ );
90
+ }
91
+ return (disableAfterInteracted || !allowInteraction);
92
+ }
93
+
94
+ return (
95
+ <View style={{ borderTopWidth: 1, borderTopColor: theme.palette.getAccent100(), opacity: isDisabled() ? .7 : 1 }}>
96
+ <CometChatButton
97
+ onPress={isDisabled() ? () => { } : onClick}
98
+ text={data.getButtonText()}
99
+ style={{...buttonStyle, textColor: isDisabled() ? theme.palette.getAccent600() : buttonStyle.textColor }}
100
+ />
101
+ </View>
102
+ );
103
+ }
104
+
105
+ function markAsInteracted(elementId: string) {
106
+ CometChat.markAsInteracted(message?.getId(), elementId).then(
107
+ (response) => {
108
+ const interaction = new CometChat.Interaction(
109
+ elementId,
110
+ new Date().getTime()
111
+ );
112
+ let clonedInteractedElements = [...interactedElements];
113
+ clonedInteractedElements.push(interaction);
114
+ setInteractedElements(clonedInteractedElements);
115
+ }
116
+ )
117
+ .catch((error) => {
118
+ console.log("error while markAsInteracted", error);
119
+ });
120
+ }
121
+
122
+ function _handleButtonClick(action: ButtonElement["action"], elementId: string, isSubmitElement?: boolean) {
123
+ if (isSubmitElement && onSubmitClick) {
124
+ onSubmitClick((action as APIAction).getPayload())
125
+ return;
126
+ }
127
+ switch (action.getActionType()) {
128
+ case ButtonAction.apiAction:
129
+ CometChatNetworkUtils.fetcher({
130
+ url: (action as APIAction).getURL(),
131
+ method: (action as APIAction).getMethod() || HTTPSRequestMethods.POST,
132
+ body: { ...action.getPayload(), cometchatSenderUid: loggedInUser?.['uid'] || "" },
133
+ headers: (action as APIAction).getHeaders(),
134
+ })
135
+ .then((response) => {
136
+ if (response.status === 200) {
137
+ markAsInteracted(elementId);
138
+ }
139
+ })
140
+ .catch((error) => {
141
+ console.log("CometChatNetworkUtils.fetcher error", error);
142
+ });
143
+ break;
144
+ case ButtonAction.urlNavigation:
145
+ const url = (action as URLNavigationAction)?.getURL();
146
+ WebView.openUrl(url);
147
+ markAsInteracted(elementId);
148
+ break;
149
+ case ButtonAction.custom:
150
+ markAsInteracted(elementId);
151
+ break;
152
+ default:
153
+ break;
154
+ }
155
+ }
156
+
157
+ return (
158
+ <View style={{ padding: 5 }}>
159
+ <View style={{ backgroundColor, borderRadius, padding }}>
160
+ {Boolean(message.getImageUrl()) &&
161
+ <CometChatImageBubble
162
+ imageUrl={{ uri: message.getImageUrl() }}
163
+ thumbnailUrl={{ uri: message.getImageUrl() }}
164
+ style={imageStyle}
165
+ resizeMode={imageResizeMode}
166
+ />
167
+ }
168
+ <Text style={[textFont, { marginVertical: 10, color: textColor }]}>{message.getText()}</Text>
169
+ </View>
170
+ {(message.getCardActions())?.map((action, index) => <React.Fragment key={index}>{_renderButton(action)}</React.Fragment>)}
171
+ </View>
172
+ )
173
+ }
@@ -0,0 +1 @@
1
+ export { CometChatCardBubble, CometChatCardBubbleInterface } from './CometChatCardBubble'
@@ -0,0 +1,43 @@
1
+ import { BorderStyle, BorderStyleInterface, FontStyle } from "../../base";
2
+
3
+ export interface CheckBoxStyleInterface {
4
+ titleFont?: FontStyle;
5
+ titleColor?: string;
6
+ border?: BorderStyleInterface;
7
+ activeBackgroundColor?: string;
8
+ inactiveBackgroundColor?: string;
9
+ optionColor?: string;
10
+ optionFont?: FontStyle;
11
+ checkboxTintColor?: string;
12
+ }
13
+
14
+ export class CheckBoxStyle {
15
+ titleFont?: FontStyle;
16
+ titleColor?: string;
17
+ border?: BorderStyleInterface;
18
+ activeBackgroundColor?: string;
19
+ inactiveBackgroundColor?: string;
20
+ optionColor?: string;
21
+ optionFont?: FontStyle;
22
+ checkboxTintColor?: string;
23
+
24
+ constructor({
25
+ titleFont = new FontStyle({}),
26
+ titleColor = "",
27
+ border = new BorderStyle({}),
28
+ activeBackgroundColor = "",
29
+ inactiveBackgroundColor = "",
30
+ optionColor = "",
31
+ optionFont = new FontStyle({}),
32
+ checkboxTintColor = "",
33
+ }: CheckBoxStyleInterface) {
34
+ this.titleFont = titleFont;
35
+ this.titleColor = titleColor;
36
+ this.border = border;
37
+ this.activeBackgroundColor = activeBackgroundColor;
38
+ this.inactiveBackgroundColor = inactiveBackgroundColor;
39
+ this.optionColor = optionColor;
40
+ this.optionFont = optionFont;
41
+ this.checkboxTintColor = checkboxTintColor;
42
+ }
43
+ }