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

fix:withDecay animation not starting if inital value is set to 0 #6769

Merged

Conversation

patrycjakalinska
Copy link
Contributor

@patrycjakalinska patrycjakalinska commented Nov 27, 2024

Summary

To ensure the animation is correctly initialized and starts as expected we set its current value to undefined. Setting current to 0 breaks the animation.

Fixes #6680.

Test plan

Run code snippet in React Native Paper example 🚀

Code snippet used in issue
import React from 'react';
import { Pressable, Text } from 'react-native';
import Animated, {
  useAnimatedStyle,
  useSharedValue,
  withDecay,
} from 'react-native-reanimated';

export default function EmptyExample() {
  const translateY = useSharedValue(0); 

  const style = useAnimatedStyle(() => ({
    transform: [{ translateY: translateY.value }],
  }));

  return (
    <>
      <Pressable
        style={{ padding: 100, backgroundColor: 'purple' }}
        onPress={() => {
          translateY.value = withDecay({
            velocity: 200,
          });
        }}>
        <Text style={{ fontSize: 50 }}>open</Text>
      </Pressable>
      <Animated.View
        style={[
          {
            backgroundColor: 'blue',
            width: 100,
            height: 100,
          },
          style,
        ]}
      />
    </>
  );
}

@patrycjakalinska patrycjakalinska marked this pull request as draft November 27, 2024 15:48
@patrycjakalinska patrycjakalinska marked this pull request as ready for review November 28, 2024 13:09
@patrycjakalinska patrycjakalinska added this pull request to the merge queue Feb 3, 2025
Merged via the queue into main with commit d77510f Feb 3, 2025
9 checks passed
@patrycjakalinska patrycjakalinska deleted the @patrycjakalinska/with-decay-never-start-issue branch February 3, 2025 15:56
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.

withDecay() never starts if initial value is 0
3 participants