Skip to content

Commit 1601090

Browse files
authored
docs: Add updates from the recent release (#386)
## Description This PR adds docs updates from the recent release of the library.
1 parent 85c85b0 commit 1601090

9 files changed

Lines changed: 308 additions & 163 deletions

File tree

packages/docs/docs/flex/props.mdx

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -766,34 +766,33 @@ type DragStartCallback = (params: DragStartParams) => void;
766766
type DragStartParams = {
767767
key: string;
768768
fromIndex: number;
769+
indexToKey: Array<string>;
770+
keyToIndex: Record<string, number>;
769771
};
770772
```
771773

772774
</details>
773775

774776
---
775777

776-
### onDragEnd
778+
### onDragMove
777779

778-
Called when the drag gesture ends. Data passed to the callback is the new order of the items.
780+
Called when the drag gesture moves.
779781

780-
| type | default | required |
781-
| ----------------------------- | ------- | -------- |
782-
| `SortableFlexDragEndCallback` | NO | NO |
782+
| type | default | required |
783+
| ------------------ | ------- | -------- |
784+
| `DragMoveCallback` | NO | NO |
783785

784786
<details>
785787
<summary>Type definitions</summary>
786788

787789
```tsx
788-
type SortableFlexDragEndCallback = (params: SortableFlexDragEndParams) => void;
790+
type DragMoveCallback = (params: DragMoveParams) => void;
789791

790-
type SortableFlexDragEndParams = {
792+
type DragMoveParams = {
791793
key: string;
792794
fromIndex: number;
793-
toIndex: number;
794-
indexToKey: Array<string>;
795-
keyToIndex: Record<string, number>;
796-
order: <I>(data: Array<I>) => Array<I>; // returns new array with items in the new order
795+
touchData: TouchData;
797796
};
798797
```
799798

@@ -834,24 +833,54 @@ type OrderChangeParams = {
834833

835834
---
836835

837-
### onDragMove
836+
### onDragEnd
838837

839-
Called when the drag gesture moves.
838+
Called when the drag gesture ends. Data passed to the callback is the new order of the items.
840839

841-
| type | default | required |
842-
| ------------------ | ------- | -------- |
843-
| `DragMoveCallback` | NO | NO |
840+
| type | default | required |
841+
| ----------------------------- | ------- | -------- |
842+
| `SortableFlexDragEndCallback` | NO | NO |
844843

845844
<details>
846845
<summary>Type definitions</summary>
847846

848847
```tsx
849-
type DragMoveCallback = (params: DragMoveParams) => void;
848+
type SortableFlexDragEndCallback = (params: SortableFlexDragEndParams) => void;
850849

851-
type DragMoveParams = {
850+
type SortableFlexDragEndParams = {
852851
key: string;
853852
fromIndex: number;
854-
touchData: TouchData;
853+
toIndex: number;
854+
indexToKey: Array<string>;
855+
keyToIndex: Record<string, number>;
856+
order: <I>(data: Array<I>) => Array<I>; // returns new array with items in the new order
857+
};
858+
```
859+
860+
</details>
861+
862+
---
863+
864+
### onActiveItemDropped
865+
866+
Called when the active item is dropped (the animation to the target item position is completed).
867+
868+
| type | default | required |
869+
| --------------------------- | ------- | -------- |
870+
| `ActiveItemDroppedCallback` | NO | NO |
871+
872+
<details>
873+
<summary>Type definitions</summary>
874+
875+
```tsx
876+
type ActiveItemDroppedCallback = (params: ActiveItemDroppedParams) => void;
877+
878+
type ActiveItemDroppedParams = {
879+
key: string;
880+
fromIndex: number;
881+
toIndex: number;
882+
indexToKey: Array<string>;
883+
keyToIndex: Record<string, number>;
855884
};
856885
```
857886

packages/docs/docs/grid/examples/touchables.mdx renamed to packages/docs/docs/grid/examples/touchable.mdx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@ sidebar_position: 5
33
description: ''
44
---
55

6-
# Touchables
6+
# Touchable
77

88
## Description
99

10-
This example shows why touchable components exported from this library are useful whe you need to **properly detect press events** on **components nested inside** the sortable component item.
11-
12-
:::info
13-
14-
The **usage is the same** for **all touchable components exported from this library**. To see more information about other touchable components, please **refer to the [Touchables](/helper-components/touchables) page**.
15-
16-
:::
10+
This example shows why the [Sortable.Touchable](/helper-components/touchable) component is useful when you need to **properly detect press events** on **components nested inside** the sortable component item (more precisely, nested within the part of the item that detects the drag gesture - this might be the entire item or just a part of it if the custom handle, like [Sortable.Handle](/helper-components/handle), is used).
1711

1812
## Source Code
1913

2014
```tsx
2115
import { useCallback, useState } from 'react';
22-
import { Text, View, StyleSheet } from 'react-native';
16+
import { StyleSheet, Text, View } from 'react-native';
2317
import type { SortableGridRenderItem } from 'react-native-sortables';
2418
import Sortable from 'react-native-sortables';
2519

@@ -32,11 +26,11 @@ export default function Example() {
3226
({ item }) => (
3327
<View style={styles.card}>
3428
<Text style={styles.text}>{item}</Text>
35-
<Sortable.Pressable
29+
<Sortable.Touchable
3630
style={styles.deleteButton}
37-
onPress={() => setData(prev => prev.filter(i => i !== item))}>
31+
onTap={() => setData(prev => prev.filter(i => i !== item))}>
3832
<Text style={styles.text}>Delete</Text>
39-
</Sortable.Pressable>
33+
</Sortable.Touchable>
4034
</View>
4135
),
4236
[]
@@ -45,36 +39,36 @@ export default function Example() {
4539
return (
4640
<View style={styles.container}>
4741
<Sortable.Grid
42+
columnGap={10}
4843
columns={2}
4944
data={data}
5045
renderItem={renderItem}
5146
rowGap={10}
52-
columnGap={10}
5347
/>
5448
</View>
5549
);
5650
}
5751

5852
const styles = StyleSheet.create({
59-
container: {
60-
padding: 10
61-
},
6253
card: {
54+
alignItems: 'center',
6355
backgroundColor: '#36877F',
56+
borderRadius: 10,
57+
gap: 10,
6458
height: 100,
59+
justifyContent: 'center'
60+
},
61+
container: {
62+
padding: 10
63+
},
64+
deleteButton: {
65+
backgroundColor: '#6AA67C',
6566
borderRadius: 10,
66-
alignItems: 'center',
67-
justifyContent: 'center',
68-
gap: 10
67+
padding: 10
6968
},
7069
text: {
7170
color: 'white',
7271
fontWeight: 'bold'
73-
},
74-
deleteButton: {
75-
backgroundColor: '#6AA67C',
76-
padding: 10,
77-
borderRadius: 10
7872
}
7973
});
8074
```
@@ -83,11 +77,11 @@ const styles = StyleSheet.create({
8377

8478
You can see that the `Pressable` component from React Native **still detects the press event even when the item started being dragged**, which is not the desired behavior.
8579

86-
On the contrary, the `Sortable.Pressable` component from this library **properly handles the press event** and grid items are removed only when the **Delete** button is **pressed, not when the item is dragged**.
80+
On the contrary, the `Sortable.Touchable` component from this library **properly handles the press event** and grid items are removed only when the **Delete** button is **pressed, not when the item is dragged**.
8781

8882
import correctVideo from '@site/static/video/grid-touchables-correct.mp4';
8983
import incorrectVideo from '@site/static/video/grid-touchables-incorrect.mp4';
9084

91-
| React Native's `Pressable` | `Sortable.Pressable` |
85+
| React Native's `Pressable` | `Sortable.Touchable` |
9286
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
9387
| <video autoPlay loop muted width="100%" style={{ maxWidth: '300px' }} src={incorrectVideo} /> | <video autoPlay loop muted width="100%" style={{ maxWidth: '300px' }} src={correctVideo} /> |

packages/docs/docs/grid/props.mdx

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -648,36 +648,33 @@ type DragStartCallback = (params: DragStartParams) => void;
648648
type DragStartParams = {
649649
key: string;
650650
fromIndex: number;
651+
indexToKey: Array<string>;
652+
keyToIndex: Record<string, number>;
651653
};
652654
```
653655

654656
</details>
655657

656658
---
657659

658-
### onDragEnd
660+
### onDragMove
659661

660-
Called when the drag gesture ends. Data passed to the callback is sorted according to the new order of the items. If the order of items is not changed, the same data array as the one passed to the `data` prop of the grid is passed in the callback params.
662+
Called when the drag gesture moves.
661663

662-
| type | default | required |
663-
| -------------------------------- | ------- | -------- |
664-
| `SortableGridDragEndCallback<T>` | NO | NO |
664+
| type | default | required |
665+
| ------------------ | ------- | -------- |
666+
| `DragMoveCallback` | NO | NO |
665667

666668
<details>
667669
<summary>Type definitions</summary>
668670

669671
```tsx
670-
type SortableGridDragEndCallback<T> = (
671-
params: SortableGridDragEndParams<T>
672-
) => void;
672+
type DragMoveCallback = (params: DragMoveParams) => void;
673673

674-
type SortableGridDragEndParams<T> = {
674+
type DragMoveParams = {
675675
key: string;
676676
fromIndex: number;
677-
toIndex: number;
678-
indexToKey: Array<string>;
679-
keyToIndex: Record<string, number>;
680-
data: Array<T>;
677+
touchData: TouchData;
681678
};
682679
```
683680

@@ -718,24 +715,56 @@ type OrderChangeParams = {
718715

719716
---
720717

721-
### onDragMove
718+
### onDragEnd
722719

723-
Called when the drag gesture moves.
720+
Called when the drag gesture ends. Data passed to the callback is sorted according to the new order of the items. If the order of items is not changed, the same data array as the one passed to the `data` prop of the grid is passed in the callback params.
724721

725-
| type | default | required |
726-
| ------------------ | ------- | -------- |
727-
| `DragMoveCallback` | NO | NO |
722+
| type | default | required |
723+
| -------------------------------- | ------- | -------- |
724+
| `SortableGridDragEndCallback<T>` | NO | NO |
728725

729726
<details>
730727
<summary>Type definitions</summary>
731728

732729
```tsx
733-
type DragMoveCallback = (params: DragMoveParams) => void;
730+
type SortableGridDragEndCallback<T> = (
731+
params: SortableGridDragEndParams<T>
732+
) => void;
734733

735-
type DragMoveParams = {
734+
type SortableGridDragEndParams<T> = {
736735
key: string;
737736
fromIndex: number;
738-
touchData: TouchData;
737+
toIndex: number;
738+
indexToKey: Array<string>;
739+
keyToIndex: Record<string, number>;
740+
data: Array<T>;
741+
};
742+
```
743+
744+
</details>
745+
746+
---
747+
748+
### onActiveItemDropped
749+
750+
Called when the active item is dropped (the animation to the target item position is completed).
751+
752+
| type | default | required |
753+
| --------------------------- | ------- | -------- |
754+
| `ActiveItemDroppedCallback` | NO | NO |
755+
756+
<details>
757+
<summary>Type definitions</summary>
758+
759+
```tsx
760+
type ActiveItemDroppedCallback = (params: ActiveItemDroppedParams) => void;
761+
762+
type ActiveItemDroppedParams = {
763+
key: string;
764+
fromIndex: number;
765+
toIndex: number;
766+
indexToKey: Array<string>;
767+
keyToIndex: Record<string, number>;
739768
};
740769
```
741770

0 commit comments

Comments
 (0)