Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "withDecay clamps position to the wrong boundary" (software-mansi…
…on#4591) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary <!-- Explain the motivation for this PR. Include "Fixes #<number>" if applicable. --> Closes software-mansion#4508 ### Bug description <table> <tr><th>BEFORE</th><th>AFTER</th></tr> <tr><td width="50%">Animation looks good if and only if the animated square has no positive velocity (velocity towards center of screen). In other case it moves much too fast and clamp to the opposite position with no bounces</td><td>If square has some positive velocity it moves visibly faster. Square always bounces when approaching clamp limit (with rubber band effect on).</td></tr> <tr><td> https://github.com/software-mansion/react-native-reanimated/assets/56199675/3035ad50-b108-49f0-8714-791c4ae706fe </td><td> https://github.com/software-mansion/react-native-reanimated/assets/56199675/d6cb43d5-3e9c-4ee5-aee2-a5a2bb4394b3 </td></tr> </table> ### Description of code change I've removed a condition updating the derivative only when square is within predefined boundaries - since we want to keep its springified movement even if it is overshooting. Especially that we used to end animation almost immediately after exceeding limits. Since after this change the `derivative` is always modified we should no longer compare it to zero, but use some epsilon instead. ## Test plan I've tested it on this example: https://github.com/MatiPl01/reanimated-issues, linked in the issue. <!-- Provide a minimal but complete code snippet that can be used to test out this change along with instructions how to run it and a description of the expected behavior. --> --------- Co-authored-by: Aleksandra Cynk <aleksandracynk@swmansion.com>
- Loading branch information