framer-motion
Version:
A simple and powerful React animation library
35 lines (32 loc) • 1.73 kB
JavaScript
import { isRefObject } from '../../utils/is-ref-object.mjs';
import { useContext } from 'react';
import { SwitchLayoutGroupContext } from '../../context/SwitchLayoutGroupContext.mjs';
function useProjection(projectionId, _a, visualElement, ProjectionNodeConstructor) {
var _b;
var layoutId = _a.layoutId, layout = _a.layout, drag = _a.drag, dragConstraints = _a.dragConstraints, layoutScroll = _a.layoutScroll;
var initialPromotionConfig = useContext(SwitchLayoutGroupContext);
if (!ProjectionNodeConstructor ||
!visualElement ||
(visualElement === null || visualElement === void 0 ? void 0 : visualElement.projection)) {
return;
}
visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_b = visualElement.parent) === null || _b === void 0 ? void 0 : _b.projection);
visualElement.projection.setOptions({
layoutId: layoutId,
layout: layout,
alwaysMeasureLayout: Boolean(drag) || (dragConstraints && isRefObject(dragConstraints)),
visualElement: visualElement,
scheduleRender: function () { return visualElement.scheduleRender(); },
/**
* TODO: Update options in an effect. This could be tricky as it'll be too late
* to update by the time layout animations run.
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
* ensuring it gets called if there's no potential layout animations.
*
*/
animationType: typeof layout === "string" ? layout : "both",
initialPromotionConfig: initialPromotionConfig,
layoutScroll: layoutScroll,
});
}
export { useProjection };