Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Keep feed card height stable while swiping photos

Anand Baburajanba5fe6dfd43d
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 63ae21a818..efff120330 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -845,7 +845,6 @@ const FeedItem: React.FC<FeedItemProps> = ({
);
const feedPhotos = photos ?? [{ imageUrl, thumbHash }];
const activePhoto = feedPhotos[photoIndex]!;
- const [settledPhotoIndex, setSettledPhotoIndex] = useState(photoIndex);
const carouselRef = React.useRef<HTMLDivElement | null>(null);
const photoAnimationRef = React.useRef<number | null>(null);
const swipeRef = React.useRef<{
@@ -878,7 +877,6 @@ const FeedItem: React.FC<FeedItemProps> = ({
) {
carousel.scrollLeft = left;
carousel.style.scrollSnapType = "";
- setSettledPhotoIndex(nextIndex);
return;
}
const startTime = performance.now();
@@ -891,7 +889,6 @@ const FeedItem: React.FC<FeedItemProps> = ({
} else {
photoAnimationRef.current = null;
carousel.style.scrollSnapType = "";
- setSettledPhotoIndex(nextIndex);
}
};
photoAnimationRef.current = requestAnimationFrame(animate);
@@ -966,7 +963,6 @@ const FeedItem: React.FC<FeedItemProps> = ({
left: photoIndex * carousel.clientWidth,
behavior: "instant",
});
- setSettledPhotoIndex(photoIndex);
}
}, [photoIndex]);
const rootRef = React.useRef<HTMLElement | null>(null);
@@ -1015,12 +1011,16 @@ const FeedItem: React.FC<FeedItemProps> = ({
activePhoto.width ??
dimensionsFromAspectRatio(aspectRatio).width,
};
- const photoFrameAspectRatio = Math.max(
+ const firstPhoto = feedPhotos[0]!;
+ const firstPhotoAspectRatio =
+ firstPhoto.width && firstPhoto.height
+ ? firstPhoto.width / firstPhoto.height
+ : aspectRatio;
+ const frameAspectRatio = Math.max(
minimumPostPhotoFrameAspectRatio,
- photoDimensions.width / photoDimensions.height,
- );
- const [frameAspectRatio, setFrameAspectRatio] = useState(
- photoFrameAspectRatio,
+ feedPhotos.length > 1
+ ? firstPhotoAspectRatio
+ : photoDimensions.width / photoDimensions.height,
);
const isPhotoReady = Boolean(displayImageUrl) && decodedPhoto.ready;
const canOpenPhoto =
@@ -1115,12 +1115,6 @@ const FeedItem: React.FC<FeedItemProps> = ({
);
}, [decodedPhoto.failed, postId]);
- React.useEffect(() => {
- if (photoIndex == settledPhotoIndex) {
- setFrameAspectRatio(photoFrameAspectRatio);
- }
- }, [photoFrameAspectRatio, photoIndex, settledPhotoIndex]);
-
React.useEffect(() => {
if (likePopID == 0) return;
@@ -1254,19 +1248,6 @@ const FeedItem: React.FC<FeedItemProps> = ({
);
if (index != photoIndex) onPhotoIndexChange?.(index);
}}
- onScrollEnd={(event) => {
- if (
- swipeRef.current?.dragging ||
- photoAnimationRef.current != null
- )
- return;
- const carousel = event.currentTarget;
- setSettledPhotoIndex(
- Math.round(
- carousel.scrollLeft / carousel.clientWidth,
- ),
- );
- }}
onKeyDown={(event) => {
if (
event.key != "ArrowLeft" &&