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

withSpring is behaving weirdly #1804

Closed
pranshuchittora opened this issue Mar 7, 2021 · 18 comments
Closed

withSpring is behaving weirdly #1804

pranshuchittora opened this issue Mar 7, 2021 · 18 comments
Assignees
Labels
Bug Platform: Web This issue is specific to web 🏠 Reanimated 2

Comments

@pranshuchittora
Copy link

pranshuchittora commented Mar 7, 2021

Description

I am trying to use withSpring to animate the height and width. After completing the animation it's going to some weird values.

Screenshots

Peek 2021-03-08 02-22

The box with the dashed border is the expected size, after completing it's going to some unexpected values.

Steps To Reproduce

It should work as expected. I tried using withTiming and it's working as expected on withSpring is behaving weirdly.

Snack or minimal code example

Snack is not allowing to install Reanimated v2 :(

Package versions

  • React:17.0.1
  • React Native: 0.63.4
  • React Native Reanimated: v2.0.0
  • NodeJS: v14 stable

Edit

Here's the hosted preview
https://affectionate-perlman-8d974a.netlify.app/

Repro steps

  1. Hit Shuffle
  2. Hit Play Animation

You will notice after completing the animation it goes to some arbitrary value.
And here's the code -> https://github.com/funcsio/reanimated-web-setup

Let me know if there's an issue with my implementation

@github-actions
Copy link

github-actions bot commented Mar 7, 2021

Issue validator

The issue is invalid!

  • Section required but not found: expected behavior(for label 🐞 bug)
  • Section required but not found: actual behavior(for label 🐞 bug)

@jakub-gonet jakub-gonet added the Platform: Web This issue is specific to web label Mar 8, 2021
@jakub-gonet jakub-gonet changed the title v2[Web]: withSpring is behaving weirdly withSpring is behaving weirdly Mar 8, 2021
@nandorojo
Copy link
Contributor

I've also noticed issues with withSpring, namely on web. I'll see if I can create a reproduction.

@pranshuchittora
Copy link
Author

@nandorojo If you want I can host a demo, I already have a custom setup for the web handy

@mrousavy
Copy link
Contributor

mrousavy commented Mar 8, 2021

Could you create/share a reproduction of that issue? Minimal GitHub repos are fine if snack doesn't work

@pranshuchittora
Copy link
Author

Here's the hosted preview
https://affectionate-perlman-8d974a.netlify.app/

Repro steps

  1. Hit Shuffle
  2. Hit Play Animation

You will notice after completing the animation it goes to some arbitrary value.
And here's the code -> https://github.com/funcsio/reanimated-web-setup

Let me know if there's an issue with my implementation

@piaskowyk piaskowyk self-assigned this Mar 11, 2021
@piaskowyk
Copy link
Member

@pranshuchittora This is related to react-native-web version. Look at this comment It just a temporary solution, but we will work on this.

@pranshuchittora
Copy link
Author

Thanks

@nandorojo
Copy link
Contributor

@piaskowyk thanks! I'm already on RNW 14, so that solution unfortunately won't work for me. Do you have an idea of when this might be resolved?

@piaskowyk
Copy link
Member

@nandorojo I debugged this today and I found a reason - this isn't problem with forwardedRef. In my opinion this is a bug in react-native-web. I created an issue and described a problem there. I know how to fix it but I want to discuss with RNW team. Probably I will prepare PR with fix to RNW next week.

@nandorojo
Copy link
Contributor

nandorojo commented Mar 12, 2021

That looks right, thanks for taking the time. I believe setNativeProps is going to get deprecated in the future. Is there an alternative?

See fixes: https://github.com/necolas/react-native-web/releases?after=0.13.4

image

@pranshuchittora
Copy link
Author

Just found out that setting Overshoot Clamping of withSpring to true, makes the withSpring work as expected on web.
On the other hand, setting it to false (default) makes the animation glitchy on completion.

@nandorojo
Copy link
Contributor

@pranshuchittora Great to know. Do you have a video/example showing the difference, by chance?

@pranshuchittora
Copy link
Author

@nandorojo you can replicate the same over here -> https://reanimated.funcs.io/

@nandorojo
Copy link
Contributor

nandorojo commented Mar 19, 2021

Can we re-open this issue? While overshootClamping: false solves it, this is not a full solution.

Once react-native-web merges necolas/react-native-web#1939, it should be good to close.

@nandorojo
Copy link
Contributor

If anyone is coming here from Moti, I added relevant docs here with this commit.

@piaskowyk
Copy link
Member

My PR for react-native-web with the fix of this issue is on the roadmap to release RNW. I suppose It'll be merged within the next release of RNW.

@nandorojo
Copy link
Contributor

I upgraded to RNW 0.15.3, (the patch was in 0.15.2) but my withSpring behavior is the same. Do I need to change anything else? I'm using 2.0.0-rc.0.

@pranshuchittora
Copy link
Author

Hi @nandorojo , I just upgraded the deps and it's working perfectly.

   "react-native": "^0.64.0",
    "react-native-reanimated": "^2.1.0",
    "react-native-web": "^0.15.5",

For demo -> https://reanimated.funcs.io/#/reanimated/dimensions

hyochan pushed a commit to hyochan/hackatalk that referenced this issue Jul 28, 2021
`transform` animation value is not preserved between render on mobile. This is the reason that `scale` is return to origin when writing a text on `textInput` which invokes `re-render`.  So I changed animation value from `scale` to `width` and `height`.

But there is a bug about `withSpring` function on `web`, then I splits an animation value according to platform. 
This bug seems to have related with `react-native-web`.  You can check relate issue with [here](software-mansion/react-native-reanimated#1804) or [here](necolas/react-native-web#1935).
imjlk pushed a commit to imjlk/hackatalk that referenced this issue Aug 19, 2021
`transform` animation value is not preserved between render on mobile. This is the reason that `scale` is return to origin when writing a text on `textInput` which invokes `re-render`.  So I changed animation value from `scale` to `width` and `height`.

But there is a bug about `withSpring` function on `web`, then I splits an animation value according to platform. 
This bug seems to have related with `react-native-web`.  You can check relate issue with [here](software-mansion/react-native-reanimated#1804) or [here](necolas/react-native-web#1935).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Platform: Web This issue is specific to web 🏠 Reanimated 2
Projects
None yet
Development

No branches or pull requests

5 participants