stream-chat-react-native-core 6.3.1 → 6.4.0-beta.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 (179) hide show
  1. package/lib/commonjs/components/Attachment/AudioAttachment.js +255 -216
  2. package/lib/commonjs/components/Attachment/AudioAttachment.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/FileAttachmentGroup.js +11 -11
  4. package/lib/commonjs/components/Attachment/FileAttachmentGroup.js.map +1 -1
  5. package/lib/commonjs/components/Attachment/Gallery.js +9 -0
  6. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  7. package/lib/commonjs/components/ChannelList/ChannelList.js +23 -0
  8. package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
  9. package/lib/commonjs/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js +31 -8
  10. package/lib/commonjs/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js.map +1 -1
  11. package/lib/commonjs/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js +75 -0
  12. package/lib/commonjs/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js.map +1 -0
  13. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js +21 -10
  14. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
  15. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessageNotification.js +23 -7
  16. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessageNotification.js.map +1 -1
  17. package/lib/commonjs/components/ChannelList/hooks/useChannelMembershipState.js +17 -0
  18. package/lib/commonjs/components/ChannelList/hooks/useChannelMembershipState.js.map +1 -0
  19. package/lib/commonjs/components/ChannelList/hooks/useSelectedChannelState.js +32 -0
  20. package/lib/commonjs/components/ChannelList/hooks/useSelectedChannelState.js.map +1 -0
  21. package/lib/commonjs/components/ChannelList/hooks/utils/index.js +102 -0
  22. package/lib/commonjs/components/ChannelList/hooks/utils/index.js.map +1 -0
  23. package/lib/commonjs/components/ChannelList/utils.js +23 -11
  24. package/lib/commonjs/components/ChannelList/utils.js.map +1 -1
  25. package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js +1 -2
  26. package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
  27. package/lib/commonjs/components/ImageGallery/components/ImageGalleryVideoControl.js +24 -13
  28. package/lib/commonjs/components/ImageGallery/components/ImageGalleryVideoControl.js.map +1 -1
  29. package/lib/commonjs/components/Message/Message.js.map +1 -1
  30. package/lib/commonjs/components/MessageInput/FileUploadPreview.js +35 -23
  31. package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
  32. package/lib/commonjs/components/ProgressControl/ProgressControl.js +57 -54
  33. package/lib/commonjs/components/ProgressControl/ProgressControl.js.map +1 -1
  34. package/lib/commonjs/components/ProgressControl/WaveProgressBar.js +52 -52
  35. package/lib/commonjs/components/ProgressControl/WaveProgressBar.js.map +1 -1
  36. package/lib/commonjs/components/index.js +22 -0
  37. package/lib/commonjs/components/index.js.map +1 -1
  38. package/lib/commonjs/contexts/themeContext/utils/theme.js +1 -0
  39. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  40. package/lib/commonjs/hooks/useAudioPlayer.js +158 -0
  41. package/lib/commonjs/hooks/useAudioPlayer.js.map +1 -0
  42. package/lib/commonjs/icons/Archieve.js +33 -0
  43. package/lib/commonjs/icons/Archieve.js.map +1 -0
  44. package/lib/commonjs/icons/Pause.js +2 -2
  45. package/lib/commonjs/icons/Pause.js.map +1 -1
  46. package/lib/commonjs/icons/Play.js +2 -2
  47. package/lib/commonjs/icons/Play.js.map +1 -1
  48. package/lib/commonjs/icons/index.js +11 -0
  49. package/lib/commonjs/icons/index.js.map +1 -1
  50. package/lib/commonjs/native.js.map +1 -1
  51. package/lib/commonjs/types/types.js.map +1 -1
  52. package/lib/commonjs/version.json +1 -1
  53. package/lib/module/components/Attachment/AudioAttachment.js +255 -216
  54. package/lib/module/components/Attachment/AudioAttachment.js.map +1 -1
  55. package/lib/module/components/Attachment/FileAttachmentGroup.js +11 -11
  56. package/lib/module/components/Attachment/FileAttachmentGroup.js.map +1 -1
  57. package/lib/module/components/Attachment/Gallery.js +9 -0
  58. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  59. package/lib/module/components/ChannelList/ChannelList.js +23 -0
  60. package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
  61. package/lib/module/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js +31 -8
  62. package/lib/module/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js.map +1 -1
  63. package/lib/module/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js +75 -0
  64. package/lib/module/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js.map +1 -0
  65. package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js +21 -10
  66. package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
  67. package/lib/module/components/ChannelList/hooks/listeners/useNewMessageNotification.js +23 -7
  68. package/lib/module/components/ChannelList/hooks/listeners/useNewMessageNotification.js.map +1 -1
  69. package/lib/module/components/ChannelList/hooks/useChannelMembershipState.js +17 -0
  70. package/lib/module/components/ChannelList/hooks/useChannelMembershipState.js.map +1 -0
  71. package/lib/module/components/ChannelList/hooks/useSelectedChannelState.js +32 -0
  72. package/lib/module/components/ChannelList/hooks/useSelectedChannelState.js.map +1 -0
  73. package/lib/module/components/ChannelList/hooks/utils/index.js +102 -0
  74. package/lib/module/components/ChannelList/hooks/utils/index.js.map +1 -0
  75. package/lib/module/components/ChannelList/utils.js +23 -11
  76. package/lib/module/components/ChannelList/utils.js.map +1 -1
  77. package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js +1 -2
  78. package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
  79. package/lib/module/components/ImageGallery/components/ImageGalleryVideoControl.js +24 -13
  80. package/lib/module/components/ImageGallery/components/ImageGalleryVideoControl.js.map +1 -1
  81. package/lib/module/components/Message/Message.js.map +1 -1
  82. package/lib/module/components/MessageInput/FileUploadPreview.js +35 -23
  83. package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
  84. package/lib/module/components/ProgressControl/ProgressControl.js +57 -54
  85. package/lib/module/components/ProgressControl/ProgressControl.js.map +1 -1
  86. package/lib/module/components/ProgressControl/WaveProgressBar.js +52 -52
  87. package/lib/module/components/ProgressControl/WaveProgressBar.js.map +1 -1
  88. package/lib/module/components/index.js +22 -0
  89. package/lib/module/components/index.js.map +1 -1
  90. package/lib/module/contexts/themeContext/utils/theme.js +1 -0
  91. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  92. package/lib/module/hooks/useAudioPlayer.js +158 -0
  93. package/lib/module/hooks/useAudioPlayer.js.map +1 -0
  94. package/lib/module/icons/Archieve.js +33 -0
  95. package/lib/module/icons/Archieve.js.map +1 -0
  96. package/lib/module/icons/Pause.js +2 -2
  97. package/lib/module/icons/Pause.js.map +1 -1
  98. package/lib/module/icons/Play.js +2 -2
  99. package/lib/module/icons/Play.js.map +1 -1
  100. package/lib/module/icons/index.js +11 -0
  101. package/lib/module/icons/index.js.map +1 -1
  102. package/lib/module/native.js.map +1 -1
  103. package/lib/module/types/types.js.map +1 -1
  104. package/lib/module/version.json +1 -1
  105. package/lib/typescript/components/Attachment/AudioAttachment.d.ts +2 -2
  106. package/lib/typescript/components/Attachment/AudioAttachment.d.ts.map +1 -1
  107. package/lib/typescript/components/Attachment/FileAttachmentGroup.d.ts.map +1 -1
  108. package/lib/typescript/components/Attachment/Gallery.d.ts.map +1 -1
  109. package/lib/typescript/components/ChannelList/ChannelList.d.ts +20 -6
  110. package/lib/typescript/components/ChannelList/ChannelList.d.ts.map +1 -1
  111. package/lib/typescript/components/ChannelList/hooks/listeners/useAddedToChannelNotification.d.ts +4 -3
  112. package/lib/typescript/components/ChannelList/hooks/listeners/useAddedToChannelNotification.d.ts.map +1 -1
  113. package/lib/typescript/components/ChannelList/hooks/listeners/useChannelMemberUpdated.d.ts +12 -0
  114. package/lib/typescript/components/ChannelList/hooks/listeners/useChannelMemberUpdated.d.ts.map +1 -0
  115. package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessage.d.ts +4 -3
  116. package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessage.d.ts.map +1 -1
  117. package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessageNotification.d.ts +4 -3
  118. package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessageNotification.d.ts.map +1 -1
  119. package/lib/typescript/components/ChannelList/hooks/useChannelMembershipState.d.ts +5 -0
  120. package/lib/typescript/components/ChannelList/hooks/useChannelMembershipState.d.ts.map +1 -0
  121. package/lib/typescript/components/ChannelList/hooks/useSelectedChannelState.d.ts +13 -0
  122. package/lib/typescript/components/ChannelList/hooks/useSelectedChannelState.d.ts.map +1 -0
  123. package/lib/typescript/components/ChannelList/hooks/utils/index.d.ts +22 -0
  124. package/lib/typescript/components/ChannelList/hooks/utils/index.d.ts.map +1 -0
  125. package/lib/typescript/components/ChannelList/utils.d.ts +10 -4
  126. package/lib/typescript/components/ChannelList/utils.d.ts.map +1 -1
  127. package/lib/typescript/components/ChannelPreview/ChannelPreviewMessenger.d.ts.map +1 -1
  128. package/lib/typescript/components/ImageGallery/components/ImageGalleryVideoControl.d.ts.map +1 -1
  129. package/lib/typescript/components/Message/Message.d.ts +22 -11
  130. package/lib/typescript/components/Message/Message.d.ts.map +1 -1
  131. package/lib/typescript/components/MessageInput/FileUploadPreview.d.ts.map +1 -1
  132. package/lib/typescript/components/ProgressControl/ProgressControl.d.ts +35 -2
  133. package/lib/typescript/components/ProgressControl/ProgressControl.d.ts.map +1 -1
  134. package/lib/typescript/components/ProgressControl/WaveProgressBar.d.ts +27 -0
  135. package/lib/typescript/components/ProgressControl/WaveProgressBar.d.ts.map +1 -1
  136. package/lib/typescript/components/index.d.ts +2 -0
  137. package/lib/typescript/components/index.d.ts.map +1 -1
  138. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +1 -0
  139. package/lib/typescript/contexts/themeContext/utils/theme.d.ts.map +1 -1
  140. package/lib/typescript/hooks/useAudioPlayer.d.ts +16 -0
  141. package/lib/typescript/hooks/useAudioPlayer.d.ts.map +1 -0
  142. package/lib/typescript/icons/Archieve.d.ts +4 -0
  143. package/lib/typescript/icons/Archieve.d.ts.map +1 -0
  144. package/lib/typescript/icons/Pause.d.ts.map +1 -1
  145. package/lib/typescript/icons/index.d.ts +1 -0
  146. package/lib/typescript/icons/index.d.ts.map +1 -1
  147. package/lib/typescript/native.d.ts +10 -3
  148. package/lib/typescript/native.d.ts.map +1 -1
  149. package/lib/typescript/types/types.d.ts +5 -1
  150. package/lib/typescript/types/types.d.ts.map +1 -1
  151. package/package.json +4 -2
  152. package/src/components/Attachment/AudioAttachment.tsx +173 -137
  153. package/src/components/Attachment/FileAttachmentGroup.tsx +9 -16
  154. package/src/components/Attachment/Gallery.tsx +3 -0
  155. package/src/components/ChannelList/ChannelList.tsx +38 -3
  156. package/src/components/ChannelList/hooks/listeners/useAddedToChannelNotification.ts +32 -3
  157. package/src/components/ChannelList/hooks/listeners/useChannelMemberUpdated.ts +116 -0
  158. package/src/components/ChannelList/hooks/listeners/useNewMessage.ts +46 -17
  159. package/src/components/ChannelList/hooks/listeners/useNewMessageNotification.ts +18 -3
  160. package/src/components/ChannelList/hooks/useChannelMembershipState.ts +22 -0
  161. package/src/components/ChannelList/hooks/useSelectedChannelState.ts +57 -0
  162. package/src/components/ChannelList/hooks/utils/index.ts +130 -0
  163. package/src/components/ChannelList/utils.ts +50 -14
  164. package/src/components/ChannelPreview/ChannelPreviewMessenger.tsx +1 -2
  165. package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx +23 -13
  166. package/src/components/Message/Message.tsx +26 -4
  167. package/src/components/MessageInput/FileUploadPreview.tsx +29 -28
  168. package/src/components/ProgressControl/ProgressControl.tsx +115 -92
  169. package/src/components/ProgressControl/WaveProgressBar.tsx +96 -59
  170. package/src/components/index.ts +2 -0
  171. package/src/contexts/themeContext/utils/theme.ts +2 -0
  172. package/src/hooks/useAudioPlayer.ts +59 -0
  173. package/src/icons/Archieve.tsx +10 -0
  174. package/src/icons/Pause.tsx +2 -5
  175. package/src/icons/Play.tsx +2 -2
  176. package/src/icons/index.ts +1 -0
  177. package/src/native.ts +11 -3
  178. package/src/types/types.ts +14 -1
  179. package/src/version.json +1 -1
