[Perf] Custom Emoji: Replace SVG placeholder with CSS, do not render highlight catch when not needed
This commit is contained in:
parent
79fca8ea1b
commit
f1f776fff5
@ -11,6 +11,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
width: 90%;
|
||||||
|
height: 90%;
|
||||||
|
background-color: #77777719;
|
||||||
|
border-radius: 0.3125rem !important;
|
||||||
|
}
|
||||||
|
|
||||||
.thumb {
|
.thumb {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { FC, TeactNode } from '../../lib/teact/teact';
|
import type { FC } from '../../lib/teact/teact';
|
||||||
import React, { memo, useRef, useState } from '../../lib/teact/teact';
|
import React, { memo, useRef, useState } from '../../lib/teact/teact';
|
||||||
import { getGlobal } from '../../global';
|
import { getGlobal } from '../../global';
|
||||||
|
|
||||||
@ -18,18 +18,17 @@ import StickerView from './StickerView';
|
|||||||
import styles from './CustomEmoji.module.scss';
|
import styles from './CustomEmoji.module.scss';
|
||||||
|
|
||||||
import blankImg from '../../assets/blank.png';
|
import blankImg from '../../assets/blank.png';
|
||||||
import svgPlaceholder from '../../assets/square.svg';
|
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
ref?: React.RefObject<HTMLDivElement>;
|
ref?: React.RefObject<HTMLDivElement>;
|
||||||
documentId: string;
|
documentId: string;
|
||||||
children?: TeactNode;
|
|
||||||
size?: number;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
loopLimit?: number;
|
|
||||||
style?: string;
|
style?: string;
|
||||||
|
size?: number;
|
||||||
isBig?: boolean;
|
isBig?: boolean;
|
||||||
noPlay?: boolean;
|
noPlay?: boolean;
|
||||||
|
loopLimit?: number;
|
||||||
|
isSelectable?: boolean;
|
||||||
withSharedAnimation?: boolean;
|
withSharedAnimation?: boolean;
|
||||||
sharedCanvasRef?: React.RefObject<HTMLCanvasElement>;
|
sharedCanvasRef?: React.RefObject<HTMLCanvasElement>;
|
||||||
sharedCanvasHqRef?: React.RefObject<HTMLCanvasElement>;
|
sharedCanvasHqRef?: React.RefObject<HTMLCanvasElement>;
|
||||||
@ -48,12 +47,13 @@ const STICKER_SIZE = 20;
|
|||||||
const CustomEmoji: FC<OwnProps> = ({
|
const CustomEmoji: FC<OwnProps> = ({
|
||||||
ref,
|
ref,
|
||||||
documentId,
|
documentId,
|
||||||
|
className,
|
||||||
|
style,
|
||||||
size = STICKER_SIZE,
|
size = STICKER_SIZE,
|
||||||
isBig,
|
isBig,
|
||||||
noPlay,
|
noPlay,
|
||||||
className,
|
|
||||||
loopLimit,
|
loopLimit,
|
||||||
style,
|
isSelectable,
|
||||||
withSharedAnimation,
|
withSharedAnimation,
|
||||||
sharedCanvasRef,
|
sharedCanvasRef,
|
||||||
sharedCanvasHqRef,
|
sharedCanvasHqRef,
|
||||||
@ -123,16 +123,18 @@ const CustomEmoji: FC<OwnProps> = ({
|
|||||||
data-alt={customEmoji?.emoji}
|
data-alt={customEmoji?.emoji}
|
||||||
style={style}
|
style={style}
|
||||||
>
|
>
|
||||||
<img
|
{isSelectable && (
|
||||||
className={styles.highlightCatch}
|
<img
|
||||||
src={blankImg}
|
className={styles.highlightCatch}
|
||||||
alt={customEmoji?.emoji}
|
src={blankImg}
|
||||||
data-entity-type={ApiMessageEntityTypes.CustomEmoji}
|
alt={customEmoji?.emoji}
|
||||||
data-document-id={documentId}
|
data-entity-type={ApiMessageEntityTypes.CustomEmoji}
|
||||||
draggable={false}
|
data-document-id={documentId}
|
||||||
/>
|
draggable={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{!customEmoji ? (
|
{!customEmoji ? (
|
||||||
<img className={styles.thumb} src={svgPlaceholder} alt="Emoji" draggable={false} />
|
<div className={buildClassName(styles.placeholder)} draggable={false} />
|
||||||
) : (
|
) : (
|
||||||
<StickerView
|
<StickerView
|
||||||
containerRef={containerRef}
|
containerRef={containerRef}
|
||||||
|
|||||||
@ -134,7 +134,7 @@ export function renderActionMessageText(
|
|||||||
|
|
||||||
if (unprocessed.includes('%action_topic%')) {
|
if (unprocessed.includes('%action_topic%')) {
|
||||||
const topicEmoji = topic?.iconEmojiId
|
const topicEmoji = topic?.iconEmojiId
|
||||||
? <CustomEmoji documentId={topic.iconEmojiId} />
|
? <CustomEmoji documentId={topic.iconEmojiId} isSelectable />
|
||||||
: '';
|
: '';
|
||||||
const topicString = topic ? `${topic.title}` : 'a topic';
|
const topicString = topic ? `${topic.title}` : 'a topic';
|
||||||
processed = processPlaceholder(
|
processed = processPlaceholder(
|
||||||
@ -153,7 +153,7 @@ export function renderActionMessageText(
|
|||||||
processed = processPlaceholder(
|
processed = processPlaceholder(
|
||||||
unprocessed,
|
unprocessed,
|
||||||
'%action_topic_icon%',
|
'%action_topic_icon%',
|
||||||
hasIcon ? <CustomEmoji documentId={topicIcon!} />
|
hasIcon ? <CustomEmoji documentId={topicIcon!} isSelectable />
|
||||||
: topic ? <TopicDefaultIcon topicId={topic!.id} title={topic!.title} /> : '...',
|
: topic ? <TopicDefaultIcon topicId={topic!.id} title={topic!.title} /> : '...',
|
||||||
);
|
);
|
||||||
unprocessed = processed.pop() as string;
|
unprocessed = processed.pop() as string;
|
||||||
|
|||||||
@ -439,6 +439,7 @@ function processEntity({
|
|||||||
key={cacheBuster ? `${cacheBuster}-${entity.offset}` : undefined}
|
key={cacheBuster ? `${cacheBuster}-${entity.offset}` : undefined}
|
||||||
documentId={entity.documentId}
|
documentId={entity.documentId}
|
||||||
size={emojiSize}
|
size={emojiSize}
|
||||||
|
isSelectable
|
||||||
withSharedAnimation
|
withSharedAnimation
|
||||||
sharedCanvasRef={sharedCanvasRef}
|
sharedCanvasRef={sharedCanvasRef}
|
||||||
sharedCanvasHqRef={sharedCanvasHqRef}
|
sharedCanvasHqRef={sharedCanvasHqRef}
|
||||||
@ -568,6 +569,7 @@ function processEntity({
|
|||||||
key={cacheBuster ? `${cacheBuster}-${entity.offset}` : undefined}
|
key={cacheBuster ? `${cacheBuster}-${entity.offset}` : undefined}
|
||||||
documentId={entity.documentId}
|
documentId={entity.documentId}
|
||||||
size={emojiSize}
|
size={emojiSize}
|
||||||
|
isSelectable
|
||||||
withSharedAnimation
|
withSharedAnimation
|
||||||
sharedCanvasRef={sharedCanvasRef}
|
sharedCanvasRef={sharedCanvasRef}
|
||||||
sharedCanvasHqRef={sharedCanvasHqRef}
|
sharedCanvasHqRef={sharedCanvasHqRef}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user