MotionWrapper.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. "use client";
  3. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
  4. Object.defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.default = MotionWrapper;
  8. var React = _interopRequireWildcard(require("react"));
  9. var _rcMotion = require("rc-motion");
  10. var _internal = require("../theme/internal");
  11. const MotionCacheContext = /*#__PURE__*/React.createContext(true);
  12. if (process.env.NODE_ENV !== 'production') {
  13. MotionCacheContext.displayName = 'MotionCacheContext';
  14. }
  15. function MotionWrapper(props) {
  16. const parentMotion = React.useContext(MotionCacheContext);
  17. const {
  18. children
  19. } = props;
  20. const [, token] = (0, _internal.useToken)();
  21. const {
  22. motion
  23. } = token;
  24. const needWrapMotionProviderRef = React.useRef(false);
  25. needWrapMotionProviderRef.current || (needWrapMotionProviderRef.current = parentMotion !== motion);
  26. if (needWrapMotionProviderRef.current) {
  27. return /*#__PURE__*/React.createElement(MotionCacheContext.Provider, {
  28. value: motion
  29. }, /*#__PURE__*/React.createElement(_rcMotion.Provider, {
  30. motion: motion
  31. }, children));
  32. }
  33. return children;
  34. }