feat: update
Some checks are pending
Publish Any Commit / build (push) Waiting to run

This commit is contained in:
Wanpan 2025-06-04 17:53:32 +08:00
parent 54ecf918cb
commit f80bc646d9

View File

@ -3,7 +3,7 @@ import { Provider as MotionProvider } from 'rc-motion';
import { useToken } from '../theme/internal'; import { useToken } from '../theme/internal';
const MotionCacheContext = React.createContext({ parentMotion: true }); const MotionCacheContext = React.createContext(false);
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
MotionCacheContext.displayName = 'MotionCacheContext'; MotionCacheContext.displayName = 'MotionCacheContext';
} }
@ -13,20 +13,22 @@ export interface MotionWrapperProps {
} }
export default function MotionWrapper(props: MotionWrapperProps): React.ReactElement { export default function MotionWrapper(props: MotionWrapperProps): React.ReactElement {
const { parentMotion } = React.useContext(MotionCacheContext); const needWrapMotionProvider = React.useContext(MotionCacheContext);
const { children } = props; const { children } = props;
const [, token] = useToken(); const [, token] = useToken();
const { motion } = token; const { motion } = token;
let node = children as React.ReactElement; const needWrapMotionProviderRef = React.useRef(false);
if (parentMotion !== motion) { needWrapMotionProviderRef.current = needWrapMotionProviderRef.current || motion === false;
node = <MotionProvider motion={motion}>{children}</MotionProvider>;
if (needWrapMotionProviderRef.current || needWrapMotionProvider) {
return (
<MotionCacheContext.Provider value={needWrapMotionProvider}>
<MotionProvider motion={motion}>{children}</MotionProvider>
</MotionCacheContext.Provider>
);
} }
return ( return children as React.ReactElement;
<MotionCacheContext.Provider value={{ parentMotion: motion }}>
{node}
</MotionCacheContext.Provider>
);
} }