Skip to content

Commit 64170ca

Browse files
committed
fix: audio attachment title overflow issue
1 parent d995ecd commit 64170ca

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

package/src/components/Attachment/AudioAttachment.tsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export type AudioAttachmentProps = {
3535
* UI Component to preview the audio files
3636
*/
3737
export const AudioAttachment = (props: AudioAttachmentProps) => {
38-
const [width, setWidth] = useState(0);
3938
const [currentSpeed, setCurrentSpeed] = useState<number>(1.0);
4039
const soundRef = React.useRef<SoundReturnType | null>(null);
4140
const {
@@ -228,9 +227,6 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
228227
return (
229228
<View
230229
accessibilityLabel='audio-attachment-preview'
231-
onLayout={({ nativeEvent }) => {
232-
setWidth(nativeEvent.layout.width);
233-
}}
234230
style={[
235231
styles.container,
236232
{
@@ -264,11 +260,6 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
264260
styles.filenameText,
265261
{
266262
color: black,
267-
width:
268-
16 - // 16 = horizontal padding
269-
40 - // 40 = file icon size
270-
24 - // 24 = close icon size
271-
24, // 24 = internal padding
272263
},
273264
I18nManager.isRTL ? { writingDirection: 'rtl' } : { writingDirection: 'ltr' },
274265
filenameText,
@@ -316,7 +307,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
316307
onProgressDrag={handleProgressDrag}
317308
progress={item.progress as number}
318309
testID='progress-control'
319-
width={width / 2}
310+
width={150}
320311
/>
321312
)}
322313
</View>
@@ -365,50 +356,48 @@ const styles = StyleSheet.create({
365356
fontSize: 14,
366357
fontWeight: 'bold',
367358
paddingBottom: 12,
368-
paddingLeft: 8,
369359
},
370360
leftContainer: {
371361
justifyContent: 'space-around',
362+
marginHorizontal: 16,
363+
width: '60%',
372364
},
373365
playPauseButton: {
374366
alignItems: 'center',
375367
alignSelf: 'center',
376368
borderRadius: 50,
377-
display: 'flex',
378369
elevation: 4,
379370
justifyContent: 'center',
380-
paddingVertical: 2,
371+
padding: 2,
381372
shadowOffset: {
382373
height: 2,
383374
width: 0,
384375
},
385376
shadowOpacity: 0.23,
386377
shadowRadius: 2.62,
387-
width: 36,
388378
},
389379
progressControlContainer: {},
390380
progressDurationText: {
391381
fontSize: 12,
392-
paddingLeft: 10,
393-
paddingRight: 8,
382+
marginRight: 4,
394383
},
395384
rightContainer: {
396-
marginLeft: 10,
385+
marginLeft: 'auto',
397386
},
398387
speedChangeButton: {
399388
alignItems: 'center',
400389
alignSelf: 'center',
401390
borderRadius: 50,
402391
elevation: 4,
403392
justifyContent: 'center',
393+
paddingHorizontal: 10,
404394
paddingVertical: 5,
405395
shadowOffset: {
406396
height: 2,
407397
width: 0,
408398
},
409399
shadowOpacity: 0.23,
410400
shadowRadius: 2.62,
411-
width: 36,
412401
},
413402
speedChangeButtonText: {
414403
fontSize: 12,
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import { lookup } from 'mime-types';
2+
13
export const getTrimmedAttachmentTitle = (title?: string) => {
24
if (!title) return '';
3-
const lastIndexOfDot = title.lastIndexOf('.');
4-
return title.length < 12 ? title : title.slice(0, 12) + '...' + title.slice(lastIndexOfDot);
5+
6+
const mimeType = lookup(title);
7+
if (mimeType) {
8+
const lastIndexOfDot = title.lastIndexOf('.');
9+
return title.length < 12 ? title : title.slice(0, 12) + '...' + title.slice(lastIndexOfDot);
10+
} else {
11+
return title;
12+
}
513
};

0 commit comments

Comments
 (0)