ISSUE-017 - Basic drag functionality added.
I cannot combine it with transition handling any top/left transitions.
This commit is contained in:
1 parent
1ba5e99532
commit
9541306894
4 files changed
+36
-8
No files matched your search
@@ -1,23 +1,31 @@
|
||||
import { useSelector } from "react-redux";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { useTransition, animated } from "@react-spring/web";
|
||||
import { useDrag } from "@use-gesture/react";
|
||||
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
||||
|
||||
import { OverlayItemContainer } from "./styles";
|
||||
|
||||
export function OverlayDisplay() {
|
||||
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
|
||||
const dispatch = useDispatch();
|
||||
const bindOverlayItem = useDrag((state) => {
|
||||
dispatch(setPosition({
|
||||
x: state.args[0].xPos + state.delta[0],
|
||||
y: state.args[0].yPos + state.delta[1],
|
||||
}));
|
||||
});
|
||||
|
||||
const xPos = currentOverlayItem?.position.x ?? 0;
|
||||
const yPos = currentOverlayItem?.position.y ?? 0;
|
||||
const transition = useTransition(visible, {
|
||||
from: { left: xPos, top: yPos + 50, opacity: 0 },
|
||||
from: { top: 50, opacity: 0 },
|
||||
enter: {
|
||||
left: xPos,
|
||||
top: yPos,
|
||||
top: 0,
|
||||
opacity: currentOverlayItem?.opacity ?? 1,
|
||||
},
|
||||
leave: { left: xPos, top: yPos + 50, opacity: 0 },
|
||||
leave: { top: 50, opacity: 0 },
|
||||
});
|
||||
|
||||
if (currentOverlayItem == null) {
|
||||
@@ -30,7 +38,14 @@ export function OverlayDisplay() {
|
||||
transition((style, visible) =>
|
||||
visible ? (
|
||||
<animated.div
|
||||
style={{ ...style, position: "absolute" }}
|
||||
{...bindOverlayItem({ xPos, yPos })}
|
||||
style={{
|
||||
...style,
|
||||
left: xPos,
|
||||
// top: style.top.get() + yPos, // This doesn't work.
|
||||
top: yPos,
|
||||
position: "absolute",
|
||||
}}
|
||||
>
|
||||
<OverlayItemContainer position={position} visible={visible}>
|
||||
{id}
|
||||
|
||||
@@ -11,8 +11,8 @@ export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(
|
||||
visible,
|
||||
}) => ({
|
||||
style: {
|
||||
top: y,
|
||||
left: x,
|
||||
// top: y,
|
||||
// left: x,
|
||||
display: visible ? undefined : "none",
|
||||
},
|
||||
}))<OverlayItemContainerProps>`
|
||||
|
||||
Reference in new issue
Block a user