Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Smooth Space profile navbar entrance after scrolling

Anand Baburajanf0bcd575a90a
diff --git a/web/apps/space/src/hooks/use-profile-sticky-header.ts b/web/apps/space/src/hooks/use-profile-sticky-header.ts
index ae0f873486..119da45df6 100644
--- a/web/apps/space/src/hooks/use-profile-sticky-header.ts
+++ b/web/apps/space/src/hooks/use-profile-sticky-header.ts
@@ -5,11 +5,17 @@ export const useProfileStickyHeader = (
identityRef: React.RefObject<HTMLDivElement | null>,
compactHeight: number,
) => {
- const [isSticky, setIsSticky] = React.useState(false);
+ const [header, setHeader] = React.useState({
+ isSticky: false,
+ shouldAnimate: false,
+ });
const syncScroll = React.useCallback(() => {
const identity = identityRef.current;
if (!enabled || !identity) return;
- setIsSticky(identity.getBoundingClientRect().bottom < compactHeight);
+ setHeader({
+ isSticky: identity.getBoundingClientRect().bottom < compactHeight,
+ shouldAnimate: false,
+ });
}, [compactHeight, enabled, identityRef]);
React.useLayoutEffect(() => {
@@ -17,13 +23,20 @@ export const useProfileStickyHeader = (
if (!enabled || !identity) return;
syncScroll();
const observer = new IntersectionObserver(
- ([entry]) =>
- setIsSticky(entry!.boundingClientRect.bottom < compactHeight),
+ ([entry]) => {
+ const isSticky =
+ entry!.boundingClientRect.bottom < compactHeight;
+ setHeader((current) =>
+ current.isSticky == isSticky
+ ? current
+ : { isSticky, shouldAnimate: true },
+ );
+ },
{ rootMargin: `-${compactHeight}px 0px 0px`, threshold: 0 },
);
observer.observe(identity);
return () => observer.disconnect();
}, [compactHeight, enabled, identityRef, syncScroll]);
- return { isSticky, syncScroll };
+ return { ...header, syncScroll };
};
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 6deaa4c519..d61a5de447 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -645,7 +645,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const canOpenProfileCover = Boolean(onOpenProfileCover);
const canOpenProfilePhoto = Boolean(onOpenProfilePhoto);
const hasProfilePosts = postsSharedCount > 0;
- const { isSticky, syncScroll } = useProfileStickyHeader(
+ const { isSticky, shouldAnimate, syncScroll } = useProfileStickyHeader(
!isPublicProfile,
profileIdentityRef,
profileStickyHeaderHeight,
@@ -1233,8 +1233,10 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
py: 0,
top: compact ? 0 : undefined,
transition:
- compact && !isSticky
- ? "opacity 160ms ease-out"
+ compact && shouldAnimate
+ ? isSticky
+ ? "opacity 240ms ease-in-out"
+ : "opacity 160ms ease-out"
: "none",
width: "100%",
zIndex: compact ? 10 : 3,