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

withDecay() never starts if initial value is 0 #6680

Open
gaearon opened this issue Nov 8, 2024 · 2 comments · May be fixed by #6769
Open

withDecay() never starts if initial value is 0 #6680

gaearon opened this issue Nov 8, 2024 · 2 comments · May be fixed by #6769
Labels
Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@gaearon
Copy link
Contributor

gaearon commented Nov 8, 2024

Description

The withDecay animation never starts if the initial value is 0.

import React from 'react';
import {Pressable, Text} from 'react-native';
import Animated, {
  useAnimatedStyle,
  useSharedValue,
  withDecay,
} from 'react-native-reanimated';

export default function App() {
  const translateY = useSharedValue(0); // <------- if you change it to 1, it'll work
  const style = useAnimatedStyle(() => ({
    transform: [{translateY: translateY.value}],
  }));
  return (
    <>
      <Pressable
        style={{padding: 100, fontSize: 50, backgroundColor: 'purple'}}
        onPress={() => {
          translateY.value = withDecay({
            velocity: 200,
          });
        }}>
        <Text>open</Text>
      </Pressable>
      <Animated.View
        style={[
          {
            backgroundColor: 'blue',
            width: 100,
            height: 100,
          },
          style,
        ]}
      />
    </>
  );
}
withdecay.mov

Steps to reproduce

See above, pretty easy repro.

Seems to affect both iOS and Android.

Testing on Paper, not sure about Fabric.

Snack or a link to a repository

https://github.com/gaearon/reanimated-repro-weird/commits/withdecay-bug (note the branch!)

Reanimated version

3.16.1

React Native version

0.76.1

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Debug app & dev bundle

Device

Android emulator

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snippet of code, snack or repo is provided labels Nov 8, 2024
@gaearon
Copy link
Contributor Author

gaearon commented Nov 9, 2024

There's gotta be a if (!sharedValue.value) somewhere, isn't it?

@patrycjakalinska
Copy link
Contributor

Hi @gaearon, your intuition was good! There was a condition that prevented the animation from running when the same value was set.

In the linked PR I've managed to fix this problem by setting an additional flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snippet of code, snack or repo is provided
Projects
None yet
2 participants