Skip to content

Commit 24ee167

Browse files
authored
docs: Add different grid item heights support example (#205)
## Description This PR adds different grid items heights support example to docs showing that sortable components can handle layout where components have different heights.
1 parent e2012ac commit 24ee167

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
sidebar_position: 4
3+
description: ''
4+
---
5+
6+
# Different Item Heights
7+
8+
## Description
9+
10+
This example shows that the **Sortable Grid** component can handle **different item heights** without any issues.
11+
12+
Similar to the **Sortable Grid** component, the **Sortable Flex** component can also handle **different item heights**.
13+
14+
## Source Code
15+
16+
```tsx
17+
import { useCallback } from 'react';
18+
import { StyleSheet, Text, View } from 'react-native';
19+
import type { SortableGridRenderItem } from 'react-native-sortable';
20+
import Sortable from 'react-native-sortable';
21+
22+
const DATA = Array.from({ length: 12 }, (_, index) => `Item ${index + 1}`);
23+
24+
export default function Example() {
25+
const renderItem = useCallback<SortableGridRenderItem<string>>(
26+
({ item }) => (
27+
<View
28+
style={[
29+
styles.card,
30+
{ height: Math.random() * 150 + 50 } // random height for demo purposes
31+
]}>
32+
<Text style={styles.text}>{item}</Text>
33+
</View>
34+
),
35+
[]
36+
);
37+
38+
return (
39+
<View style={styles.container}>
40+
<Sortable.Grid
41+
columnGap={10}
42+
columns={3}
43+
data={DATA}
44+
renderItem={renderItem}
45+
rowGap={10}
46+
/>
47+
</View>
48+
);
49+
}
50+
51+
const styles = StyleSheet.create({
52+
card: {
53+
alignItems: 'center',
54+
backgroundColor: '#36877F',
55+
borderRadius: 10,
56+
height: 100,
57+
justifyContent: 'center'
58+
},
59+
container: {
60+
padding: 10
61+
},
62+
text: {
63+
color: 'white',
64+
fontWeight: 'bold'
65+
}
66+
});
67+
```
68+
69+
## Result
70+
71+
import defaultVideo from '@site/static/video/grid-different-item-heights.mp4';
72+
73+
<video autoPlay loop muted width='300px' src={defaultVideo} />

packages/docs/docs/grid/examples/touchables.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 5
33
description: ''
44
---
55

2.41 MB
Binary file not shown.

0 commit comments

Comments
 (0)