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

[ReanimatedSwipeable] Multiple bug fixes and improvements #3149

Merged
merged 18 commits into from
Oct 17, 2024

Conversation

latekvo
Copy link
Contributor

@latekvo latekvo commented Oct 11, 2024

Description

This PR applies multiple bug fixes and improvements to the ReanimatedSwipeable

Changes:

  • Fix reversed swipe direction being supplied to open and willOpen callbacks.
  • Fix startDrag callbacks receiving invalid direction when opening swipeable.
  • Fix unpredictable swipe direction being supplied to close and willClose callbacks.
  • Fix onSwipeableWillClose and onSwipeableClose callbacks sometimes being called on open.
  • Fix progress value skipping last 10% of it's range and having a delay relative to the translation.
    closes ReanimatedSwipable Delayed #3147

Test plan

Will create an example showcasing outputs of all the affected callbacks, work in progress.

@latekvo latekvo requested a review from m-bert October 11, 2024 13:35
@m-bert
Copy link
Contributor

m-bert commented Oct 11, 2024

This PR applies multiple bug fixes and improvements to the ReanimatedSwipeable

Is it necessary to fix all of them in just 1 PR? I'd prefer to split it into smaller ones if possible.

@latekvo
Copy link
Contributor Author

latekvo commented Oct 11, 2024

Is it necessary to fix all of them in just 1 PR? I'd prefer to split it into smaller ones if possible.

Most of them are very minor, most also depend on each other / are fixes to the same part of ReanimatedSwipeable.

I can split them up if you'd prefer that but i think it'd significantly complicate the process, i'll definitely have to deal with conflicts, and PRs blocking eachother.

latekvo added a commit that referenced this pull request Oct 14, 2024
## Description

Add missing documentation for `onSwipeableOpenStartDrag` and
`onSwipeableOpenStartDrag` callbacks of `ReanimatedSwipeable`

Moved from #3149
@latekvo latekvo marked this pull request as ready for review October 14, 2024 09:37
latekvo added a commit that referenced this pull request Oct 14, 2024
…pdate (#3151)

## Description

Fix `onStart` callbacks of `ReanimatedSwipeable` being called every
update.

Moved from #3149

## Test plan

- open `Swipeable Reanimation` example
- replace the `ReanimatedSwipeable` component with the following code:
```js
<ReanimatedSwipeable
  containerStyle={styles.swipeable}
  onSwipeableOpenStartDrag={(direction) => console.log(direction)}
  onSwipeableCloseStartDrag={(direction) => console.log(direction)}>
  <Text>Swipeable!</Text>
</ReanimatedSwipeable>
```
- see how only one update is sent to the console, while before this PR
new updates were constantly generated
appliedTranslation.value = withSpring(
toValue,
translationSpringConfig,
(isFinished) => {
if (isFinished) {
runOnJS(dispatchEndEvents)(fromValue, toValue);
runOnJS(dispatchEndEvents)(frozenRowState, toValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all events executed on the JS thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all of them are, couldn't find any that aren't

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can update the calling logic to check whether the callback is a worklet and run it on the UI thread if it is (that's for another PR though).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, will do that.

Copy link
Contributor

@m-bert m-bert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it could be split into smaller PRs (like switching to enum instead of string), but I won't block it. Please wait for @j-piasecki final opinion on this

Comment on lines 208 to 212
enum SwipeDirection {
LEFT = 'left',
RIGHT = 'right',
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this declaration at the top of the file (somewhere around SwipeableExcludes type). I know it is JS and it works, but I think it's a good practice. Also if you read code from the top you know what SwipeDirection is (at first I thought it was a number, then I saw the declaration)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in a329a6d

Copy link
Member

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this, the changes are not necessarily related but the PR isn't that big. In the future though, please try to open separate PRs for unrelated changes (like extracting direction to enum).

Please address #3149 (comment) first.

@latekvo latekvo requested a review from m-bert October 17, 2024 10:27
@latekvo latekvo merged commit 8351e4b into main Oct 17, 2024
1 check passed
@latekvo latekvo deleted the @latekvo/fix-reanimated-swipeable-animation-delay branch October 17, 2024 10:37
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.

ReanimatedSwipable Delayed
3 participants