Commit fb0be4e
authored
fix: Add item zIndex preserving based on the order of items (#534)
## 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 `zIndex` based 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)
| Before | After |
|-|-|
| <video
src="https://github.com/user-attachments/assets/dd1749d3-99be-48b1-8d1a-eeffcea199e1"
/> | <video
src="https://github.com/user-attachments/assets/6f1d8a6b-c74d-44c3-9a49-3c66c74bfa98"
/> |
<details>
<summary>Example source code</summary>
```tsx
import { useCallback } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import type { SortableGridRenderItem } from 'react-native-sortables';
import Sortable from 'react-native-sortables';
import { ScrollScreen } from '@/components';
import { colors, radius, sizes, spacing, text } from '@/theme';
const DATA = Array.from({ length: 5 }, (_, index) => `Item ${index + 1}`);
export default function PlaygroundExample() {
const renderItem = useCallback<SortableGridRenderItem<string>>(
({ item }) => (
<View style={styles.card}>
<Text style={styles.text}>{item}</Text>
<View
style={{
backgroundColor: 'red',
height: 40,
position: 'absolute',
right: -20,
top: -20,
width: 40
}}
/>
</View>
),
[]
);
return (
<ScrollScreen contentContainerStyle={styles.container} includeNavBarHeight>
<Sortable.Grid
columnGap={10}
columns={3}
data={DATA}
renderItem={renderItem}
rowGap={10}
/>
</ScrollScreen>
);
}
const styles = StyleSheet.create({
card: {
alignItems: 'center',
backgroundColor: '#36877F',
borderRadius: radius.md,
height: sizes.xl,
justifyContent: 'center'
},
container: {
padding: spacing.md
},
text: {
...text.label2,
color: colors.white
}
});
```
</details>1 parent ecc4512 commit fb0be4e
File tree
1 file changed
+15
-7
lines changed1 file changed
+15
-7
lines changedLines changed: 15 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
21 | 28 | | |
22 | | - | |
| 29 | + | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
0 commit comments