@@ -12,8 +12,10 @@ var _reactNative = require("react-native");
12
12
  var _dayjs = _interopRequireDefault(require("dayjs"));
13
13
  var _duration = _interopRequireDefault(require("dayjs/plugin/duration"));
14
14
  var _contexts = require("../../contexts");
15
+ var _useAudioPlayer2 = require("../../hooks/useAudioPlayer");
15
16
  var _icons = require("../../icons");
16
17
  var _native = require("../../native");
18
+ var _types = require("../../types/types");
17
19
  var _getTrimmedAttachmentTitle = require("../../utils/getTrimmedAttachmentTitle");
18
20
  var _ProgressControl = require("../ProgressControl/ProgressControl");
19
21
  var _WaveProgressBar = require("../ProgressControl/WaveProgressBar");
@@ -24,19 +26,14 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
24
26
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
25
27
  _dayjs["default"].extend(_duration["default"]);
26
28
  var AudioAttachment = function AudioAttachment(props) {
27
- var _item$duration;
28
- var _useState = (0, _react.useState)(0),
29
+ var _useState = (0, _react.useState)(1.0),
29
30
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
30
- width = _useState2[0],
31
- setWidth = _useState2[1];
32
- var _useState3 = (0, _react.useState)(0),
31
+ currentSpeed = _useState2[0],
32
+ setCurrentSpeed = _useState2[1];
33
+ var _useState3 = (0, _react.useState)(false),
33
34
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
34
- progressControlTextWidth = _useState4[0],
35
- setProgressControlTextWidth = _useState4[1];
36
- var _useState5 = (0, _react.useState)(1.0),
37
- _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
38
- currentSpeed = _useState6[0],
39
- setCurrentSpeed = _useState6[1];
35
+ audioFinished = _useState4[0],
36
+ setAudioFinished = _useState4[1];
40
37
  var soundRef = _react["default"].useRef(null);
41
38
  var _props$hideProgressBa = props.hideProgressBar,
42
39
  hideProgressBar = _props$hideProgressBa === void 0 ? false : _props$hideProgressBa,
@@ -47,104 +44,155 @@ var AudioAttachment = function AudioAttachment(props) {
47
44
  _props$showSpeedSetti = props.showSpeedSettings,
48
45
  showSpeedSettings = _props$showSpeedSetti === void 0 ? false : _props$showSpeedSetti,
49
46
  testID = props.testID;
47
+ var _useAudioPlayer = (0, _useAudioPlayer2.useAudioPlayer)({
48
+ soundRef: soundRef
49
+ }),
50
+ changeAudioSpeed = _useAudioPlayer.changeAudioSpeed,
51
+ pauseAudio = _useAudioPlayer.pauseAudio,
52
+ playAudio = _useAudioPlayer.playAudio,
53
+ seekAudio = _useAudioPlayer.seekAudio;
54
+ var isExpoCLI = _native.SDK === 'stream-chat-expo';
55
+ var isVoiceRecording = item.type === _types.FileTypes.VoiceRecording;
50
56
  var handleLoad = function handleLoad(payload) {
51
- onLoad(item.id, item.duration || payload.duration);
57
+ if (isVoiceRecording && item.duration) {
58
+ onLoad(item.id, item.duration);
59
+ } else {
60
+ onLoad(item.id, item.duration || payload.duration);
61
+ }
52
62
  };
53
63
  var handleProgress = function handleProgress(data) {
54
- if (data.currentTime <= data.seekableDuration) {
55
- onProgress(item.id, data.currentTime);
64
+ var currentTime = data.currentTime,
65
+ seekableDuration = data.seekableDuration;
66
+ if (isVoiceRecording && item.duration) {
67
+ if (currentTime < item.duration && !audioFinished) {
68
+ onProgress(item.id, currentTime / item.duration);
69
+ } else {
70
+ setAudioFinished(true);
71
+ }
72
+ } else {
73
+ if (currentTime < seekableDuration && !audioFinished) {
74
+ onProgress(item.id, currentTime / seekableDuration);
75
+ } else {
76
+ setAudioFinished(true);
77
+ }
56
78
  }
57
79
  };
58
- var handleEnd = function handleEnd() {
59
- onPlayPause(item.id, true);
60
- onProgress(item.id, item.duration, true);
80
+ var onSeek = function onSeek(seekResponse) {
81
+ setAudioFinished(false);
82
+ onProgress(item.id, seekResponse.currentTime / item.duration);
61
83
  };
62
84
  var handlePlayPause = function () {
63
- var _ref = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(isPausedStatusAvailable) {
85
+ var _ref = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
64
86
  return _regenerator["default"].wrap(function _callee$(_context) {
65
87
  while (1) switch (_context.prev = _context.next) {
66
88
  case 0:
67
- if (!soundRef.current) {
68
- _context.next = 20;
69
- break;
70
- }
71
- if (!(isPausedStatusAvailable === undefined)) {
72
- _context.next = 19;
73
- break;
74
- }
75
- if (item.progress === 1) {
76
- if (soundRef.current.seek) soundRef.current.seek(0);
77
- if (soundRef.current.setPositionAsync) soundRef.current.setPositionAsync(0);
78
- }
79
89
  if (!item.paused) {
80
- _context.next = 13;
90
+ _context.next = 7;
81
91
  break;
82
92
  }
83
- if (!soundRef.current.playAsync) {
84
- _context.next = 7;
93
+ if (!isExpoCLI) {
94
+ _context.next = 4;
85
95
  break;
86
96
  }
87
- _context.next = 7;
88
- return soundRef.current.playAsync();
97
+ _context.next = 4;
98
+ return playAudio();
99
+ case 4:
100
+ onPlayPause(item.id, false);
101
+ _context.next = 11;
102
+ break;
89
103
  case 7:
90
- if (!soundRef.current.setProgressUpdateIntervalAsync) {
104
+ if (!isExpoCLI) {
91
105
  _context.next = 10;
92
106
  break;
93
107
  }
94
108
  _context.next = 10;
95
- return soundRef.current.setProgressUpdateIntervalAsync(60);
109
+ return pauseAudio();
96
110
  case 10:
97
- onPlayPause(item.id, false);
98
- _context.next = 17;
99
- break;
100
- case 13:
101
- if (!soundRef.current.pauseAsync) {
102
- _context.next = 16;
103
- break;
104
- }
105
- _context.next = 16;
106
- return soundRef.current.pauseAsync();
107
- case 16:
108
111
  onPlayPause(item.id, true);
109
- case 17:
110
- _context.next = 20;
111
- break;
112
- case 19:
113
- onPlayPause(item.id, isPausedStatusAvailable);
114
- case 20:
112
+ case 11:
115
113
  case "end":
116
114
  return _context.stop();
117
115
  }
118
116
  }, _callee);
119
117
  }));
120
- return function handlePlayPause(_x) {
118
+ return function handlePlayPause() {
121
119
  return _ref.apply(this, arguments);
122
120
  };
123
121
  }();
124
- var handleProgressDrag = function () {
125
- var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(position) {
126
- var _soundRef$current, _soundRef$current2;
122
+ var handleEnd = function () {
123
+ var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2() {
127
124
  return _regenerator["default"].wrap(function _callee2$(_context2) {
128
125
  while (1) switch (_context2.prev = _context2.next) {
129
126
  case 0:
130
- onProgress(item.id, position);
131
- if ((_soundRef$current = soundRef.current) != null && _soundRef$current.seek) soundRef.current.seek(position);
132
- if (!((_soundRef$current2 = soundRef.current) != null && _soundRef$current2.setPositionAsync)) {
133
- _context2.next = 5;
134
- break;
135
- }
136
- _context2.next = 5;
137
- return soundRef.current.setPositionAsync(position * 1000);
138
- case 5:
127
+ setAudioFinished(false);
128
+ _context2.next = 3;
129
+ return pauseAudio();
130
+ case 3:
131
+ onPlayPause(item.id, true);
132
+ _context2.next = 6;
133
+ return seekAudio(0);
134
+ case 6:
139
135
  case "end":
140
136
  return _context2.stop();
141
137
  }
142
138
  }, _callee2);
143
139
  }));
144
- return function handleProgressDrag(_x2) {
140
+ return function handleEnd() {
145
141
  return _ref2.apply(this, arguments);
146
142
  };
147
143
  }();
144
+ var dragStart = function () {
145
+ var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
146
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
147
+ while (1) switch (_context3.prev = _context3.next) {
148
+ case 0:
149
+ if (!isExpoCLI) {
150
+ _context3.next = 3;
151
+ break;
152
+ }
153
+ _context3.next = 3;
154
+ return pauseAudio();
155
+ case 3:
156
+ onPlayPause(item.id, true);
157
+ case 4:
158
+ case "end":
159
+ return _context3.stop();
160
+ }
161
+ }, _callee3);
162
+ }));
163
+ return function dragStart() {
164
+ return _ref3.apply(this, arguments);
165
+ };
166
+ }();
167
+ var dragProgress = function dragProgress(progress) {
168
+ onProgress(item.id, progress);
169
+ };
170
+ var dragEnd = function () {
171
+ var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(progress) {
172
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
173
+ while (1) switch (_context4.prev = _context4.next) {
174
+ case 0:
175
+ _context4.next = 2;
176
+ return seekAudio(progress * item.duration);
177
+ case 2:
178
+ if (!isExpoCLI) {
179
+ _context4.next = 5;
180
+ break;
181
+ }
182
+ _context4.next = 5;
183
+ return playAudio();
184
+ case 5:
185
+ onPlayPause(item.id, false);
186
+ case 6:
187
+ case "end":
188
+ return _context4.stop();
189
+ }
190
+ }, _callee4);
191
+ }));
192
+ return function dragEnd(_x) {
193
+ return _ref4.apply(this, arguments);
194
+ };
195
+ }();
148
196
  var onPlaybackStatusUpdate = function onPlaybackStatusUpdate(playbackStatus) {
149
197
  if (!playbackStatus.isLoaded) {
150
198
  if (playbackStatus.error) {
@@ -155,48 +203,65 @@ var AudioAttachment = function AudioAttachment(props) {
155
203
  positionMillis = playbackStatus.positionMillis;
156
204
  if (item.duration === 0) {
157
205
  onLoad(item.id, durationMillis / 1000);
206
+ } else {
207
+ if (isVoiceRecording && item.duration) {
208
+ onLoad(item.id, item.duration);
209
+ } else {
210
+ onLoad(item.id, durationMillis / 1000);
211
+ }
158
212
  }
159
213
  if (playbackStatus.isPlaying) {
160
- onProgress(item.id, positionMillis / 1000);
214
+ if (isVoiceRecording && item.duration) {
215
+ if (positionMillis <= item.duration * 1000) {
216
+ onProgress(item.id, positionMillis / (item.duration * 1000));
217
+ }
218
+ } else {
219
+ if (positionMillis <= durationMillis) {
220
+ onProgress(item.id, positionMillis / durationMillis);
221
+ }
222
+ }
161
223
  } else {}
162
224
  if (playbackStatus.isBuffering) {}
163
225
  if (playbackStatus.didJustFinish && !playbackStatus.isLooping) {
226
+ onProgress(item.id, 1);
164
227
  handleEnd();
165
228
  }
166
229
  }
167
230
  };
168
231
  (0, _react.useEffect)(function () {
169
- if (_native.Sound.Player === null) {
232
+ if (isExpoCLI) {
170
233
  var initiateSound = function () {
171
- var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
172
- return _regenerator["default"].wrap(function _callee3$(_context3) {
173
- while (1) switch (_context3.prev = _context3.next) {
234
+ var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5() {
235
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
236
+ while (1) switch (_context5.prev = _context5.next) {
174
237
  case 0:
175
238
  if (!(item && item.file && item.file.uri)) {
176
- _context3.next = 4;
239
+ _context5.next = 4;
177
240
  break;
178
241
  }
179
- _context3.next = 3;
242
+ _context5.next = 3;
180
243
  return _native.Sound.initializeSound({
181
244
  uri: item.file.uri
182
- }, {}, onPlaybackStatusUpdate);
245
+ }, {
246
+ progressUpdateIntervalMillis: 100
247
+ }, onPlaybackStatusUpdate);
183
248
  case 3:
184
- soundRef.current = _context3.sent;
249
+ soundRef.current = _context5.sent;
185
250
  case 4:
186
251
  case "end":
187
- return _context3.stop();
252
+ return _context5.stop();
188
253
  }
189
- }, _callee3);
254
+ }, _callee5);
190
255
  }));
191
256
  return function initiateSound() {
192
- return _ref3.apply(this, arguments);
257
+ return _ref5.apply(this, arguments);
193
258
  };
194
259
  }();
195
260
  initiateSound();
196
261
  }
