Skip to content
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: and cancel method to useAnimationState() and useDynamicAnimation() #367

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JeongHeonK
Copy link

What?

  • add cancel() method to useAnimationState() and useDynamicAnimation()

Why?

  • Existing hooks do not allow animations to be paused but rather only enable control through specified keys.
  • After analyzing the provided Moti components, it was observed that they use merged style and useAnimationStyle() instead of shared values, which makes implementing a cancel method infeasible.
  • To implement functionality that allows animations to be paused rather than outright canceled, it seems necessary to introduce a cancel method.

How?

As shown in the file changes below, I added the cancel method to execute the cancelAnimation() function from the Reanimated library and updated the types accordingly.

Usage

const animationState = useAnimationState({
  from: {
    opacity: 0,
    scale: 0.9,
  },
  to: {
    opacity: 1,
    scale: 1.1,
  },
  expanded: {
    scale: 2,
  },
});

const onPress = () => {
  if (animationState.current === "to") {
    animationState.transitionTo("expanded");
  }
};

const onCancel = () => {
  animationState.cancel();
};

Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
moti ❌ Failed (Inspect) Nov 26, 2024 10:27am

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.

1 participant