Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit c06766c

Browse files
committed
fix: Modify image message bubble styles
1 parent a5cc162 commit c06766c

1 file changed

Lines changed: 67 additions & 8 deletions

File tree

src/screens/DirectMessagesScreen.tsx

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
1+
import React, {
2+
useCallback,
3+
useEffect,
4+
useLayoutEffect,
5+
useRef,
6+
useState,
7+
} from 'react';
28
import {
39
Bubble,
410
Composer,
@@ -11,7 +17,13 @@ import {
1117
MessageTextProps,
1218
Time,
1319
} from 'react-native-gifted-chat';
14-
import { StyleSheet, ActivityIndicator, ScrollView } from 'react-native';
20+
import {
21+
StyleSheet,
22+
ActivityIndicator,
23+
ScrollView,
24+
Image,
25+
Dimensions,
26+
} from 'react-native';
1527
import {
1628
useInfinitePrivatePosts,
1729
useCreatePrivatePostMutation,
@@ -236,10 +248,17 @@ export const DirectMessagesScreen = ({
236248
return (
237249
<Bubble
238250
{...props}
239-
wrapperStyle={{
240-
left: styles.leftMessageView,
241-
right: styles.rightMessageView,
242-
}}
251+
wrapperStyle={
252+
props.currentMessage?.text
253+
? {
254+
left: styles.leftMessageView,
255+
right: styles.rightMessageView,
256+
}
257+
: {
258+
right: styles.messageImageBubble,
259+
left: styles.messageImageBubble,
260+
}
261+
}
243262
textStyle={{
244263
left: styles.leftText,
245264
right: styles.rightText,
@@ -248,7 +267,8 @@ export const DirectMessagesScreen = ({
248267
usernameStyle={styles.signatureText}
249268
renderTime={(timeProps) =>
250269
timeProps.currentMessage?.createdAt !==
251-
(timeProps as any).nextMessage?.createdAt && (
270+
(timeProps as any).nextMessage?.createdAt &&
271+
props.currentMessage?.text && (
252272
<Time
253273
{...timeProps}
254274
timeTextStyle={{
@@ -418,13 +438,43 @@ const renderCustomImage = memoize(
418438
const CustomMessageImage = React.memo(
419439
(props: MessageImageProps<IMessage>) => {
420440
const { styles } = useStyles(defaultStyles);
441+
const [dimensions, setDimensions] = useState({});
442+
443+
useEffect(() => {
444+
const image = props.currentMessage?.image;
445+
446+
if (image) {
447+
Image.getSize(image, (width, height) => {
448+
const aspectRatio = width / height;
449+
const largerDimension = width > height ? 'width' : 'height';
450+
setDimensions({
451+
[largerDimension]: 'auto',
452+
aspectRatio,
453+
});
454+
});
455+
}
456+
}, [props.currentMessage?.image]);
457+
421458
return (
422459
<View style={{ position: 'relative' }}>
423460
<ActivityIndicator
424461
style={styles.messageImageLoadingIcon}
425462
color={styles.messageImageLoadingIcon?.color}
426463
/>
427-
<MessageImage {...props} />
464+
<MessageImage
465+
{...props}
466+
lightboxProps={{
467+
underlayColor: styles.messageImageLightbox?.backgroundColor,
468+
style: styles.messageImageLightbox,
469+
}}
470+
imageStyle={[
471+
dimensions,
472+
{
473+
maxWidth: Dimensions.get('screen').width * 0.65,
474+
},
475+
styles.messageImage,
476+
]}
477+
/>
428478
</View>
429479
);
430480
},
@@ -599,6 +649,15 @@ const defaultStyles = createStyles('DirectMessagesScreen', (theme) => ({
599649
...StyleSheet.absoluteFillObject,
600650
color: theme.colors.onPrimaryContainer,
601651
},
652+
messageImageBubble: {
653+
backgroundColor: 'transparent',
654+
},
655+
messageImage: {
656+
margin: 0,
657+
},
658+
messageImageLightbox: {
659+
backgroundColor: 'transparent',
660+
},
602661
}));
603662

604663
declare module '@styles' {

0 commit comments

Comments
 (0)