Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions package/src/components/Attachment/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { getUrlWithoutParams } from '../../utils/utils';
export type GalleryPropsWithContext = Pick<ImageGalleryContextValue, 'imageGalleryStateStore'> &
Pick<
MessageContextValue,
| 'alignment'
| 'images'
| 'videos'
| 'onLongPress'
Expand All @@ -69,6 +70,7 @@ export type GalleryPropsWithContext = Pick<ImageGalleryContextValue, 'imageGalle
const GalleryWithContext = (props: GalleryPropsWithContext) => {
const {
additionalPressableProps,
alignment,
imageGalleryStateStore,
ImageLoadingFailedIndicator,
ImageLoadingIndicator,
Expand Down Expand Up @@ -141,6 +143,7 @@ const GalleryWithContext = (props: GalleryPropsWithContext) => {
styles.container,
{
flexDirection: invertedDirections ? 'column' : 'row',
alignSelf: alignment === 'right' ? 'flex-end' : 'flex-start',
},
images.length !== 1
? { width: gridWidth, height: gridHeight }
Expand Down Expand Up @@ -439,18 +442,25 @@ const GalleryImageThumbnail = ({

const areEqual = (prevProps: GalleryPropsWithContext, nextProps: GalleryPropsWithContext) => {
const {
alignment: prevAlignment,
images: prevImages,
message: prevMessage,
myMessageTheme: prevMyMessageTheme,
videos: prevVideos,
} = prevProps;
const {
alignment: nextAlignment,
images: nextImages,
message: nextMessage,
myMessageTheme: nextMyMessageTheme,
videos: nextVideos,
} = nextProps;

const alignmentEqual = prevAlignment === nextAlignment;
if (!alignmentEqual) {
return false;
}

const messageEqual =
prevMessage?.id === nextMessage?.id &&
`${prevMessage?.updated_at}` === `${nextMessage?.updated_at}`;
Expand Down Expand Up @@ -498,6 +508,7 @@ export type GalleryProps = Partial<GalleryPropsWithContext>;
*/
export const Gallery = (props: GalleryProps) => {
const {
alignment: propAlignment,
additionalPressableProps: propAdditionalPressableProps,
ImageLoadingFailedIndicator: PropImageLoadingFailedIndicator,
ImageLoadingIndicator: PropImageLoadingIndicator,
Expand All @@ -517,6 +528,7 @@ export const Gallery = (props: GalleryProps) => {

const { imageGalleryStateStore } = useImageGalleryContext();
const {
alignment: contextAlignment,
images: contextImages,
message: contextMessage,
onLongPress: contextOnLongPress,
Expand All @@ -539,7 +551,7 @@ export const Gallery = (props: GalleryProps) => {
const images = propImages || contextImages;
const videos = propVideos || contextVideos;
const message = propMessage || contextMessage;

const alignment = propAlignment || contextAlignment;
if (!images.length && !videos.length) {
return null;
}
Expand Down Expand Up @@ -568,6 +580,7 @@ export const Gallery = (props: GalleryProps) => {
<MemoizedGallery
{...{
additionalPressableProps,
alignment,
channelId: message?.cid,
imageGalleryStateStore,
ImageLoadingFailedIndicator,
Expand Down Expand Up @@ -608,7 +621,6 @@ const useStyles = () => {
},
container: {
flexDirection: 'row',
justifyContent: 'center',
gap: primitives.spacingXxs,
},
imageContainer: {},
Expand Down
6 changes: 3 additions & 3 deletions package/src/components/Attachment/GalleryImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type GalleryImageWithContextProps = GalleryImageProps &
Pick<ChatContextValue, 'ImageComponent'>;

export const GalleryImageWithContext = (props: GalleryImageWithContextProps) => {
const { ImageComponent = Image, uri, ...rest } = props;
const { ImageComponent = Image, uri, style, ...rest } = props;

// Caching image components such as FastImage will not work with local images.
// This for the case of local uris, we use the default Image component.
Expand All @@ -18,7 +18,7 @@ export const GalleryImageWithContext = (props: GalleryImageWithContextProps) =>
<ImageComponent
{...rest}
accessibilityLabel='Gallery Image'
style={[styles.image, rest.style]}
style={[styles.image, style]}
source={{
uri: makeImageCompatibleUrl(uri),
}}
Expand All @@ -30,7 +30,7 @@ export const GalleryImageWithContext = (props: GalleryImageWithContextProps) =>
<Image
{...rest}
accessibilityLabel='Gallery Image'
style={[styles.image, rest.style]}
style={[styles.image, style]}
source={{
uri: makeImageCompatibleUrl(uri),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function buildGalleryOfSingleImage({
image,
resizableCDNHosts,
flex: 1,
resizeMode: 'cover',
...container,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
return (
<View
key={`gallery_${messageContentOrderIndex}`}
style={[styles.galleryContainer]}
style={styles.galleryContainer}
>
<Gallery />
</View>
Expand Down