ISSUE-017 - Figured out how to allow for Transition and Dragging on the same element.

The secret? Don't! Use another throw-away div and put it around the draggable div.
Also adopted animated.div into the Styled-Component. Really cool how it just works.
This commit is contained in:
Kyle Geib committed 2022-01-12 14:52:38 -05:00
1 parent 9541306894
commit a6a5eb7751
2 files changed
+28 -8

No files matched your search

@@ -5,7 +5,7 @@ import { useDrag } from "@use-gesture/react";
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
import { OverlayItemContainer } from "./styles";
import { AnimatedOverlayItemContainer } from "./styles";
export function OverlayDisplay() {
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
@@ -37,21 +37,20 @@ export function OverlayDisplay() {
return (
transition((style, visible) =>
visible ? (
<animated.div
<animated.div style={{ ...style, position: "absolute" }}>
<AnimatedOverlayItemContainer
{...bindOverlayItem({ xPos, yPos })}
style={{
...style,
left: xPos,
// top: style.top.get() + yPos, // This doesn't work.
top: yPos,
position: "absolute",
}}
visible={visible}
>
<OverlayItemContainer position={position} visible={visible}>
{id}
<br />
(x:{position.x}px, y:{position.y}px)
</OverlayItemContainer>
</AnimatedOverlayItemContainer>
</animated.div>
) : null,
)
@@ -1,3 +1,4 @@
import { animated } from "@react-spring/web";
import styled from "styled-components";
import { OverlayPosition } from "../../../types/state";
@@ -11,8 +12,8 @@ export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(
visible,
}) => ({
style: {
// top: y,
// left: x,
top: y,
left: x,
display: visible ? undefined : "none",
},
}))<OverlayItemContainerProps>`
@@ -24,3 +25,23 @@ export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(
`;
OverlayItemContainer.displayName = "OverlayItemContainer";
type AnimatedOverlayItemContainerProps = {
visible: boolean,
}
export const AnimatedOverlayItemContainer = styled(animated.div).attrs<AnimatedOverlayItemContainerProps>(({
visible,
}) => ({
style: {
display: visible ? undefined : "none",
},
}))<AnimatedOverlayItemContainerProps>`
position: absolute;
z-index: 1;
/* Temporary. Overlay will be transparent and based on an image. */
width: 150px;
height: 150px;
background-color: white;
box-shadow: 0px 7px 11px 1px black;
`;