Album: Fix shift on small screens (#6276)
This commit is contained in:
parent
3e19a911e1
commit
0b6c61f9d0
@ -139,7 +139,7 @@ import { getCustomEmojiSize } from '../composer/helpers/customEmoji';
|
|||||||
import { buildContentClassName } from './helpers/buildContentClassName';
|
import { buildContentClassName } from './helpers/buildContentClassName';
|
||||||
import { calculateAlbumLayout } from './helpers/calculateAlbumLayout';
|
import { calculateAlbumLayout } from './helpers/calculateAlbumLayout';
|
||||||
import getSingularPaidMedia from './helpers/getSingularPaidMedia';
|
import getSingularPaidMedia from './helpers/getSingularPaidMedia';
|
||||||
import { calculateMediaDimensions, getMinMediaWidth, MIN_MEDIA_WIDTH_WITH_TEXT } from './helpers/mediaDimensions';
|
import { calculateMediaDimensions, getMinMediaWidth, getMinMediaWidthWithText } from './helpers/mediaDimensions';
|
||||||
|
|
||||||
import useAppLayout from '../../../hooks/useAppLayout';
|
import useAppLayout from '../../../hooks/useAppLayout';
|
||||||
import useContextMenuHandlers from '../../../hooks/useContextMenuHandlers';
|
import useContextMenuHandlers from '../../../hooks/useContextMenuHandlers';
|
||||||
@ -341,7 +341,6 @@ type QuickReactionPosition =
|
|||||||
| 'in-meta';
|
| 'in-meta';
|
||||||
|
|
||||||
const NBSP = '\u00A0';
|
const NBSP = '\u00A0';
|
||||||
const NO_MEDIA_CORNERS_THRESHOLD = 18;
|
|
||||||
const QUICK_REACTION_SIZE = 1.75 * REM;
|
const QUICK_REACTION_SIZE = 1.75 * REM;
|
||||||
const EXTRA_SPACE_FOR_REACTIONS = 2.25 * REM;
|
const EXTRA_SPACE_FOR_REACTIONS = 2.25 * REM;
|
||||||
const MAX_REASON_LENGTH = 200;
|
const MAX_REASON_LENGTH = 200;
|
||||||
@ -930,7 +929,6 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
const sizeCalculations = useMemo(() => {
|
const sizeCalculations = useMemo(() => {
|
||||||
let calculatedWidth;
|
let calculatedWidth;
|
||||||
let contentWidth: number | undefined;
|
let contentWidth: number | undefined;
|
||||||
let noMediaCorners = false;
|
|
||||||
let style = '';
|
let style = '';
|
||||||
let reactionsMaxWidth;
|
let reactionsMaxWidth;
|
||||||
|
|
||||||
@ -962,21 +960,14 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (width) {
|
if (width) {
|
||||||
if (width < MIN_MEDIA_WIDTH_WITH_TEXT) {
|
if (width < getMinMediaWidthWithText(isMobile)) {
|
||||||
contentWidth = width;
|
contentWidth = width;
|
||||||
}
|
}
|
||||||
calculatedWidth = Math.max(getMinMediaWidth(text?.text, isMediaWithCommentButton), width);
|
calculatedWidth = Math.max(getMinMediaWidth(text?.text, isMobile, isMediaWithCommentButton), width);
|
||||||
if (!asForwarded && invoice?.extendedMedia && calculatedWidth - width > NO_MEDIA_CORNERS_THRESHOLD) {
|
|
||||||
noMediaCorners = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (albumLayout) {
|
} else if (albumLayout) {
|
||||||
calculatedWidth = Math.max(
|
const minWidth = getMinMediaWidth(text?.text, isMobile, isMediaWithCommentButton);
|
||||||
getMinMediaWidth(text?.text, isMediaWithCommentButton), albumLayout.containerStyle.width,
|
calculatedWidth = Math.max(minWidth, albumLayout.containerStyle.width);
|
||||||
);
|
|
||||||
if (calculatedWidth - albumLayout.containerStyle.width > NO_MEDIA_CORNERS_THRESHOLD) {
|
|
||||||
noMediaCorners = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calculatedWidth) {
|
if (calculatedWidth) {
|
||||||
@ -989,7 +980,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contentWidth, noMediaCorners, style, reactionsMaxWidth,
|
contentWidth, style, reactionsMaxWidth,
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
albumLayout, asForwarded, extraPadding, hasSubheader, invoice?.extendedMedia, isAlbum, isMediaWithCommentButton,
|
albumLayout, asForwarded, extraPadding, hasSubheader, invoice?.extendedMedia, isAlbum, isMediaWithCommentButton,
|
||||||
@ -997,7 +988,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
contentWidth, noMediaCorners, style, reactionsMaxWidth,
|
contentWidth, style, reactionsMaxWidth,
|
||||||
} = sizeCalculations;
|
} = sizeCalculations;
|
||||||
|
|
||||||
function renderMessageText(isForAnimation?: boolean) {
|
function renderMessageText(isForAnimation?: boolean) {
|
||||||
@ -1098,7 +1089,6 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
asForwarded && 'forwarded-message',
|
asForwarded && 'forwarded-message',
|
||||||
hasForwardedCustomShape && 'forwarded-custom-shape',
|
hasForwardedCustomShape && 'forwarded-custom-shape',
|
||||||
hasSubheader && 'with-subheader',
|
hasSubheader && 'with-subheader',
|
||||||
noMediaCorners && 'no-media-corners',
|
|
||||||
);
|
);
|
||||||
const hasCustomAppendix = isLastInGroup
|
const hasCustomAppendix = isLastInGroup
|
||||||
&& (!hasText || (isInvertedMedia && !hasFactCheck && reactionsPosition !== 'inside')) && !withCommentButton;
|
&& (!hasText || (isInvertedMedia && !hasFactCheck && reactionsPosition !== 'inside')) && !withCommentButton;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import { IS_ANDROID } from '../../../util/browser/windowEnvironment';
|
|||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
import { renderTextWithEntities } from '../../common/helpers/renderTextWithEntities';
|
import { renderTextWithEntities } from '../../common/helpers/renderTextWithEntities';
|
||||||
import { preventMessageInputBlur } from '../helpers/preventMessageInputBlur';
|
import { preventMessageInputBlur } from '../helpers/preventMessageInputBlur';
|
||||||
import { calculateMediaDimensions, getMinMediaWidth, MIN_MEDIA_WIDTH_WITH_TEXT } from './helpers/mediaDimensions';
|
import { calculateMediaDimensions, getMinMediaWidth, getMinMediaWidthWithText } from './helpers/mediaDimensions';
|
||||||
|
|
||||||
import useAppLayout from '../../../hooks/useAppLayout';
|
import useAppLayout from '../../../hooks/useAppLayout';
|
||||||
import useContextMenuHandlers from '../../../hooks/useContextMenuHandlers';
|
import useContextMenuHandlers from '../../../hooks/useContextMenuHandlers';
|
||||||
@ -116,9 +116,10 @@ const SponsoredMessage: FC<OwnProps & StateProps> = ({
|
|||||||
hideSponsored();
|
hideSponsored();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const content = message && getMessageContent(message);
|
||||||
const {
|
const {
|
||||||
photo, video,
|
photo, video, text,
|
||||||
} = message ? getMessageContent(message) : { photo: undefined, video: undefined };
|
} = content || {};
|
||||||
|
|
||||||
const isGif = video?.isGif;
|
const isGif = video?.isGif;
|
||||||
const hasMedia = Boolean(photo || video);
|
const hasMedia = Boolean(photo || video);
|
||||||
@ -173,10 +174,10 @@ const SponsoredMessage: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (width) {
|
if (width) {
|
||||||
if (width < MIN_MEDIA_WIDTH_WITH_TEXT) {
|
if (width < getMinMediaWidthWithText(isMobile)) {
|
||||||
contentWidth = width;
|
contentWidth = width;
|
||||||
}
|
}
|
||||||
calculatedWidth = Math.max(getMinMediaWidth(), width);
|
calculatedWidth = Math.max(getMinMediaWidth(text?.text, isMobile), width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +188,7 @@ const SponsoredMessage: FC<OwnProps & StateProps> = ({
|
|||||||
return {
|
return {
|
||||||
contentWidth, noMediaCorners, style,
|
contentWidth, noMediaCorners, style,
|
||||||
};
|
};
|
||||||
}, [photo, video, isMobile]);
|
}, [photo, video, isMobile, text?.text]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
contentWidth, style,
|
contentWidth, style,
|
||||||
|
|||||||
@ -595,15 +595,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.no-media-corners {
|
|
||||||
--border-top-left-radius: 0;
|
|
||||||
--border-top-right-radius: 0;
|
|
||||||
|
|
||||||
.Album {
|
|
||||||
margin-inline: auto !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.custom-shape.is-via-bot {
|
&.custom-shape.is-via-bot {
|
||||||
font-size: inherit !important;
|
font-size: inherit !important;
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ export type IAlbumLayout = {
|
|||||||
containerStyle: ApiDimensions;
|
containerStyle: ApiDimensions;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getRatios(messages: ApiMessage[], isSingleMessage?: boolean, isMobile?: boolean) {
|
function getRatios(messages: ApiMessage[], isSingleMessage: boolean, isMobile: boolean) {
|
||||||
const isOutgoing = messages[0].isOutgoing;
|
const isOutgoing = messages[0].isOutgoing;
|
||||||
const allMedia = (isSingleMessage
|
const allMedia = (isSingleMessage
|
||||||
? messages[0].content.paidMedia!.extendedMedia.map((media) => (
|
? messages[0].content.paidMedia!.extendedMedia.map((media) => (
|
||||||
@ -108,10 +108,10 @@ export function calculateAlbumLayout(
|
|||||||
isOwn: boolean,
|
isOwn: boolean,
|
||||||
noAvatars: boolean,
|
noAvatars: boolean,
|
||||||
album: IAlbum,
|
album: IAlbum,
|
||||||
isMobile?: boolean,
|
isMobile: boolean,
|
||||||
): IAlbumLayout {
|
): IAlbumLayout {
|
||||||
const spacing = 2;
|
const spacing = 2;
|
||||||
const ratios = getRatios(album.messages, album.isPaidMedia, isMobile);
|
const ratios = getRatios(album.messages, Boolean(album.isPaidMedia), isMobile);
|
||||||
const proportions = getProportions(ratios);
|
const proportions = getProportions(ratios);
|
||||||
const averageRatio = getAverageRatio(ratios);
|
const averageRatio = getAverageRatio(ratios);
|
||||||
const albumCount = ratios.length;
|
const albumCount = ratios.length;
|
||||||
|
|||||||
@ -9,13 +9,16 @@ import {
|
|||||||
|
|
||||||
const SMALL_IMAGE_THRESHOLD = 12;
|
const SMALL_IMAGE_THRESHOLD = 12;
|
||||||
const MIN_MESSAGE_LENGTH_FOR_BLUR = 40;
|
const MIN_MESSAGE_LENGTH_FOR_BLUR = 40;
|
||||||
export const MIN_MEDIA_WIDTH_WITH_TEXT = 20 * REM;
|
|
||||||
const MIN_MEDIA_WIDTH = SMALL_IMAGE_THRESHOLD * REM;
|
const MIN_MEDIA_WIDTH = SMALL_IMAGE_THRESHOLD * REM;
|
||||||
export const MIN_MEDIA_HEIGHT = 5 * REM;
|
export const MIN_MEDIA_HEIGHT = 5 * REM;
|
||||||
|
|
||||||
export function getMinMediaWidth(text?: string, hasCommentButton?: boolean) {
|
export function getMinMediaWidthWithText(isMobile: boolean) {
|
||||||
return (text?.length ?? 0) > MIN_MESSAGE_LENGTH_FOR_BLUR || hasCommentButton
|
return (isMobile ? 14 : 20) * REM;
|
||||||
? MIN_MEDIA_WIDTH_WITH_TEXT
|
}
|
||||||
|
|
||||||
|
export function getMinMediaWidth(text: string = '', isMobile: boolean, hasCommentButton?: boolean) {
|
||||||
|
return text.length > MIN_MESSAGE_LENGTH_FOR_BLUR || hasCommentButton
|
||||||
|
? getMinMediaWidthWithText(isMobile)
|
||||||
: MIN_MEDIA_WIDTH;
|
: MIN_MEDIA_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +37,7 @@ export function calculateMediaDimensions({
|
|||||||
isInWebPage?: boolean;
|
isInWebPage?: boolean;
|
||||||
asForwarded?: boolean;
|
asForwarded?: boolean;
|
||||||
noAvatars?: boolean;
|
noAvatars?: boolean;
|
||||||
isMobile?: boolean;
|
isMobile: boolean;
|
||||||
}) {
|
}) {
|
||||||
const isPhoto = media.mediaType === 'photo';
|
const isPhoto = media.mediaType === 'photo';
|
||||||
const isVideo = media.mediaType === 'video';
|
const isVideo = media.mediaType === 'video';
|
||||||
@ -45,7 +48,7 @@ export function calculateMediaDimensions({
|
|||||||
: isVideo ? calculateVideoDimensions(media, isOwn, asForwarded, isWebPageVideo, noAvatars, isMobile)
|
: isVideo ? calculateVideoDimensions(media, isOwn, asForwarded, isWebPageVideo, noAvatars, isMobile)
|
||||||
: calculateExtendedPreviewDimensions(media, isOwn, asForwarded, isInWebPage, noAvatars, isMobile);
|
: calculateExtendedPreviewDimensions(media, isOwn, asForwarded, isInWebPage, noAvatars, isMobile);
|
||||||
|
|
||||||
const minMediaWidth = getMinMediaWidth(messageText);
|
const minMediaWidth = getMinMediaWidth(messageText, isMobile);
|
||||||
|
|
||||||
let stretchFactor = 1;
|
let stretchFactor = 1;
|
||||||
if (width < minMediaWidth && minMediaWidth - width < SMALL_IMAGE_THRESHOLD) {
|
if (width < minMediaWidth && minMediaWidth - width < SMALL_IMAGE_THRESHOLD) {
|
||||||
|
|||||||
@ -16,10 +16,10 @@ type MediaQueryCacheKey = 'mobile' | 'tablet' | 'landscape' | 'touch';
|
|||||||
const mediaQueryCache = new Map<MediaQueryCacheKey, MediaQueryList>();
|
const mediaQueryCache = new Map<MediaQueryCacheKey, MediaQueryList>();
|
||||||
const callbacks = createCallbackManager();
|
const callbacks = createCallbackManager();
|
||||||
|
|
||||||
let isMobile: boolean | undefined;
|
let isMobile: boolean;
|
||||||
let isTablet: boolean | undefined;
|
let isTablet: boolean;
|
||||||
let isLandscape: boolean | undefined;
|
let isLandscape: boolean;
|
||||||
let isTouchScreen: boolean | undefined;
|
let isTouchScreen: boolean;
|
||||||
|
|
||||||
export function getIsMobile() {
|
export function getIsMobile() {
|
||||||
return isMobile;
|
return isMobile;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user