Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

✨ Add animation lifecycle callbacks #75

Merged
merged 2 commits into from
Jan 21, 2025
Merged

Conversation

almond-bongbong
Copy link
Owner

Add Animation Lifecycle Callbacks

Overview

This PR introduces animation lifecycle callback props to the SlotCounter component, allowing users to track the start and end of animations.

Changes

  • Add onAnimationStart and onAnimationEnd callback props
  • Implement animation state tracking using isAnimatingRef
  • Add transition end event listener to handle animation completion
  • Handle edge cases when new animation starts while previous one is still running
  • Use ref pattern to prevent unnecessary re-renders from callback changes

Implementation Details

  • Used useRef to store callback functions to prevent unnecessary re-renders
  • Added transitionend event listener to detect animation completion
  • Properly cleanup event listeners to prevent memory leaks
  • Handle edge cases where new animation starts before previous one completes

Usage Example

<SlotCounter
  value={value}
  onAnimationStart={() => console.log('Animation started')}
  onAnimationEnd={() => console.log('Animation completed')}
/>

- Add onAnimationStart and onAnimationEnd props
Copy link
Owner Author

@almond-bongbong almond-bongbong left a comment

Choose a reason for hiding this comment

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

Please add a quick note in the README about onAnimationStart and onAnimationEnd. Thanks.

@almond-bongbong almond-bongbong merged commit 394a4c4 into main Jan 21, 2025
@almond-bongbong almond-bongbong deleted the feature/add-events branch January 21, 2025 22:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant