π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[photos][web] Animate sidebar opening and closing
AswinAsokb9ff5d9cbc86
diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsxindex b663b77990..598f6bbdb8 100644--- a/web/apps/photos/src/components/gallery/BarImpl.tsx+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx@@ -487,9 +487,8 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({"--gallery-navigation-surface": "#FFFFFF","--gallery-navigation-hover":"color-mix(in srgb, var(--mui-palette-text-base) 8%, var(--gallery-navigation-surface))",- display: collapsed && !mobile ? "none" : "flex",flexShrink: 0,- width: mobile ? "100%" : 328,+ width: "100%",height: "100%",minHeight: 0,px: mobile ? "12px" : "16px",diff --git a/web/apps/photos/src/components/gallery/NavigationSlide.tsx b/web/apps/photos/src/components/gallery/NavigationSlide.tsxnew file mode 100644index 0000000000..110e8f42d5--- /dev/null+++ b/web/apps/photos/src/components/gallery/NavigationSlide.tsx@@ -0,0 +1,56 @@+import { Box } from "@mui/material";+import type { PropsWithChildren } from "react";+import {+ navigationMotion,+ useNavigationContentMotion,+} from "./use-navigation-content-motion";++export const NavigationSlide: React.FC<+ PropsWithChildren<{+ open: boolean;+ width: number | { xs: number; sm: number };+ reduceMotion: boolean;+ rail?: boolean;+ }>+> = ({ open, width, reduceMotion, rail, children }) => {+ const positionRef = useNavigationContentMotion(open, reduceMotion);+ return (+ <Box+ ref={positionRef}+ inert={!open}+ sx={{+ position: "relative",+ flexShrink: 0,+ width: open ? width : 0,+ height: "100%",+ pointerEvents: open ? undefined : "none",+ zIndex: rail ? 2 : 1,+ }}+ >+ <Box+ sx={{+ position: "absolute",+ inset: "0 auto 0 0",+ width,+ overflow: "clip",+ }}+ >+ <Box+ sx={{+ height: "100%",+ transform:+ open || reduceMotion+ ? "translateX(0)"+ : "translateX(-100%)",+ opacity: open ? 1 : 0,+ transition: reduceMotion+ ? `opacity ${navigationMotion.fadeDuration}ms ${navigationMotion.easing}`+ : `transform ${navigationMotion.duration}ms ${navigationMotion.easing}, opacity ${navigationMotion.fadeDuration}ms ${navigationMotion.easing}`,+ }}+ >+ {children}+ </Box>+ </Box>+ </Box>+ );+};diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsxindex 0da8225f02..23a863d6f0 100644--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx@@ -41,7 +41,9 @@ import {type GalleryBarImplProps,type GalleryBarPresentationProps,} from "./BarImpl";+import { NavigationSlide } from "./NavigationSlide";import type { GalleryBarMode } from "./reducer";+import { useNavigationContentMotion } from "./use-navigation-content-motion";type GalleryNavigation = Omit<GalleryBarImplProps,@@ -75,10 +77,20 @@ export const PhotosNavigationShell: React.FC<...props}) => {const isOffline = useIsOffline();+ const reduceMotion = useMediaQuery("(prefers-reduced-motion: reduce)");const [railOpen, setRailOpen] = useState(true);const [navigationCollapsed, setNavigationCollapsed] = useState(false);const toggleRail = () => setRailOpen((open) => !open);const mobile = useMediaQuery(useTheme().breakpoints.down("md"));+ const panelOpen =+ railOpen &&+ !!galleryNavigation &&+ !props.isInSearchMode &&+ !navigationCollapsed;+ const contentRef = useNavigationContentMotion(+ `${mobile}-${panelOpen}-${railOpen}`,+ reduceMotion,+ );const { show: showMobileNavigation, props: mobileDrawerProps } =useModalVisibility();const { onClose: closeMobileNavigation } = mobileDrawerProps;@@ -144,6 +156,17 @@ export const PhotosNavigationShell: React.FC<setNavigationCollapsed(false);if (mobile) showMobileNavigation();};+ const galleryBar = galleryNavigation && (+ <GalleryBarImpl+ {...galleryNavigation}+ mode={props.mode}+ collapsed={!panelOpen}+ mobileDrawerProps={mobileDrawerProps}+ onCreateAlbum={openAlbumCreation}+ onSelectCollectionID={selectCollection}+ onSelectPerson={selectPerson}+ />+ );return (<Stacksx={(theme) => ({@@ -152,8 +175,9 @@ export const PhotosNavigationShell: React.FC<minHeight: 0,bgcolor: "#F4F4F4",...theme.applyStyles("light", {- "& > :first-child .MuiButton-colorSecondary, & > :last-child > nav .MuiButton-colorSecondary":- { "--mui-palette-secondary-main": "#FFFFFF" },+ "& > :first-child .MuiButton-colorSecondary": {+ "--mui-palette-secondary-main": "#FFFFFF",+ },}),...theme.applyStyles("dark", { bgcolor: "#161616" }),})}@@ -179,44 +203,58 @@ export const PhotosNavigationShell: React.FC<flex: 1,minWidth: 0,minHeight: 0,+ overflow: "clip",p: {xs: railOpen ? "0 8px 8px 0" : "0 8px 8px",sm: railOpen ? "0 11px 11px 0" : "0 11px 11px",},}}>- <Box- component="nav"- sx={{- display: railOpen ? "flex" : "none",- flexDirection: "column",- alignItems: "center",- flexShrink: 0,- width: { xs: "56px", sm: "72px" },- px: { xs: "9px", sm: "14px" },- gap: "12px",- }}+ <NavigationSlide+ open={railOpen}+ width={{ xs: 56, sm: 72 }}+ reduceMotion={reduceMotion}+ rail>- {alternateHeader == null && (- <NormalNavigationRail- {...props}- isHome={- props.mode == "albums" &&- !props.isInSearchMode &&- galleryNavigation?.activeCollectionID ==- PseudoCollectionID.all- }- onChangeMode={handleChangeMode}- opensDialog={mobile}- navigationOpen={- !!galleryNavigation &&- (mobile- ? mobileDrawerProps.open- : !navigationCollapsed)- }- />- )}- </Box>+ <Box+ component="nav"+ sx={(theme) => ({+ display: "flex",+ height: "100%",+ flexDirection: "column",+ alignItems: "center",+ flexShrink: 0,+ width: "100%",+ px: { xs: "9px", sm: "14px" },+ gap: "12px",+ ...theme.applyStyles("light", {+ "& .MuiButton-colorSecondary": {+ "--mui-palette-secondary-main": "#FFFFFF",+ },+ }),+ })}+ >+ {alternateHeader == null && (+ <NormalNavigationRail+ {...props}+ isHome={+ props.mode == "albums" &&+ !props.isInSearchMode &&+ galleryNavigation?.activeCollectionID ==+ PseudoCollectionID.all+ }+ onChangeMode={handleChangeMode}+ opensDialog={mobile}+ navigationOpen={+ !!galleryNavigation &&+ (mobile+ ? mobileDrawerProps.open+ : !navigationCollapsed)+ }+ />+ )}+ </Box>+ </NavigationSlide><Stacksx={{flex: 1,@@ -227,15 +265,17 @@ export const PhotosNavigationShell: React.FC<>{galleryNavigation && !props.isInSearchMode && (<>- <GalleryBarImpl- {...galleryNavigation}- mode={props.mode}- collapsed={!railOpen || navigationCollapsed}- mobileDrawerProps={mobileDrawerProps}- onCreateAlbum={openAlbumCreation}- onSelectCollectionID={selectCollection}- onSelectPerson={selectPerson}- />+ {mobile ? (+ galleryBar+ ) : (+ <NavigationSlide+ open={panelOpen}+ width={328}+ reduceMotion={reduceMotion}+ >+ {galleryBar}+ </NavigationSlide>+ )}<CreateAlbumDialog{...albumNameInputVisibilityProps}isHidden={createInHiddenSection}@@ -245,6 +285,7 @@ export const PhotosNavigationShell: React.FC<</>)}<Stack+ ref={contentRef}sx={{ flex: 1, minWidth: 0, minHeight: 0, gap: "8px" }}><Stackdiff --git a/web/apps/photos/src/components/gallery/use-navigation-content-motion.ts b/web/apps/photos/src/components/gallery/use-navigation-content-motion.tsnew file mode 100644index 0000000000..a4c1b623ae--- /dev/null+++ b/web/apps/photos/src/components/gallery/use-navigation-content-motion.ts@@ -0,0 +1,58 @@+import { useEffect, useLayoutEffect, useRef } from "react";++export const navigationMotion = {+ easing: "cubic-bezier(0.32, 0.72, 0, 1)",+ duration: 200,+ fadeDuration: 150,+};++export const useNavigationContentMotion = (+ layoutKey: string | boolean,+ reduceMotion: boolean,+) => {+ const ref = useRef<HTMLDivElement>(null);+ const previousLeft = useRef<number | undefined>(undefined);+ const animation = useRef<Animation | undefined>(undefined);++ useLayoutEffect(() => {+ const element = ref.current;+ if (!element) return;+ const previousAnimation = animation.current;+ const offset =+ !reduceMotion && previousAnimation?.playState == "running"+ ? new DOMMatrixReadOnly(getComputedStyle(element).transform).m41+ : 0;+ previousAnimation?.cancel();+ animation.current = undefined;+ const left = element.getBoundingClientRect().left;+ const from = previousLeft.current;+ previousLeft.current = left;+ if (from === undefined || reduceMotion) return;+ const delta = from + offset - left;+ if (Math.abs(delta) < 0.5) return;+ const motion = element.animate(+ [+ { transform: `translateX(${delta}px)` },+ { transform: "translateX(0)" },+ ],+ {+ duration: navigationMotion.duration,+ easing: navigationMotion.easing,+ },+ );+ animation.current = motion;+ }, [layoutKey, reduceMotion]);++ useEffect(() => {+ const resetPosition = () => {+ animation.current?.cancel();+ previousLeft.current = ref.current?.getBoundingClientRect().left;+ };+ window.addEventListener("resize", resetPosition);+ return () => {+ window.removeEventListener("resize", resetPosition);+ animation.current?.cancel();+ };+ }, []);+ return ref;+};