Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

feat: adding play arrow to share page portal animation #407

Merged
merged 5 commits into from
Jan 20, 2023
Merged
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: 1 addition & 0 deletions functions/src/share/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const BaseHTMLContext: Record<string, string | Record<string, string>> = {
playerVolume: bucketPathForFile('public/player-volume.png'),
playerFullscreen: bucketPathForFile('public/player-fullscreen.png'),
close: bucketPathForFile('public/close.png'),
portalArrowIcon: bucketPathForFile('public/portal-play-icon.png'),
desktopPortalSpritesheet: bucketPathForFile('public/desktop-portal-spritesheet.png'),
mobilePortalSpritesheet: bucketPathForFile('public/mobile-portal-spritesheet.png'),
},
Expand Down
31 changes: 28 additions & 3 deletions functions/src/share/templates/portal-animation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,23 @@ export default `
},
};

function Sprite({
function ThumbSprite({
spritePath,
playIconPath,
position = [0, 0],
size,
}) {
let image;
let playIconImage;
let loaded = false;
let playIconLoaded = false;

let x = position[0]; y = position[1];

let renderOffset, renderSize;

this.load = function(canvas) {
return new Promise((resolve, reject) => {
const thumbPromise = new Promise((resolve, reject) => {
if (image && loaded) {
resolve();
} else {
Expand All @@ -144,6 +147,19 @@ export default `
}
}
});

const playIconPromise = new Promise((resolve, reject) => {
if (playIconImage && playIconLoaded) {
resolve();
} else {
playIconImage = new Image();
playIconImage.src = playIconPath;
playIconImage.onload = function() {
resolve();
}
}
});
return Promise.all([thumbPromise, playIconPromise]);
};

this.update = function(_) {}
Expand All @@ -168,6 +184,14 @@ export default `
renderHeight, // dHeight
);

canvas.drawImage(
playIconImage,
x + thumbWidth / 2 - 75,
y + thumbHeight / 2 - 75,
140,
140,
);

canvas.restore();
}
}
Expand Down Expand Up @@ -274,8 +298,9 @@ export default `
mode.textureSize,
);

const thumb = new Sprite({
const thumb = new ThumbSprite({
spritePath: '{{{thumbImageUrl}}}',
playIconPath: '{{{assetUrls.portalArrowIcon}}}',
position: mode.thumbOffset,
size: mode.thumbSize,
});
Expand Down