197
262
  return function () {
198
- var _soundRef$current3;
199
- if ((_soundRef$current3 = soundRef.current) != null && _soundRef$current3.stopAsync && soundRef.current.unloadAsync) {
263
+ var _soundRef$current;
264
+ if ((_soundRef$current = soundRef.current) != null && _soundRef$current.stopAsync && soundRef.current.unloadAsync) {
200
265
  soundRef.current.stopAsync();
201
266
  soundRef.current.unloadAsync();
202
267
  }
@@ -204,109 +269,84 @@ var AudioAttachment = function AudioAttachment(props) {
204
269
  }, []);
205
270
  (0, _react.useEffect)(function () {
206
271
  var initalPlayPause = function () {
207
- var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4() {
208
- return _regenerator["default"].wrap(function _callee4$(_context4) {
209
- while (1) switch (_context4.prev = _context4.next) {
272
+ var _ref6 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee6() {
273
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
274
+ while (1) switch (_context6.prev = _context6.next) {
210
275
  case 0:
211
- if (!soundRef.current) {
212
- _context4.next = 13;
276
+ if (isExpoCLI) {
277
+ _context6.next = 2;
213
278
  break;
214
279
  }
280
+ return _context6.abrupt("return");
281
+ case 2:
215
282
  if (!item.paused) {
216
- _context4.next = 7;
217
- break;
218
- }
219
- if (!soundRef.current.pauseAsync) {
220
- _context4.next = 5;
283
+ _context6.next = 7;
221
284
  break;
222
285
  }
223
- _context4.next = 5;
224
- return soundRef.current.pauseAsync();
286
+ _context6.next = 5;
287
+ return pauseAudio();
225
288
  case 5:
226
- _context4.next = 13;
289
+ _context6.next = 9;
227
290
  break;
228
291
  case 7:
229
- if (!soundRef.current.playAsync) {
230
- _context4.next = 10;
231
- break;
232
- }
233
- _context4.next = 10;
234
- return soundRef.current.playAsync();
235
- case 10:
236
- if (!soundRef.current.setProgressUpdateIntervalAsync) {
237
- _context4.next = 13;
238
- break;
239
- }
240
- _context4.next = 13;
241
- return soundRef.current.setProgressUpdateIntervalAsync(60);
242
- case 13:
292
+ _context6.next = 9;
293
+ return playAudio();
294
+ case 9:
243
295
  case "end":
244
- return _context4.stop();
296
+ return _context6.stop();
245
297
  }
246
- }, _callee4);
298
+ }, _callee6);
247
299
  }));
248
300
  return function initalPlayPause() {
249
- return _ref4.apply(this, arguments);
301
+ return _ref6.apply(this, arguments);
250
302
  };
251
303
  }();
252
304
  if (!_native.Sound.Player) {
253
305
  initalPlayPause();
254
306
  }
255
- }, [item.paused]);
307
+ }, [item.paused, isExpoCLI, pauseAudio, playAudio]);
256
308
  var onSpeedChangeHandler = function () {
257
- var _ref5 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5() {
258
- return _regenerator["default"].wrap(function _callee5$(_context5) {
259
- while (1) switch (_context5.prev = _context5.next) {
309
+ var _ref7 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7() {
310
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
311
+ while (1) switch (_context7.prev = _context7.next) {
260
312
  case 0:
261
313
  if (!(currentSpeed === 2.0)) {
262
- _context5.next = 7;
314
+ _context7.next = 6;
263
315
  break;
264
316
  }
265
317
  setCurrentSpeed(1.0);
266
- if (!(soundRef.current && soundRef.current.setRateAsync)) {
267
- _context5.next = 5;
268
- break;
269
- }
270
- _context5.next = 5;
271
- return soundRef.current.setRateAsync(1.0);
272
- case 5:
273
- _context5.next = 19;
318
+ _context7.next = 4;
319
+ return changeAudioSpeed(1.0);
320
+ case 4:
321
+ _context7.next = 16;
274
322
  break;
275
- case 7:
323
+ case 6:
276
324
  if (!(currentSpeed === 1.0)) {
277
- _context5.next = 14;
325
+ _context7.next = 12;
278
326
  break;
279
327
  }
280
328
  setCurrentSpeed(1.5);
281
- if (!(soundRef.current && soundRef.current.setRateAsync)) {
282
- _context5.next = 12;
283
- break;
284
- }
285
- _context5.next = 12;
286
- return soundRef.current.setRateAsync(1.5);
287
- case 12:
288
- _context5.next = 19;
329
+ _context7.next = 10;
330
+ return changeAudioSpeed(1.5);
331
+ case 10:
332
+ _context7.next = 16;
289
333
  break;
290
- case 14:
334
+ case 12:
291
335
  if (!(currentSpeed === 1.5)) {
292
- _context5.next = 19;
336
+ _context7.next = 16;
293
337
  break;
294
338
  }
295
339
  setCurrentSpeed(2.0);
296
- if (!(soundRef.current && soundRef.current.setRateAsync)) {
297
- _context5.next = 19;
298
- break;
299
- }
300
- _context5.next = 19;
301
- return soundRef.current.setRateAsync(2.0);
302
- case 19:
340
+ _context7.next = 16;
341
+ return changeAudioSpeed(2.0);
342
+ case 16:
303
343
  case "end":
304
- return _context5.stop();
344
+ return _context7.stop();
305
345
  }
306
- }, _callee5);
346
+ }, _callee7);
307
347
  }));
