-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add capability to control resizing animation #59
base: main
Are you sure you want to change the base?
feat: add capability to control resizing animation #59
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hey! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, we have 3 options:
- Allow the customer to choose a behavior specific to resizing items.
- Allow the customer to global strategy for dragging and resizing items.
- Use the existing "snap-to-grid" functionality and apply it to resizing.
I would like us to exhaust the 3rd option before moving on
const defaultCalculateNewSpan: CalculateNewSpan = ({ | ||
span, | ||
direction, | ||
deltaX, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deltaX
is in pixels, and Span
's start
and end
values should be transformed values, relative to the current range.
Make it so the function receives translated values. You can name it delta
, just make sure it receives translated values. You can do so by calling the getValueFromScreenX
and calculating the delta.
const newSpan = calculateNewSpan({ | ||
span: props.span, | ||
direction: dragDirection, | ||
deltaX: dragDeltaX, | ||
}); | ||
const newWidth = valueToPixels(newSpan.end - newSpan.start); | ||
draggableProps.node.current.style.width = `${newWidth}px`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For your particular use case, I suggest you to try and use the existing getValueFromScreenX
function, which already implements "snap-to-grid" behavior.
Maybe calculate the delta.
Or maybe even export snapValueToRangeGrid
function from useTimeline
and use it here?
@@ -25,6 +25,7 @@ export interface UseItemProps | |||
onResizeEnd?: (event: ResizeEndEvent) => void; | |||
onResizeMove?: (event: ResizeMoveEvent) => void; | |||
onResizeStart?: (event: ResizeStartEvent) => void; | |||
calcNewSan?: CalculateNewSpan; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in calcNewSan
Thank you for your review, but I don't have enough time to working on this PR now. |
I would rather allow the custom modifiers from user to inject into the timeline context if possible. something like these. |
I agree, this may be the most flexible option. I am currently unsure as to what should be the appropriate implementation, and currently have no spare time to investigate this. Suggestions will be appreciated 🙏 |
Related to #44
Hi, let me suggest to add the feature to control resize animation.
Currently,
dnd-timeline
doesn't allow us to control the resize animation during pointer move, it only allows whenonResizeEnd
.So user can resize invalid and they notice it on
pointerup
event.I needed to control resize only by specific tick (in my case, 1 day tick) and I implemented it.
The demo movie is here:
2024-09-29.21.31.52.mov
My code is here:
Thank you for your great library and review!