Skip to content

Use a blurhash for blurred story backgrounds #7133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion stylesheets/components/StoryViewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

&__content {
align-items: center;
backdrop-filter: blur(90px);
background: variables.$color-black-alpha-20;
display: flex;
flex-direction: column;
Expand Down
26 changes: 19 additions & 7 deletions ts/components/StoryViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import FocusTrap from 'focus-trap-react';
import type { UIEvent } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import { BlurhashCanvas } from 'react-blurhash';
import type { DraftBodyRanges } from '../types/BodyRange';
import type { LocalizerType } from '../types/Util';
import { ThemeType, type LocalizerType } from '../types/Util';
import type { ContextMenuOptionType } from './ContextMenu';
import type {
ConversationType,
Expand Down Expand Up @@ -41,9 +42,9 @@ import { StoryViewsNRepliesModal } from './StoryViewsNRepliesModal';
import { Theme } from '../util/theme';
import { ToastType } from '../types/Toast';
import { getAvatarColor } from '../types/Colors';
import { getStoryBackground } from '../util/getStoryBackground';
import { COLOR_BLACK_ALPHA_90 } from '../util/getStoryBackground';
import { getStoryDuration } from '../util/getStoryDuration';
import { isVideoAttachment } from '../types/Attachment';
import { defaultBlurHash, isVideoAttachment } from '../types/Attachment';
import { graphemeAndLinkAwareSlice } from '../util/graphemeAndLinkAwareSlice';
import { useEscapeHandling } from '../hooks/useEscapeHandling';
import { useRetryStorySend } from '../hooks/useRetryStorySend';
Expand Down Expand Up @@ -602,10 +603,21 @@ export function StoryViewer({
}}
>
{alertElement}
<div
className="StoryViewer__overlay"
style={{ background: getStoryBackground(attachment) }}
/>

{attachment ? (
<BlurhashCanvas
className="StoryViewer__overlay"
hash={attachment.blurHash || defaultBlurHash(ThemeType.dark)}
width={attachment.width}
height={attachment.height}
/>
) : (
<div
className="StoryViewer__overlay"
style={{ background: COLOR_BLACK_ALPHA_90 }}
/>
)}

<div className="StoryViewer__content">
{canNavigateLeft && (
<button
Expand Down
2 changes: 1 addition & 1 deletion ts/util/getStoryBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { AttachmentType, TextAttachmentType } from '../types/Attachment';

const COLOR_BLACK_ALPHA_90 = 'rgba(0, 0, 0, 0.9)';
export const COLOR_BLACK_ALPHA_90 = 'rgba(0, 0, 0, 0.9)';
export const COLOR_BLACK_INT = 4278190080;
export const COLOR_WHITE_INT = 4294704123;

Expand Down