Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix Space profile photo sizing and viewer drag dismissal

Anand Baburajan0ec85b0e4fed
diff --git a/web/apps/space/src/components/FileViewer.tsx b/web/apps/space/src/components/FileViewer.tsx
index d56d3b7db0..40e72ee0ca 100644
--- a/web/apps/space/src/components/FileViewer.tsx
+++ b/web/apps/space/src/components/FileViewer.tsx
@@ -494,6 +494,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
isDeleteExit ||
isDraftPostExit ||
isCaptionEditing ||
+ isReplyMode ||
isDraftPost ||
isDraftPostPreviewPending;
const viewerViewportSize = React.useCallback(() => {
@@ -1034,10 +1035,10 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
arrowNext: false,
arrowPrev: false,
bgClickAction: false,
- bgOpacity: 1,
+ bgOpacity: 0,
clickToCloseNonZoomable: false,
close: false,
- closeOnVerticalDrag: false,
+ closeOnVerticalDrag: true,
counter: false,
doubleTapAction: "zoom",
errorMsg: "Unable to preview this photo",
@@ -1083,6 +1084,15 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
pswp.on("close", () => {
if (!closedByReact) onCloseRef.current();
});
+ pswp.on("verticalDrag", (event) => {
+ if (isSwipeBlockedRef.current) event.preventDefault();
+ });
+ pswp.on("zoomPanUpdate", () => {
+ root.style.setProperty(
+ "--space-viewer-bg-opacity",
+ String(pswp!.bgOpacity),
+ );
+ });
pswp.on("change", () => {
const nextIndex = pswp?.currIndex;
if (nextIndex != undefined) {
@@ -1175,6 +1185,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
swipeGestureRef.current = null;
pswpRef.current = undefined;
pswp?.destroy();
+ root.style.removeProperty("--space-viewer-bg-opacity");
};
}, [isDraftPostPreviewPending, usePhotoSwipeViewer, viewerViewportSize]);
@@ -1229,7 +1240,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
finishDraftPostExit();
}}
sx={{
- bgcolor: viewerBackground,
+ bgcolor: "rgb(0 0 0 / var(--space-viewer-bg-opacity, 1))",
boxSizing: "border-box",
color: textBase,
display: "flex",
@@ -1246,6 +1257,8 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
transition: `opacity ${draftPostExitDurationMs}ms cubic-bezier(0.22, 1, 0.36, 1)`,
width: "100%",
zIndex: 1300,
+ "& [data-space-viewer-chrome='true'], & [data-space-viewer-bottom='true']":
+ { opacity: "var(--space-viewer-bg-opacity, 1)" },
"@media (prefers-reduced-motion: reduce)": {
transition: "none",
},
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 75c0e749ca..5d36afefe5 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -11,7 +11,6 @@ import { SpaceAvatarImage } from "components/AvatarImage";
import { SpaceFeedPostButton } from "components/FeedPostButton";
import {
SpaceFileViewer,
- SpaceViewerPostBackdrop,
type SpaceViewerPhoto,
type SpaceViewerPostActionMode,
} from "components/FileViewer";
@@ -1786,7 +1785,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
position: "relative",
}}
>
- {selectedViewer && <SpaceViewerPostBackdrop />}
<Box
sx={{
bgcolor: homeBackground,
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index bdf86e0724..1d73db2ee1 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -23,7 +23,6 @@ import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";
import { SpaceFeedPostButton } from "components/FeedPostButton";
import {
SpaceFileViewer,
- SpaceViewerPostBackdrop,
type SpaceViewerPhoto,
type SpaceViewerPostActionMode,
} from "components/FileViewer";
@@ -122,7 +121,6 @@ interface SelectedProfilePost {
interface PostMasonryTile {
aspectRatio: number;
- dimensions: ProfilePhotoDimensions;
index: number;
item: ProfilePostItem;
}
@@ -166,7 +164,6 @@ const buildPostMasonrySections = (
)!;
section.tiles.push({
aspectRatio: photoAspectRatio(dimensions),
- dimensions,
index,
item,
});
@@ -296,12 +293,10 @@ const ProfilePostLoadingIndicator: React.FC = () => (
);
interface ProfilePostTileProps {
- dimensions: ProfilePhotoDimensions;
displayName: string;
flexGrow: number;
imageUrl?: string;
index: number;
- isSingleItemRow: boolean;
isUnavailable: boolean;
item: ProfilePostItem;
loadRootMargin: string;
@@ -312,12 +307,10 @@ interface ProfilePostTileProps {
}
const ProfilePostTile: React.FC<ProfilePostTileProps> = ({
- dimensions,
displayName,
flexGrow,
imageUrl,
index,
- isSingleItemRow,
isUnavailable: isPostUnavailable,
item,
loadRootMargin,
@@ -391,12 +384,12 @@ const ProfilePostTile: React.FC<ProfilePostTileProps> = ({
}}
sx={{
appearance: "none",
- aspectRatio: `${dimensions.width} / ${dimensions.height}`,
bgcolor: photoMasonryPlaceholderBackground,
border: 0,
cursor: imageUrl && !isUnavailable ? "pointer" : "default",
display: "block",
- flex: isSingleItemRow ? "0 0 100%" : `${flexGrow} 1 0`,
+ flex: `${flexGrow} 1 0`,
+ height: "100%",
minWidth: 0,
opacity: 1,
overflow: "hidden",
@@ -563,8 +556,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
}) => {
const [selectedPost, setSelectedPost] =
useState<SelectedProfilePost | null>(null);
- const [isDraftPostExitAnimating, setIsDraftPostExitAnimating] =
- useState(false);
const [isDraftPostExiting, setIsDraftPostExiting] = useState(false);
const [isPostPhotoOpening, setIsPostPhotoOpening] = useState(false);
const [isInviteLinkCopied, setIsInviteLinkCopied] = useState(false);
@@ -740,7 +731,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
};
const closeSelectedPost = () => {
activeLocalPostObjectUrlRef.current = null;
- setIsDraftPostExitAnimating(false);
setIsDraftPostExiting(false);
setSelectedPost(null);
revokeLocalPostObjectUrls();
@@ -1092,8 +1082,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
);
const renderPostTile = (
- { aspectRatio, dimensions, index, item }: PostMasonryTile,
- isSingleItemRow: boolean,
+ { aspectRatio, index, item }: PostMasonryTile,
rowAspectRatio: number,
) => {
const imageUrl = loadedPostImageURLFor(item);
@@ -1102,11 +1091,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
<ProfilePostTile
key={`${item.id}-${index}`}
flexGrow={aspectRatio / rowAspectRatio}
- dimensions={dimensions}
displayName={displayName}
imageUrl={imageUrl}
index={index}
- isSingleItemRow={isSingleItemRow}
isUnavailable={isUnavailable}
item={item}
loadRootMargin={postImageLoadRootMargin}
@@ -1338,9 +1325,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
position: "relative",
}}
>
- {selectedPost && (
- <SpaceViewerPostBackdrop exiting={isDraftPostExitAnimating} />
- )}
<Box
sx={{
bgcolor: "transparent",
@@ -1912,28 +1896,25 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
overflow: "hidden",
}}
>
- {rows.map((row) => {
- const isSingleItemRow =
- row.tiles.length == 1;
- return (
- <Box
- key={row.tiles[0]!.item.id}
- sx={{
- display: "flex",
- gap: photoMasonryGap,
- width: "100%",
- }}
- >
- {row.tiles.map((tile) =>
- renderPostTile(
- tile,
- isSingleItemRow,
- row.aspectRatio,
- ),
- )}
- </Box>
- );
- })}
+ {rows.map((row) => (
+ <Box
+ key={row.tiles[0]!.item.id}
+ sx={{
+ display: "flex",
+ flexShrink: 0,
+ gap: photoMasonryGap,
+ height: row.height,
+ width: "100%",
+ }}
+ >
+ {row.tiles.map((tile) =>
+ renderPostTile(
+ tile,
+ row.aspectRatio,
+ ),
+ )}
+ </Box>
+ ))}
</Box>
</Box>
))}
@@ -2049,9 +2030,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
? onAddFriendForPostAction
: undefined
}
- onDraftPostExitAnimationStart={() => {
- setIsDraftPostExitAnimating(true);
- }}
onDraftPostExitStart={() => setIsDraftPostExiting(true)}
onDraftPostPublished={() => {
void clearSelectedPostHistory("back").then(() =>
diff --git a/web/apps/space/src/utils/profile-photo-layout.ts b/web/apps/space/src/utils/profile-photo-layout.ts
index 1949b444f2..1723b37335 100644
--- a/web/apps/space/src/utils/profile-photo-layout.ts
+++ b/web/apps/space/src/utils/profile-photo-layout.ts
@@ -5,7 +5,7 @@ export const profilePhotoRows = <Tile extends { aspectRatio: number }>(
tiles: Tile[],
width: number,
) => {
- const rows: { aspectRatio: number; tiles: Tile[] }[] = [];
+ const rows: { aspectRatio: number; height: number; tiles: Tile[] }[] = [];
let nextTileIndex = 0;
while (nextTileIndex < tiles.length) {
@@ -33,7 +33,11 @@ export const profilePhotoRows = <Tile extends { aspectRatio: number }>(
rowSize--;
}
- rows.push({ aspectRatio, tiles: rowTiles });
+ rows.push({
+ aspectRatio,
+ height: (width - (rowSize - 1) * profilePhotoGap) / aspectRatio,
+ tiles: rowTiles,
+ });
nextTileIndex += rowSize;
}
diff --git a/web/apps/space/tests/profile-photo-layout.test.ts b/web/apps/space/tests/profile-photo-layout.test.ts
index 56184ed281..5c530959be 100644
--- a/web/apps/space/tests/profile-photo-layout.test.ts
+++ b/web/apps/space/tests/profile-photo-layout.test.ts
@@ -8,6 +8,13 @@ import {
const photos = (ratios: number[]) =>
ratios.map((aspectRatio, id) => ({ id, aspectRatio }));
+test("a portrait and landscape share a row at their allocated widths", () => {
+ const tiles = photos([3 / 4, 3 / 2]);
+ expect(profilePhotoRows(tiles, 363)).toEqual([
+ { aspectRatio: 2.25, height: 160, tiles },
+ ]);
+});
+
test("short landscape rows split without changing photo dimensions", () => {
const tiles = photos([4 / 3, 5 / 4, 7 / 4]);
const rows = profilePhotoRows(tiles, 328);
@@ -51,14 +58,13 @@ test.each([288, 328, 358, 568])(
expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);
for (const row of rows) {
const gaps = (row.tiles.length - 1) * profilePhotoGap;
- const height = (width - gaps) / row.aspectRatio;
expect(
row.tiles.reduce(
- (sum, tile) => sum + tile.aspectRatio * height,
+ (sum, tile) => sum + tile.aspectRatio * row.height,
gaps,
),
).toBeCloseTo(width);
- expect(height).toBeGreaterThanOrEqual(
+ expect(row.height).toBeGreaterThanOrEqual(
Math.min(
profilePhotoMinRowHeight,
width / row.tiles[0]!.aspectRatio,