Skip to content

Commit 2f570e1

Browse files
authored
fix: gallery layout issue (#3432)
1 parent 6a2e96d commit 2f570e1

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

package/src/components/Attachment/Gallery.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { getUrlWithoutParams } from '../../utils/utils';
4343
export type GalleryPropsWithContext = Pick<ImageGalleryContextValue, 'imageGalleryStateStore'> &
4444
Pick<
4545
MessageContextValue,
46+
| 'alignment'
4647
| 'images'
4748
| 'videos'
4849
| 'onLongPress'
@@ -69,6 +70,7 @@ export type GalleryPropsWithContext = Pick<ImageGalleryContextValue, 'imageGalle
6970
const GalleryWithContext = (props: GalleryPropsWithContext) => {
7071
const {
7172
additionalPressableProps,
73+
alignment,
7274
imageGalleryStateStore,
7375
ImageLoadingFailedIndicator,
7476
ImageLoadingIndicator,
@@ -141,6 +143,7 @@ const GalleryWithContext = (props: GalleryPropsWithContext) => {
141143
styles.container,
142144
{
143145
flexDirection: invertedDirections ? 'column' : 'row',
146+
alignSelf: alignment === 'right' ? 'flex-end' : 'flex-start',
144147
},
145148
images.length !== 1
146149
? { width: gridWidth, height: gridHeight }
@@ -439,18 +442,25 @@ const GalleryImageThumbnail = ({
439442

440443
const areEqual = (prevProps: GalleryPropsWithContext, nextProps: GalleryPropsWithContext) => {
441444
const {
445+
alignment: prevAlignment,
442446
images: prevImages,
443447
message: prevMessage,
444448
myMessageTheme: prevMyMessageTheme,
445449
videos: prevVideos,
446450
} = prevProps;
447451
const {
452+
alignment: nextAlignment,
448453
images: nextImages,
449454
message: nextMessage,
450455
myMessageTheme: nextMyMessageTheme,
451456
videos: nextVideos,
452457
} = nextProps;
453458

459+
const alignmentEqual = prevAlignment === nextAlignment;
460+
if (!alignmentEqual) {
461+
return false;
462+
}
463+
454464
const messageEqual =
455465
prevMessage?.id === nextMessage?.id &&
456466
`${prevMessage?.updated_at}` === `${nextMessage?.updated_at}`;
@@ -498,6 +508,7 @@ export type GalleryProps = Partial<GalleryPropsWithContext>;
498508
*/
499509
export const Gallery = (props: GalleryProps) => {
500510
const {
511+
alignment: propAlignment,
501512
additionalPressableProps: propAdditionalPressableProps,
502513
ImageLoadingFailedIndicator: PropImageLoadingFailedIndicator,
503514
ImageLoadingIndicator: PropImageLoadingIndicator,
@@ -517,6 +528,7 @@ export const Gallery = (props: GalleryProps) => {
517528

518529
const { imageGalleryStateStore } = useImageGalleryContext();
519530
const {
531+
alignment: contextAlignment,
520532
images: contextImages,
521533
message: contextMessage,
522534
onLongPress: contextOnLongPress,
@@ -539,7 +551,7 @@ export const Gallery = (props: GalleryProps) => {
539551
const images = propImages || contextImages;
540552
const videos = propVideos || contextVideos;
541553
const message = propMessage || contextMessage;
542-
554+
const alignment = propAlignment || contextAlignment;
543555
if (!images.length && !videos.length) {
544556
return null;
545557
}
@@ -568,6 +580,7 @@ export const Gallery = (props: GalleryProps) => {
568580
<MemoizedGallery
569581
{...{
570582
additionalPressableProps,
583+
alignment,
571584
channelId: message?.cid,
572585
imageGalleryStateStore,
573586
ImageLoadingFailedIndicator,
@@ -608,7 +621,6 @@ const useStyles = () => {
608621
},
609622
container: {
610623
flexDirection: 'row',
611-
justifyContent: 'center',
612624
gap: primitives.spacingXxs,
613625
},
614626
imageContainer: {},

package/src/components/Attachment/GalleryImage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type GalleryImageWithContextProps = GalleryImageProps &
99
Pick<ChatContextValue, 'ImageComponent'>;
1010

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

1414
// Caching image components such as FastImage will not work with local images.
1515
// This for the case of local uris, we use the default Image component.
@@ -18,7 +18,7 @@ export const GalleryImageWithContext = (props: GalleryImageWithContextProps) =>
1818
<ImageComponent
1919
{...rest}
2020
accessibilityLabel='Gallery Image'
21-
style={[styles.image, rest.style]}
21+
style={[styles.image, style]}
2222
source={{
2323
uri: makeImageCompatibleUrl(uri),
2424
}}
@@ -30,7 +30,7 @@ export const GalleryImageWithContext = (props: GalleryImageWithContextProps) =>
3030
<Image
3131
{...rest}
3232
accessibilityLabel='Gallery Image'
33-
style={[styles.image, rest.style]}
33+
style={[styles.image, style]}
3434
source={{
3535
uri: makeImageCompatibleUrl(uri),
3636
}}

package/src/components/Attachment/utils/buildGallery/buildGalleryOfSingleImage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export function buildGalleryOfSingleImage({
8585
image,
8686
resizableCDNHosts,
8787
flex: 1,
88+
resizeMode: 'cover',
8889
...container,
8990
});
9091

package/src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
328328
return (
329329
<View
330330
key={`gallery_${messageContentOrderIndex}`}
331-
style={[styles.galleryContainer]}
331+
style={styles.galleryContainer}
332332
>
333333
<Gallery />
334334
</View>

0 commit comments

Comments
 (0)