feat:碎片完善
This commit is contained in:
1 parent
ec7e8e2bd2
commit
046501705f
74 files changed
+1602
-172
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { createContext, useContext, ReactNode } from "react";
|
||||
|
||||
interface PuzzleAnimationContextType {
|
||||
/** 触发碎片动画,传递碎片ID */
|
||||
triggerPuzzleAnimation: (pieceId: number) => void;
|
||||
}
|
||||
|
||||
const PuzzleAnimationContext = createContext<PuzzleAnimationContextType | null>(
|
||||
null
|
||||
);
|
||||
|
||||
export const PuzzleAnimationProvider = ({
|
||||
children,
|
||||
triggerPuzzleAnimation,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
triggerPuzzleAnimation: (pieceId: number) => void;
|
||||
}) => {
|
||||
return (
|
||||
<PuzzleAnimationContext.Provider value={{ triggerPuzzleAnimation }}>
|
||||
{children}
|
||||
</PuzzleAnimationContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const usePuzzleAnimation = () => {
|
||||
const context = useContext(PuzzleAnimationContext);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"usePuzzleAnimation must be used within PuzzleAnimationProvider"
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in new issue
Block a user