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: use a new hook to combine the refs in Popup rather than overriding the passed ref #2292

Merged

Conversation

trevinhofmann
Copy link
Collaborator

This was a fun one to debug 😄

I eventually noticed that the passed popupRef always had a current value of null, so it wasn't being set even though the Popup component seemed to correctly use React.forwardRef. Later, I noticed that the useSwipeToDismissProps also have a ref prop. That was overriding the initial ref={ref} because we were spreading all of the useSwipeToDismissProps including the new ref.

I could have simply moved the ref={ref} line below {...(isTouch ? useSwipeToDismissProps : null)}, but then we would be overriding/losing the ref from useSwipeToDismissProps which is almost certainly not desirable either.

To solve this, I created a new hook called useCombinedRefs which lets us create a new ref combining multiple other refs. In Popup, we now use that hook to combine the passed ref with useSwipeToDismissProps.ref.

Now, with the ref being set, the CSS animation styles are being correctly applied to the popup in the gesture menu.

This fixes #2059.

Demo:

Screen.Recording.2024-08-16.at.3.35.18.PM.mov

Copy link
Contributor

@raineorshine raineorshine left a comment

Choose a reason for hiding this comment

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

Interesting! Tricky indeed. I'll have to remember to watch out for spreading props.

@raineorshine raineorshine merged commit aab54a0 into cybersemics:main Aug 19, 2024
3 checks passed
@trevinhofmann
Copy link
Collaborator Author

Interesting! Tricky indeed. I'll have to remember to watch out for spreading props.

FWIW, I don't even allow spreading JSX props in my own ESLint config: https://github.com/trevinhofmann/eslint-config-principled/blob/08b1601df2a7f7d4db734aec708d410685389602/src/components/react/best-practices.ts#L71-L74

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.

[mobile] Alert snaps in/out instead of fading
2 participants