Skip to content

Commit

Permalink
fix(ui/post): progress indicator init should start with zero
Browse files Browse the repository at this point in the history
  • Loading branch information
sawaYch committed Nov 25, 2023
1 parent 647ef7c commit b9718e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 360 deletions.
4 changes: 2 additions & 2 deletions src/components/application-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const ApplicationPane: React.FC<ApplicationPaneProps> = ({
const variants = useMemo(
() => ({
open: {
transition: { staggerChildren: 0.07, delayChildren: 0.2 },
// transition: { staggerChildren: 0.07, delayChildren: 0.2 },
},
closed: {
transition: { staggerChildren: 0.01, staggerDirection: -1 },
// transition: { staggerChildren: 0.01, staggerDirection: -1 },
},
}),
[]
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const Layout: FC<PropsWithChildren<PageProps>> = ({ children, location }) => {
/>
)}
<Header />
<StyledMain ref={ref}>
<StyledMain id="main" ref={ref}>
<StaticImage
className="!fixed top-0 left-0 opacity-bg w-screen h-screen pointer-events-none select-none z-20"
src="../images/girl.png"
Expand Down
20 changes: 19 additions & 1 deletion src/components/progress-indicator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { MotionValue, motion, useSpring } from 'framer-motion';
import { useEffect, useState } from 'react';
import cn from 'classnames';

interface ProgressIndicatorProps {
scrollYProgress: MotionValue<number>;
Expand All @@ -11,7 +13,23 @@ const ProgressIndicator = ({ scrollYProgress }: ProgressIndicatorProps) => {
restDelta: 0.001,
});

return <motion.div className="progress-bar z-[51]" style={{ scaleX }} />;
const [hasScrollEventFired, setHasScrollEventFired] = useState(false);

useEffect(() => {
const styledMain = document.getElementById('main');
if (styledMain == null) return;
styledMain.addEventListener('scroll', () => setHasScrollEventFired(true));
}, []);

return (
<motion.div
className={cn('progress-bar z-[51]', {
invisible: !hasScrollEventFired,
visible: hasScrollEventFired,
})}
style={{ scaleX }}
/>
);
};

export default ProgressIndicator;
Loading

0 comments on commit b9718e9

Please sign in to comment.