Fix adding sticker in media editor

This commit is contained in:
Fedor Indutny 2024-09-30 16:59:55 -07:00 committed by GitHub
parent b68e731950
commit 697df7e946
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 10 deletions

View file

@ -56,6 +56,7 @@ import { Theme } from '../util/theme';
import { ThemeType } from '../types/Util';
import { arrow } from '../util/keyboard';
import { canvasToBytes } from '../util/canvasToBytes';
import { loadImage } from '../util/loadImage';
import { getConversationSelector } from '../state/selectors/conversations';
import { hydrateRanges } from '../types/BodyRange';
import { useConfirmDiscard } from '../hooks/useConfirmDiscard';
@ -1213,17 +1214,19 @@ export function MediaEditor({
i18n={i18n}
installedPacks={installedPacks}
knownPacks={[]}
onPickSticker={(_packId, _stickerId, src: string) => {
onPickSticker={async (_packId, _stickerId, src: string) => {
if (!fabricCanvas) {
return;
}
const img = await loadImage(src);
const STICKER_SIZE_RELATIVE_TO_CANVAS = 4;
const size =
Math.min(imageState.width, imageState.height) /
STICKER_SIZE_RELATIVE_TO_CANVAS;
const sticker = new MediaEditorFabricSticker(src);
const sticker = new MediaEditorFabricSticker(img);
sticker.scaleToHeight(size);
sticker.setPositionByOrigin(
new fabric.Point(