Skip to content

feat(handlebars): Add drag-end animation with spring configuration#332

Open
ChinmayNoob wants to merge 1 commit into
OpenCut-app:mainfrom
ChinmayNoob:chinmay/updatinghandlebars
Open

feat(handlebars): Add drag-end animation with spring configuration#332
ChinmayNoob wants to merge 1 commit into
OpenCut-app:mainfrom
ChinmayNoob:chinmay/updatinghandlebars

Conversation

@ChinmayNoob
Copy link
Copy Markdown

@ChinmayNoob ChinmayNoob commented Jul 17, 2025

Demo

opencut.mp4

Description

This PR enhances the Handlebars component by adding drag-end animation functionality. When users release the handles after dragging, they smoothly animate back to their original positions using spring animations, creating a more polished and interactive user experience.

Motivation: Improve the user interaction feedback and make the component feel more dynamic and responsive.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I have tested the following scenarios:

  • Drag left handle and release - verifies smooth reset animation
  • Drag right handle and release - verifies smooth reset animation
  • Verify text content remains centered and properly spaced
  • Test animation performance and smoothness

Test Configuration:

  • Node version: 18.x
  • Browser: Chrome, Firefox, Safari
  • Operating System: Windows 10

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • The existing component functionality remains unchanged
  • The TypeScript types are properly maintained and enhanced for animation config

Additional context

The animation is implemented using Framer Motion's spring configuration, which can be easily adjusted through the springConfig object if we need to modify the animation feel. The changes maintain the original styling and dimensions while adding this new interactive feature.

Key changes:

  • Added drag state tracking
  • Implemented spring-based reset animation
  • Maintained original component styling
  • Added TypeScript type safety for animation configuration

Summary by CodeRabbit

  • New Features

    • Improved handlebar interaction with animated transitions and smoother drag-and-drop experience.
  • Bug Fixes

    • Resolved issues with handle positions updating abruptly by introducing spring animations for a more natural movement.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jul 17, 2025

👷 Deploy request for appcut pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit cad2d89

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 17, 2025

@ChinmayNoob is attempting to deploy a commit to the OpenCut OSS Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 17, 2025

Walkthrough

The Handlebars component in the landing page now manages an isDragging state to differentiate between dragging and idle states. Drag events update handle positions directly, and when dragging ends, spring animations smoothly reset the handles to their default positions using specific animation parameters.

Changes

File(s) Change Summary
apps/web/src/components/landing/handlebars.tsx Added isDragging state, spring animation for handle reset, and updated drag logic for smooth transitions.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Handlebars Component

  User->>Handlebars Component: Start Drag Handle
  Handlebars Component->>Handlebars Component: set isDragging = true
  User->>Handlebars Component: Drag Handle (move)
  Handlebars Component->>Handlebars Component: Update handle position directly
  User->>Handlebars Component: End Drag
  Handlebars Component->>Handlebars Component: set isDragging = false
  Handlebars Component->>Handlebars Component: Animate handles to default with spring
Loading

Possibly related PRs

  • OpenCut-app/OpenCut#175: Introduced the original Handlebars component; this PR extends its drag logic with state management and animations.

Poem

🐇
Handles glide with springy flair,
Dragging now tracked with extra care.
When you let go, they bounce right back,
Animated smooth—no sudden crack!
A gentle hop, a subtle slide,
In motion’s arms, the handles ride.
—A rabbit’s ode to UI pride!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/web/src/components/landing/handlebars.tsx (2)

37-44: Consider consolidating spring configurations for consistency.

The springConfig object is well-defined, but there are inconsistent spring parameters used in the drag-end animation (lines 49-53, 56-60) versus the handle transitions. Consider using the same configuration throughout for consistent animation feel.

-      animate(leftHandleX, 0, {
-        type: "spring",
-        stiffness: 300,
-        damping: 30,
-        mass: 1
-      });
+      animate(leftHandleX, 0, springConfig);