308
348
  return function onSpeedChangeHandler() {
309
- return _ref5.apply(this, arguments);
349
+ return _ref7.apply(this, arguments);
310
350
  };
311
351
  }();
312
352
  var _useTheme = (0, _contexts.useTheme)(),
@@ -329,8 +369,13 @@ var AudioAttachment = function AudioAttachment(props) {
329
369
  static_white = _useTheme$theme$color.static_white,
330
370
  white = _useTheme$theme$color.white,
331
371
  filenameText = _useTheme$theme.messageInput.fileUploadPreview.filenameText;
332
- var progressValueInSeconds = item.duration * item.progress;
333
- var progressDuration = progressValueInSeconds ? progressValueInSeconds / 3600 >= 1 ? _dayjs["default"].duration(progressValueInSeconds, 'second').format('HH:mm:ss') : _dayjs["default"].duration(progressValueInSeconds, 'second').format('mm:ss') : _dayjs["default"].duration((_item$duration = item.duration) != null ? _item$duration : 0, 'second').format('mm:ss');
372
+ var progressValueInSeconds = (0, _react.useMemo)(function () {
373
+ return item.duration * item.progress;
374
+ }, [item.duration, item.progress]);
375
+ var progressDuration = (0, _react.useMemo)(function () {
376
+ var _item$duration;
377
+ return progressValueInSeconds ? progressValueInSeconds / 3600 >= 1 ? _dayjs["default"].duration(progressValueInSeconds, 'second').format('HH:mm:ss') : _dayjs["default"].duration(progressValueInSeconds, 'second').format('mm:ss') : _dayjs["default"].duration((_item$duration = item.duration) != null ? _item$duration : 0, 'second').format('mm:ss');
378
+ }, [progressValueInSeconds, item.duration]);
334
379
  return (0, _jsxRuntime.jsxs)(_reactNative.View, {
335
380
  accessibilityLabel: "audio-attachment-preview",
336
381
  style: [styles.container, {
@@ -338,30 +383,27 @@ var AudioAttachment = function AudioAttachment(props) {
338
383
  borderColor: grey_whisper
339
384
  }, container],
340
385
  testID: testID,
341
- children: [(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
342
- accessibilityLabel: "Play Pause Button",
343
- onPress: function onPress() {
344
- return handlePlayPause();
345
- },
346
- style: [styles.playPauseButton, {
347
- backgroundColor: static_white,
348
- shadowColor: black
349
- }, playPauseButton],
350
- children: item.paused ? (0, _jsxRuntime.jsx)(_icons.Play, {
351
- fill: static_black,
352
- height: 32,
353
- width: 32
354
- }) : (0, _jsxRuntime.jsx)(_icons.Pause, {
355
- fill: static_black,
356
- height: 32,
357
- width: 32
386
+ children: [(0, _jsxRuntime.jsx)(_reactNative.View, {
387
+ style: [styles.leftContainer, leftContainer],
388
+ children: (0, _jsxRuntime.jsx)(_reactNative.Pressable, {
389
+ accessibilityLabel: "Play Pause Button",
390
+ onPress: handlePlayPause,
391
+ style: [styles.playPauseButton, {
392
+ backgroundColor: static_white,
393
+ shadowColor: black
394
+ }, playPauseButton],
395
+ children: item.paused ? (0, _jsxRuntime.jsx)(_icons.Play, {
396
+ fill: static_black,
397
+ height: 32,
398
+ width: 32
399
+ }) : (0, _jsxRuntime.jsx)(_icons.Pause, {
400
+ fill: static_black,
401
+ height: 32,
402
+ width: 32
403
+ })
358
404
  })
359
405
  }), (0, _jsxRuntime.jsxs)(_reactNative.View, {
360
- onLayout: function onLayout(_ref6) {
361
- var nativeEvent = _ref6.nativeEvent;
362
- setWidth(nativeEvent.layout.width);
363
- },
364
- style: [styles.leftContainer, leftContainer],
406
+ style: [styles.centerContainer],
365
407
  children: [(0, _jsxRuntime.jsx)(_reactNative.Text, {
366
408
  accessibilityLabel: "File Name",
367
409
  numberOfLines: 1,
@@ -375,20 +417,7 @@ var AudioAttachment = function AudioAttachment(props) {
375
417
  children: (0, _getTrimmedAttachmentTitle.getTrimmedAttachmentTitle)(item.file.name)
376
418
  }), (0, _jsxRuntime.jsxs)(_reactNative.View, {
377
419
  style: styles.audioInfo,
378
- children: [_native.Sound.Player && (0, _jsxRuntime.jsx)(_native.Sound.Player, {
379
- onEnd: handleEnd,
380
- onLoad: handleLoad,
381
- onProgress: handleProgress,
382
- paused: item.paused,
383
- rate: currentSpeed,
384
- soundRef: soundRef,
385
- testID: "sound-player",
386
- uri: item.file.uri
387
- }), (0, _jsxRuntime.jsx)(_reactNative.Text, {
388
- onLayout: function onLayout(_ref7) {
389
- var nativeEvent = _ref7.nativeEvent;
390
- setProgressControlTextWidth(nativeEvent.layout.width);
391
- },
420
+ children: [(0, _jsxRuntime.jsx)(_reactNative.Text, {
392
421
  style: [styles.progressDurationText, {
393
422
  color: grey_dark
394
423
  }, progressDurationText],
@@ -396,30 +425,36 @@ var AudioAttachment = function AudioAttachment(props) {
396
425
  }), !hideProgressBar && (0, _jsxRuntime.jsx)(_reactNative.View, {
397
426
  style: [styles.progressControlContainer, progressControlContainer],
398
427
  children: item.file.waveform_data ? (0, _jsxRuntime.jsx)(_WaveProgressBar.WaveProgressBar, {
399
- amplitudesCount: 35,
400
- onPlayPause: handlePlayPause,
401
- onProgressDrag: function onProgressDrag(position) {
402
- if (item.file.waveform_data) {
403
- var progress = position / 30 * item.duration;
404
- handleProgressDrag(progress);
405
- }
406
- },
428
+ amplitudesCount: 30,
429
+ onEndDrag: dragEnd,
430
+ onProgressDrag: dragProgress,
431
+ onStartDrag: dragStart,
407
432
  progress: item.progress,
408
433
  waveformData: item.file.waveform_data
409
434
  }) : (0, _jsxRuntime.jsx)(_ProgressControl.ProgressControl, {
410
435
  duration: item.duration,
411
436
  filledColor: accent_blue,
412
- onPlayPause: handlePlayPause,
413
- onProgressDrag: handleProgressDrag,
437
+ onEndDrag: dragEnd,
438
+ onProgressDrag: dragProgress,
439
+ onStartDrag: dragStart,
414
440
  progress: item.progress,
415
- testID: "progress-control",
416
- width: width - progressControlTextWidth
441
+ testID: "progress-control"
417
442
  })
418
443
  })]
444
+ }), _native.Sound.Player && (0, _jsxRuntime.jsx)(_native.Sound.Player, {
445
+ onEnd: handleEnd,
446
+ onLoad: handleLoad,
447
+ onProgress: handleProgress,
448
+ onSeek: onSeek,
449
+ paused: item.paused,
450
+ rate: currentSpeed,
451
+ soundRef: soundRef,
452
+ testID: "sound-player",
453
+ uri: item.file.uri
419
454
  })]
420
- }), showSpeedSettings && (0, _jsxRuntime.jsx)(_reactNative.View, {
455
+ }), showSpeedSettings ? (0, _jsxRuntime.jsx)(_reactNative.View, {
421
456
  style: [styles.rightContainer, rightContainer],
422
- children: item.progress === 0 || item.progress === 1 ? (0, _jsxRuntime.jsx)(_icons.Audio, {
457
+ children: item.paused ? (0, _jsxRuntime.jsx)(_icons.Audio, {
423
458
  fill: '#ffffff'
424
459
  }) : (0, _jsxRuntime.jsx)(_reactNative.Pressable, {
425
460
  onPress: onSpeedChangeHandler,
@@ -429,44 +464,46 @@ var AudioAttachment = function AudioAttachment(props) {
429
464
  }, speedChangeButton],
430
465
  children: (0, _jsxRuntime.jsx)(_reactNative.Text, {
431
466
  style: [styles.speedChangeButtonText, speedChangeButtonText],
432
- children: "x".concat(currentSpeed)
467
+ children: "x".concat(currentSpeed.toFixed(1))
433
468
  })
434
469
  })
435
- })]
470
+ }) : null]
436
471
  });
437
472
  };
438
473
  exports.AudioAttachment = AudioAttachment;
439
474
  var styles = _reactNative.StyleSheet.create({
440
475
  audioInfo: {
441
476
  alignItems: 'center',
442
- display: 'flex',
443
477
  flexDirection: 'row'
444
478
  },
479
+ centerContainer: {
480
+ flexGrow: 1
481
+ },
445
482
  container: {
446
483
  alignItems: 'center',
447
484
  borderRadius: 12,
448
485
  borderWidth: 1,
486
+ flex: 1,
449
487
  flexDirection: 'row',
450
- paddingHorizontal: 8,
488
+ paddingLeft: 8,
489
+ paddingRight: 16,
451
490
  paddingVertical: 12
452
491
  },
453
492
  filenameText: {
454
493
  fontSize: 14,
455
494
  fontWeight: 'bold',
456
- paddingBottom: 12
495
+ marginBottom: 8
457
496
  },
458
497
  leftContainer: {
459
- justifyContent: 'space-around',
460
- marginHorizontal: 16,
461
- width: '60%'
498
+ marginRight: 8
462
499
  },
463
500
  playPauseButton: {
464
501
  alignItems: 'center',
465
- alignSelf: 'center',
466
502
  borderRadius: 50,
467
503
  elevation: 4,
468
504
  justifyContent: 'center',
469
- padding: 2,
505
+ marginRight: 8,
506
+ padding: 4,
470
507
  shadowOffset: {
471
508
  height: 2,
472
509
  width: 0
@@ -474,13 +511,16 @@ var styles = _reactNative.StyleSheet.create({
474
511
  shadowOpacity: 0.23,
475
512
  shadowRadius: 2.62
476
513
  },
477
- progressControlContainer: {},
514
+ progressControlContainer: {
515
+ flexGrow: 1,
516
+ justifyContent: 'center'
517
+ },
478
518
  progressDurationText: {
479
519
  fontSize: 12,
480
- marginRight: 4
520
+ marginRight: 8
481
521
  },
482
522
  rightContainer: {
483
- marginLeft: 'auto'
523
+ marginLeft: 16
484
524
  },
485
525
  speedChangeButton: {
486
526
  alignItems: 'center',
@@ -488,8 +528,8 @@ var styles = _reactNative.StyleSheet.create({
488
528
  borderRadius: 50,
489
529
  elevation: 4,
490
530
  justifyContent: 'center',
491
- paddingHorizontal: 10,
492
- paddingVertical: 5,
531
+ paddingHorizontal: 8,
532
+ paddingVertical: 4,
493
533
  shadowOffset: {
494
534
  height: 2,
495
535
  width: 0
@@ -498,8 +538,7 @@ var styles = _reactNative.StyleSheet.create({
498
538
  shadowRadius: 2.62
499
539
  },
500
540
  speedChangeButtonText: {
501
- fontSize: 12,
502
- fontWeight: '500'
541
+ fontSize: 12
503
542
  }
504
543
  });
505
544
  AudioAttachment.displayName = 'AudioAttachment{messageInput{audioAttachment}}';