Skip to content

Commit

Permalink
Fix NSFW messaging visible when image opened with scaling animation (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored May 6, 2024
1 parent 39f6c88 commit 9b388b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/features/media/gallery/GalleryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import type ZoomLevel from "photoswipe/dist/types/slide/zoom-level";
import PhotoSwipeLightbox from "photoswipe/lightbox";

import "photoswipe/style.css";
import { findBlurOverlayContainer } from "../../post/inFeed/large/media/BlurOverlayMessage";
import { compact } from "lodash";

interface IGalleryContext {
// used for determining whether page needs to be scrolled up first
Expand Down Expand Up @@ -173,13 +175,17 @@ export default function GalleryProvider({ children }: GalleryProviderProps) {
instance.on("openingAnimationStart", () => {
if (animationType !== "zoom") return;

thumbEl.style.setProperty("visibility", "hidden");
compact([thumbEl, findBlurOverlayContainer(thumbEl)]).forEach((el) =>
el.style.setProperty("visibility", "hidden"),
);
});

const cleanupHideThumb = () => {
if (animationType !== "zoom") return;

thumbEl.style.removeProperty("visibility");
compact([thumbEl, findBlurOverlayContainer(thumbEl)]).forEach((el) =>
el.style.removeProperty("visibility"),
);
};

instance.on("closingAnimationEnd", cleanupHideThumb);
Expand Down
6 changes: 5 additions & 1 deletion src/features/post/inFeed/large/LargePostContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { InFeedContext } from "../../../feed/Feed";
import useIsPostUrlMedia from "../../useIsPostUrlMedia";
import PostLink from "../../link/PostLink";

// This is needed to hide NSFW messaging, etc when image is open
export const LARGE_POST_MEDIA_CONTAINER_CLASSNAME =
"large-post-media-container";

const PostBody = styled.div`
font-size: 0.8em;
line-height: 1.25;
Expand Down Expand Up @@ -64,7 +68,7 @@ export default function LargePostContents({ post }: LargePostContentsProps) {

if (urlIsMedia || markdownLoneImage) {
return (
<ImageContainer>
<ImageContainer className={LARGE_POST_MEDIA_CONTAINER_CLASSNAME}>
<LargeFeedPostMedia
blur={inFeed ? isNsfwBlurred(post, blurNsfw) : false}
post={post}
Expand Down
15 changes: 14 additions & 1 deletion src/features/post/inFeed/large/media/BlurOverlayMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IonIcon } from "@ionic/react";
import { styled } from "@linaria/react";
import { alertCircle } from "ionicons/icons";
import { LARGE_POST_MEDIA_CONTAINER_CLASSNAME } from "../LargePostContents";

const MessageContainer = styled.div`
// Safari bug where absolutely positioned content isn't viewable over
Expand Down Expand Up @@ -55,12 +56,24 @@ const Description = styled.div`
${showIfTaller}
`;

const BLUR_OVERLAY_CONTAINER_CLASSNAME = "blur-overlay-container";

export default function BlurOverlayMessage() {
return (
<MessageContainer>
<MessageContainer className={BLUR_OVERLAY_CONTAINER_CLASSNAME}>
<WarningIcon icon={alertCircle} />
<Title>NSFW</Title>
<Description>Sensitive content — tap to view</Description>
</MessageContainer>
);
}

export function findBlurOverlayContainer(
imgEl: HTMLElement,
): HTMLElement | undefined {
const el = imgEl
.closest(`.${LARGE_POST_MEDIA_CONTAINER_CLASSNAME}`)
?.querySelector(`.${BLUR_OVERLAY_CONTAINER_CLASSNAME}`);

if (el instanceof HTMLElement) return el;
}

0 comments on commit 9b388b0

Please sign in to comment.