-      animate(rightHandleX, contentWidth, {
-        type: "spring",
-        stiffness: 300,
-        damping: 30,
-        mass: 1
-      });
+      animate(rightHandleX, contentWidth, springConfig);

46-65: Consider timing of state updates and optimize dependencies.

The drag-end animation logic is sound, but there are two potential improvements:

  1. State update timing: The state updates happen immediately when animation starts, not when it completes. This could cause issues if other components depend on these values during animation.

  2. Unnecessary dependencies: Motion values leftHandleX and rightHandleX don't trigger re-renders, so they may not be needed in the dependency array.

Consider updating state when animation completes:

useEffect(() => {
  if (!isDragging) {
-    animate(leftHandleX, 0, {
+    animate(leftHandleX, 0, {
      type: "spring",
      stiffness: 300,
      damping: 30,
      mass: 1
-    });
+    }).then(() => setLeftHandle(0));

-    animate(rightHandleX, contentWidth, {
+    animate(rightHandleX, contentWidth, {
      type: "spring",
      stiffness: 300,
      damping: 30,
      mass: 1
-    });
+    }).then(() => setRightHandle(contentWidth));

-    setLeftHandle(0);
-    setRightHandle(contentWidth);
  }
-}, [isDragging, contentWidth, leftHandleX, rightHandleX]);
+}, [isDragging, contentWidth]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b97a308 and cad2d89.

📒 Files selected for processing (1)
  • apps/web/src/components/landing/handlebars.tsx (8 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/web/src/components/landing/handlebars.tsx (1)
Learnt from: simonorzel26
PR: OpenCut-app/OpenCut#324
File: apps/web/src/components/editor/snap-indicator.tsx:43-43
Timestamp: 2025-07-17T08:26:10.929Z
Learning: In the timeline refactor PR #324, the snap indicator component in apps/web/src/components/editor/snap-indicator.tsx requires the hard-coded `ml-48` class in addition to the calculated `leftPosition` for proper alignment. This is intentional and needed for the new timeline layout.
🔇 Additional comments (6)
apps/web/src/components/landing/handlebars.tsx (6)

4-4: LGTM: Import addition is correct and necessary.

The animate import is properly added and required for the programmatic spring animations in the drag end functionality.


22-22: LGTM: State management for drag tracking is well-implemented.

The isDragging state properly tracks the drag state to prevent conflicts between manual dragging and automatic spring animations.


87-96: LGTM: Conditional motion value updates prevent animation conflicts.

The addition of isDragging guards in both useEffect hooks is excellent. This prevents the motion values from being overridden during the spring animation, ensuring smooth reset animations without conflicts.


103-103: LGTM: Drag state tracking is properly implemented.

The addition of setIsDragging(true) in both drag handlers correctly marks the beginning of drag operations, enabling proper state management for the animation system.

Also applies to: 112-112


120-122: LGTM: Drag end handler is clean and effective.

The handleDragEnd function properly marks the end of drag operations, triggering the spring animation system through the state change.


152-152: LGTM: Consistent animation configuration across components.

The addition of onDragEnd={handleDragEnd} to both handles and the consistent use of springConfig for transitions creates a cohesive animation experience. This properly integrates the drag-end functionality with the handle interactions.

Also applies to: 155-155, 176-176, 179-179, 200-200

@anwarulislam
Copy link
Copy Markdown
Contributor

It looks cool, but it doesn’t really fit the vibe of video editing. You’re not trimming it right here.

@ChinmayNoob
Copy link
Copy Markdown
Author

Are there any modifications that you can suggest which i can try on this component or is it better to let it be just like how it is

One change i can suggest is how the clips of this components are, we can do it like it is done in all the softwares

2025-07-17.22-09-10.mp4

Otherwise if you are ok with how the component is we can close this pr

@anwarulislam
Copy link
Copy Markdown
Contributor

Hey @ChinmayNoob, I think the current one looks better and fits the vibe. But if you find something that matches the editor vibe even better, go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants