Skip to content

Commit

Permalink
fix: Modify image message bubble styles
Browse files Browse the repository at this point in the history
  • Loading branch information
sternetj committed May 17, 2024
1 parent a5cc162 commit c06766c
Showing 1 changed file with 67 additions and 8 deletions.
75 changes: 67 additions & 8 deletions src/screens/DirectMessagesScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
import React, {
useCallback,
useEffect,
useLayoutEffect,
useRef,
useState,
} from 'react';
import {
Bubble,
Composer,
Expand All @@ -11,7 +17,13 @@ import {
MessageTextProps,
Time,
} from 'react-native-gifted-chat';
import { StyleSheet, ActivityIndicator, ScrollView } from 'react-native';
import {
StyleSheet,
ActivityIndicator,
ScrollView,
Image,
Dimensions,
} from 'react-native';
import {
useInfinitePrivatePosts,
useCreatePrivatePostMutation,
Expand Down Expand Up @@ -236,10 +248,17 @@ export const DirectMessagesScreen = ({
return (
<Bubble
{...props}
wrapperStyle={{
left: styles.leftMessageView,
right: styles.rightMessageView,
}}
wrapperStyle={
props.currentMessage?.text
? {
left: styles.leftMessageView,
right: styles.rightMessageView,
}
: {
right: styles.messageImageBubble,
left: styles.messageImageBubble,
}
}
textStyle={{
left: styles.leftText,
right: styles.rightText,
Expand All @@ -248,7 +267,8 @@ export const DirectMessagesScreen = ({
usernameStyle={styles.signatureText}
renderTime={(timeProps) =>
timeProps.currentMessage?.createdAt !==
(timeProps as any).nextMessage?.createdAt && (
(timeProps as any).nextMessage?.createdAt &&
props.currentMessage?.text && (
<Time
{...timeProps}
timeTextStyle={{
Expand Down Expand Up @@ -418,13 +438,43 @@ const renderCustomImage = memoize(
const CustomMessageImage = React.memo(
(props: MessageImageProps<IMessage>) => {
const { styles } = useStyles(defaultStyles);
const [dimensions, setDimensions] = useState({});

useEffect(() => {
const image = props.currentMessage?.image;

if (image) {
Image.getSize(image, (width, height) => {
const aspectRatio = width / height;
const largerDimension = width > height ? 'width' : 'height';
setDimensions({
[largerDimension]: 'auto',
aspectRatio,
});
});
}
}, [props.currentMessage?.image]);

return (
<View style={{ position: 'relative' }}>
<ActivityIndicator
style={styles.messageImageLoadingIcon}
color={styles.messageImageLoadingIcon?.color}
/>
<MessageImage {...props} />
<MessageImage
{...props}
lightboxProps={{
underlayColor: styles.messageImageLightbox?.backgroundColor,
style: styles.messageImageLightbox,
}}
imageStyle={[
dimensions,
{
maxWidth: Dimensions.get('screen').width * 0.65,
},
styles.messageImage,
]}
/>
</View>
);
},
Expand Down Expand Up @@ -599,6 +649,15 @@ const defaultStyles = createStyles('DirectMessagesScreen', (theme) => ({
...StyleSheet.absoluteFillObject,
color: theme.colors.onPrimaryContainer,
},
messageImageBubble: {
backgroundColor: 'transparent',
},
messageImage: {
margin: 0,
},
messageImageLightbox: {
backgroundColor: 'transparent',
},
}));

declare module '@styles' {
Expand Down

0 comments on commit c06766c

Please sign in to comment.