fix: series page not showing correct bg
This commit is contained in:
4 files changed
+50
-19
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
AnimatePresence,
|
||||||
type HTMLMotionProps,
|
type HTMLMotionProps,
|
||||||
motion,
|
motion,
|
||||||
useScroll,
|
useScroll,
|
||||||
@@ -17,6 +18,15 @@ interface ItemBackdropProps {
|
|||||||
motionProps?: HTMLMotionProps<"img">;
|
motionProps?: HTMLMotionProps<"img">;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MotionImg = motion.img;
|
||||||
|
|
||||||
|
const animationProps = {
|
||||||
|
initial: { opacity: 0 },
|
||||||
|
animate: { opacity: 1 },
|
||||||
|
exit: { opacity: 0 },
|
||||||
|
transition: { duration: 0.5 },
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ItemBackdrop delays applying motion-driven parallax until after mount
|
* ItemBackdrop delays applying motion-driven parallax until after mount
|
||||||
* to avoid hydration timing errors ("Target ref is defined but not hydrated").
|
* to avoid hydration timing errors ("Target ref is defined but not hydrated").
|
||||||
@@ -24,7 +34,7 @@ interface ItemBackdropProps {
|
|||||||
* attached, it renders a static img to prevent motion from touching an
|
* attached, it renders a static img to prevent motion from touching an
|
||||||
* unhydrated DOM node.
|
* unhydrated DOM node.
|
||||||
*/
|
*/
|
||||||
function ItemBackdropContent({
|
const ItemBackdropContent = React.memo(function ItemBackdropContent({
|
||||||
targetRef,
|
targetRef,
|
||||||
src,
|
src,
|
||||||
alt,
|
alt,
|
||||||
@@ -47,19 +57,18 @@ function ItemBackdropContent({
|
|||||||
});
|
});
|
||||||
const y = useTransform(scrollYProgress, [0, 1], [-distance, distance]);
|
const y = useTransform(scrollYProgress, [0, 1], [-distance, distance]);
|
||||||
return (
|
return (
|
||||||
<motion.img
|
<MotionImg
|
||||||
alt={alt}
|
alt={alt}
|
||||||
src={src}
|
src={src}
|
||||||
className={className ?? "item-hero-backdrop"}
|
className={className ?? "item-hero-backdrop"}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.currentTarget.style.opacity = "1";
|
|
||||||
onLoad?.(e);
|
onLoad?.(e);
|
||||||
}}
|
}}
|
||||||
style={{ y }}
|
style={{ y }}
|
||||||
{...motionProps}
|
{...motionProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
export function ItemBackdrop({
|
export function ItemBackdrop({
|
||||||
targetRef,
|
targetRef,
|
||||||
@@ -90,6 +99,14 @@ export function ItemBackdrop({
|
|||||||
return () => cancelAnimationFrame(raf);
|
return () => cancelAnimationFrame(raf);
|
||||||
}, [targetRef, ready]);
|
}, [targetRef, ready]);
|
||||||
|
|
||||||
|
const finalMotionProps = React.useMemo(
|
||||||
|
() => ({
|
||||||
|
...animationProps,
|
||||||
|
...motionProps,
|
||||||
|
}),
|
||||||
|
[motionProps],
|
||||||
|
);
|
||||||
|
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
@@ -105,15 +122,18 @@ export function ItemBackdrop({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemBackdropContent
|
<AnimatePresence>
|
||||||
targetRef={targetRef}
|
<ItemBackdropContent
|
||||||
src={src}
|
key={src}
|
||||||
alt={alt}
|
targetRef={targetRef}
|
||||||
distance={distance}
|
src={src}
|
||||||
className={className}
|
alt={alt}
|
||||||
onLoad={onLoad}
|
distance={distance}
|
||||||
motionProps={motionProps}
|
className={className}
|
||||||
/>
|
onLoad={onLoad}
|
||||||
|
motionProps={finalMotionProps}
|
||||||
|
/>
|
||||||
|
</AnimatePresence>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ interface ItemHeaderProps {
|
|||||||
mediaQualityInfo?: MediaQualityInfo;
|
mediaQualityInfo?: MediaQualityInfo;
|
||||||
scrollTargetRef?: RefObject<HTMLDivElement | null>;
|
scrollTargetRef?: RefObject<HTMLDivElement | null>;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
backdropSrc?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ItemHeader = ({
|
const ItemHeader = ({
|
||||||
@@ -43,6 +44,7 @@ const ItemHeader = ({
|
|||||||
mediaQualityInfo,
|
mediaQualityInfo,
|
||||||
scrollTargetRef,
|
scrollTargetRef,
|
||||||
children,
|
children,
|
||||||
|
backdropSrc,
|
||||||
}: ItemHeaderProps) => {
|
}: ItemHeaderProps) => {
|
||||||
const isEpisode = item.Type === "Episode";
|
const isEpisode = item.Type === "Episode";
|
||||||
const backdropTag =
|
const backdropTag =
|
||||||
@@ -61,7 +63,7 @@ const ItemHeader = ({
|
|||||||
const logoId =
|
const logoId =
|
||||||
isEpisode && parentLogoImageTag ? (item.SeriesId ?? item.Id) : item.Id;
|
isEpisode && parentLogoImageTag ? (item.SeriesId ?? item.Id) : item.Id;
|
||||||
|
|
||||||
const LogoOrTitle = () =>
|
const logo =
|
||||||
logoTag ? (
|
logoTag ? (
|
||||||
<img
|
<img
|
||||||
alt={item.Name ?? ""}
|
alt={item.Name ?? ""}
|
||||||
@@ -93,14 +95,15 @@ const ItemHeader = ({
|
|||||||
targetRef={scrollTargetRef}
|
targetRef={scrollTargetRef}
|
||||||
alt={item.Name ?? ""}
|
alt={item.Name ?? ""}
|
||||||
backdropSrc={
|
backdropSrc={
|
||||||
backdropTag
|
backdropSrc ??
|
||||||
|
(backdropTag
|
||||||
? api &&
|
? api &&
|
||||||
getImageUrlsApi(api).getItemImageUrlById(
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
backdropId ?? "",
|
backdropId ?? "",
|
||||||
"Backdrop",
|
"Backdrop",
|
||||||
{ tag: backdropTag },
|
{ tag: backdropTag },
|
||||||
)
|
)
|
||||||
: undefined
|
: undefined)
|
||||||
}
|
}
|
||||||
fallbackSrc={heroBg}
|
fallbackSrc={heroBg}
|
||||||
/>
|
/>
|
||||||
@@ -156,10 +159,10 @@ const ItemHeader = ({
|
|||||||
width: "fit-content",
|
width: "fit-content",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LogoOrTitle />
|
{logo}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<LogoOrTitle />
|
logo
|
||||||
)}
|
)}
|
||||||
{isEpisode && (
|
{isEpisode && (
|
||||||
<Typography mb={2} fontWeight={200} variant="h4">
|
<Typography mb={2} fontWeight={200} variant="h4">
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ $cardWidth: 18%;
|
|||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
object-position: top;
|
object-position: top;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
transition: opacity $transition-time-default;
|
transition: opacity $transition-time-default;
|
||||||
&-container {
|
&-container {
|
||||||
filter: brightness(0.8);
|
filter: brightness(0.8);
|
||||||
|
|||||||
@@ -303,7 +303,12 @@ function SeriesTitlePage() {
|
|||||||
className="scrollY padded-top flex flex-column item item-series"
|
className="scrollY padded-top flex flex-column item item-series"
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
>
|
>
|
||||||
<ItemHeader item={item.data} api={api} scrollTargetRef={containerRef}>
|
<ItemHeader
|
||||||
|
item={item.data}
|
||||||
|
api={api}
|
||||||
|
scrollTargetRef={containerRef}
|
||||||
|
backdropSrc={backdropImage.url}
|
||||||
|
>
|
||||||
<div className="item-hero-buttons-container">
|
<div className="item-hero-buttons-container">
|
||||||
<div
|
<div
|
||||||
className="flex flex-row"
|
className="flex flex-row"
|
||||||
|
|||||||
Reference in new issue
Block a user