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

Commit b7e80a7

Browse files
authored
Merge pull request #557 from lifeomic/adjust-message-bubble-styles
fix: Modify image message bubble styles
2 parents a5cc162 + eed6ea7 commit b7e80a7

1 file changed

Lines changed: 70 additions & 8 deletions

File tree

src/screens/DirectMessagesScreen.tsx

Lines changed: 70 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,46 @@ 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+
451+
if (isFinite(aspectRatio)) {
452+
setDimensions({
453+
[largerDimension]: 'auto',
454+
aspectRatio,
455+
});
456+
}
457+
});
458+
}
459+
}, [props.currentMessage?.image]);
460+
421461
return (
422462
<View style={{ position: 'relative' }}>
423463
<ActivityIndicator
424464
style={styles.messageImageLoadingIcon}
425465
color={styles.messageImageLoadingIcon?.color}
426466
/>
427-
<MessageImage {...props} />
467+
<MessageImage
468+
{...props}
469+
lightboxProps={{
470+
underlayColor: styles.messageImageLightbox?.backgroundColor,
471+
style: styles.messageImageLightbox,
472+
}}
473+
imageStyle={[
474+
dimensions,
475+
{
476+
maxWidth: Dimensions.get('screen').width * 0.65,
477+
},
478+
styles.messageImage,
479+
]}
480+
/>
428481
</View>
429482
);
430483
},
@@ -599,6 +652,15 @@ const defaultStyles = createStyles('DirectMessagesScreen', (theme) => ({
599652
...StyleSheet.absoluteFillObject,
600653
color: theme.colors.onPrimaryContainer,
601654
},
655+
messageImageBubble: {
656+
backgroundColor: 'transparent',
657+
},
658+
messageImage: {
659+
margin: 0,
660+
},
661+
messageImageLightbox: {
662+
backgroundColor: 'transparent',
663+
},
602664
}));
603665

604666
declare module '@styles' {

0 commit comments

Comments
 (0)