fix: use a new hook to combine the refs in Popup rather than overriding the passed ref #2292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was a fun one to debug 😄
I eventually noticed that the passed
popupRef
always had a current value ofnull
, so it wasn't being set even though thePopup
component seemed to correctly useReact.forwardRef
. Later, I noticed that theuseSwipeToDismissProps
also have aref
prop. That was overriding the initialref={ref}
because we were spreading all of theuseSwipeToDismissProps
including the newref
.I could have simply moved the
ref={ref}
line below{...(isTouch ? useSwipeToDismissProps : null)}
, but then we would be overriding/losing theref
fromuseSwipeToDismissProps
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. InPopup
, we now use that hook to combine the passedref
withuseSwipeToDismissProps.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