Skip to content

Commit f13358a

Browse files
committed
Finish handle example
1 parent c2d0afe commit f13358a

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
1-
# TODO
1+
---
2+
sidebar_position: 6
3+
description: ''
4+
---
5+
6+
# Custom Handle
7+
8+
## Description
9+
10+
The **Custom Handle** example demonstrates how to use a custom item drag handle.
11+
12+
## Usage
13+
14+
### Source Code
15+
16+
```tsx
17+
import { faGripVertical } from '@fortawesome/free-solid-svg-icons';
18+
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
19+
import { useCallback } from 'react';
20+
import { StyleSheet, Text, View } from 'react-native';
21+
import type { SortableGridRenderItem } from 'react-native-sortables';
22+
import Sortable from 'react-native-sortables';
23+
24+
import { ScrollScreen } from '@/components';
25+
26+
const DATA = Array.from({ length: 8 }, (_, index) => `Item ${index + 1}`);
27+
28+
export default function PlaygroundExample() {
29+
const renderItem = useCallback<SortableGridRenderItem<string>>(
30+
({ item }) => (
31+
<View style={styles.card}>
32+
<Text style={styles.text}>{item}</Text>
33+
{/* Wraps the handle component (an icon in this case) */}
34+
<Sortable.Handle>
35+
<FontAwesomeIcon color='white' icon={faGripVertical} />
36+
</Sortable.Handle>
37+
</View>
38+
),
39+
[]
40+
);
41+
42+
return (
43+
<ScrollScreen contentContainerStyle={styles.container} includeNavBarHeight>
44+
<Sortable.Grid
45+
activeItemScale={1.05}
46+
columns={1}
47+
data={DATA}
48+
overDrag='vertical'
49+
renderItem={renderItem}
50+
rowGap={10}
51+
customHandle // must be set to use a custom handle
52+
/>
53+
</ScrollScreen>
54+
);
55+
}
56+
57+
const styles = StyleSheet.create({
58+
card: {
59+
alignItems: 'center',
60+
backgroundColor: '#36877F',
61+
borderRadius: 12,
62+
flexDirection: 'row',
63+
justifyContent: 'center',
64+
padding: 24
65+
},
66+
container: {
67+
padding: 16
68+
},
69+
text: {
70+
color: 'white',
71+
flex: 1,
72+
fontWeight: 'bold'
73+
}
74+
});
75+
```
76+
77+
## Result
78+
79+
import handleVideo from '@site/static/video/grid-custom-handle.mp4';
80+
81+
<video autoPlay loop muted width='300px' src={handleVideo} />

packages/docs/docs/helper-components/handle.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ import Sortable from 'react-native-sortables';
3131
// ... other components
3232
```
3333

34+
:::important
35+
36+
To use a custom handle component, you **must** set the `customHandle` prop on the sortable component.
37+
38+
:::
39+
3440
## Props
3541

3642
### mode
833 KB
Binary file not shown.

0 commit comments

Comments
 (0)