fix: Add item zIndex preserving based on the order of items#534
fix: Add item zIndex preserving based on the order of items#534
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a z-index issue for sortable items by implementing order-based z-index calculation. Previously, z-index was only adjusted for active and previously active items, which caused incorrect overlapping when items had overlapping visual elements (like the red squares in the example). The new implementation assigns z-index values based on item positions to preserve proper visual layering after reordering.
Changes:
- Modified z-index calculation to consider item order from
indexToKeyandkeyToIndexcontext values - Added different z-index tiers for active items, animating items, and static items based on their positions
- Preserved higher z-index for active and previously active items during drag animations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/react-native-sortables/src/providers/shared/hooks/useItemZIndex.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
In the previous implementation, the zIndex was only changed for the active/previously active item. This was fine for most cases apart from these in which the items were implemented in such a way that they were overlapping each other. In this case, after changing the order of items, they were no longer overlapping properly (see recording in the section below).
This PR sets
zIndexbased on the relative order of items so that the overlapping is preserved after the items are reordered.Changes showcase
You can see that in the Before recording the previously active item stays above remaining ones (look at the red squares)
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-01-13.at.19.03.39.mp4
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-01-13.at.19.03.06.mp4
Example source code