Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Frozen router for framer motion exit animations to work
- Loading branch information
1 parent
43f206b
commit 36304d3
Showing
8 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use client"; | ||
|
||
import { motion, AnimatePresence } from "framer-motion"; | ||
import ThemeRegistry from "./ThemeRegistry"; | ||
import { PropsWithChildren } from "react"; | ||
|
||
import { useSelectedLayoutSegment } from "next/navigation"; | ||
import FrozenRouter from "@/components/FrozenRouter"; | ||
|
||
// Client wraps any client/rsc components with AnimatePresence | ||
export default function Client({ children }: PropsWithChildren) { | ||
const segment = useSelectedLayoutSegment(); | ||
return ( | ||
<AnimatePresence | ||
initial | ||
mode="wait" | ||
onExitComplete={() => console.log("triggered")} | ||
> | ||
<ThemeRegistry options={{ key: "mui" }} key={segment}> | ||
<motion.main | ||
initial={{ | ||
opacity: 0, | ||
y: -100, | ||
}} | ||
animate={{ | ||
opacity: 1, | ||
y: 0, | ||
}} | ||
exit={{ | ||
opacity: 0, | ||
y: 100, | ||
}} | ||
transition={{ duration: 0.6, ease: "easeInOut" }} | ||
> | ||
<FrozenRouter>{children}</FrozenRouter> | ||
</motion.main> | ||
</ThemeRegistry> | ||
</AnimatePresence> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { LayoutRouterContext } from "next/dist/shared/lib/app-router-context"; | ||
import { useContext, useRef } from "react"; | ||
|
||
export default function FrozenRouter(props: { children: React.ReactNode }) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
const context = useContext(LayoutRouterContext); | ||
const frozen = useRef(context).current; | ||
|
||
return ( | ||
<LayoutRouterContext.Provider value={frozen}> | ||
{props.children} | ||
</LayoutRouterContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 36304d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
faq-accordion-card – ./
faq-accordion-card-ashy-psi.vercel.app
faq-accordion-card-gaurav4604.vercel.app
faq-accordion-card-git-master-gaurav4604.vercel.app
Hello. I was impressed by your work that came over from the framer,nextjs issue/1850.
I had a similar issue myself, where an exit animation occurred after moving to a new page.
I have a question. What is the exact purpose of OuterLayoutRouter that led to the conception of FrozenRouter?
And how does FrozenRouter operate? Thank you if you could provide an answer.