mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +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';
|
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>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user