mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
This commit is contained in:
parent
54ecf918cb
commit
f80bc646d9
@ -3,7 +3,7 @@ import { Provider as MotionProvider } from 'rc-motion';
|
||||
|
||||
import { useToken } from '../theme/internal';
|
||||
|
||||
const MotionCacheContext = React.createContext({ parentMotion: true });
|
||||
const MotionCacheContext = React.createContext(false);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
MotionCacheContext.displayName = 'MotionCacheContext';
|
||||
}
|
||||
@ -13,20 +13,22 @@ export interface MotionWrapperProps {
|
||||
}
|
||||
|
||||
export default function MotionWrapper(props: MotionWrapperProps): React.ReactElement {
|
||||
const { parentMotion } = React.useContext(MotionCacheContext);
|
||||
const needWrapMotionProvider = React.useContext(MotionCacheContext);
|
||||
|
||||
const { children } = props;
|
||||
const [, token] = useToken();
|
||||
const { motion } = token;
|
||||
|
||||
let node = children as React.ReactElement;
|
||||
if (parentMotion !== motion) {
|
||||
node = <MotionProvider motion={motion}>{children}</MotionProvider>;
|
||||
const needWrapMotionProviderRef = React.useRef(false);
|
||||
needWrapMotionProviderRef.current = needWrapMotionProviderRef.current || motion === false;
|
||||
|
||||
if (needWrapMotionProviderRef.current || needWrapMotionProvider) {
|
||||
return (
|
||||
<MotionCacheContext.Provider value={needWrapMotionProvider}>
|
||||
<MotionProvider motion={motion}>{children}</MotionProvider>
|
||||
</MotionCacheContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<MotionCacheContext.Provider value={{ parentMotion: motion }}>
|
||||
{node}
|
||||
</MotionCacheContext.Provider>
|
||||
);
|
||||
return children as React.ReactElement;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user