@btfash/react-native-reanimated-dnd 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
1
  import React from "react";
2
- import { SortableProps } from "../types/sortable";
3
- export declare const Sortable: React.MemoExoticComponent<({ data, renderItem, ...props }: SortableProps<any>) => React.JSX.Element>;
2
+ import { SortableProps, UniqueIdentifier } from "../types/sortable";
3
+ declare function SortableComponent<TData extends {
4
+ id: TID;
5
+ }, TID extends UniqueIdentifier = string>({ data, renderItem, direction, itemHeight, itemWidth, gap, paddingHorizontal, style, contentContainerStyle, itemKeyExtractor, useFlatList, }: SortableProps<TData, TID>): React.JSX.Element;
6
+ export declare const Sortable: typeof SortableComponent;
7
+ export {};
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
- import { SortableItemProps, SortableHandleProps } from "../types/sortable";
3
- export declare function SortableItem<T>({ id, data, positions, direction, lowerBound, leftBound, autoScrollDirection, autoScrollHorizontalDirection, itemsCount, itemHeight, itemWidth, gap, paddingHorizontal, containerHeight, containerWidth, children, style, animatedStyle: customAnimatedStyle, onMove, onDragStart, onDrop, onDragging, onDraggingHorizontal, }: SortableItemProps<T>): React.JSX.Element;
2
+ import { SortableItemProps, SortableHandleProps, UniqueIdentifier } from "../types/sortable";
3
+ export declare function SortableItem<T, TID extends UniqueIdentifier>({ id, data, positions, direction, lowerBound, leftBound, autoScrollDirection, autoScrollHorizontalDirection, itemsCount, itemHeight, itemWidth, gap, paddingHorizontal, containerHeight, containerWidth, children, style, animatedStyle: customAnimatedStyle, onMove, onDragStart, onDrop, onDragging, onDraggingHorizontal, }: SortableItemProps<T, TID>): React.JSX.Element;
4
4
  export declare namespace SortableItem {
5
5
  var Handle: ({ children, style }: SortableHandleProps) => React.JSX.Element;
6
6
  }
@@ -1,4 +1,5 @@
1
1
  import { SharedValue } from "react-native-reanimated";
2
+ import { UniqueIdentifier } from "../types";
2
3
  export declare enum ScrollDirection {
3
4
  None = "none",
4
5
  Up = "up",
@@ -10,24 +11,14 @@ export declare enum HorizontalScrollDirection {
10
11
  Right = "right"
11
12
  }
12
13
  export declare function clamp(value: number, lowerBound: number, upperBound: number): number;
13
- export declare function objectMove(object: {
14
- [id: string]: number;
15
- }, from: number, to: number): {
16
- [id: string]: number;
17
- };
14
+ export declare function objectMove<TID extends UniqueIdentifier>(object: Record<TID, number>, from: number, to: number): Record<TID, number>;
18
15
  export declare function listToObject<T extends {
19
- id: string;
20
- }>(list: T[]): {
21
- [id: string]: number;
22
- };
23
- export declare function setPosition(positionY: number, itemsCount: number, positions: SharedValue<{
24
- [id: string]: number;
25
- }>, id: string, itemHeight: number): void;
16
+ id: TID;
17
+ }, TID extends UniqueIdentifier>(list: T[]): Record<TID, number>;
18
+ export declare function setPosition<TID extends UniqueIdentifier>(positionY: number, itemsCount: number, positions: SharedValue<Record<TID, number>>, id: TID, itemHeight: number): void;
26
19
  export declare function setAutoScroll(positionY: number, lowerBound: number, upperBound: number, scrollThreshold: number, autoScroll: SharedValue<ScrollDirection>): void;
27
20
  export declare function getItemXPosition(position: number, itemWidth: number, gap?: number, paddingHorizontal?: number): number;
28
21
  export declare function getContentWidth(itemsCount: number, itemWidth: number, gap?: number, paddingHorizontal?: number): number;
29
- export declare function setHorizontalPosition(positionX: number, itemsCount: number, positions: SharedValue<{
30
- [id: string]: number;
31
- }>, id: string, itemWidth: number, gap?: number, paddingHorizontal?: number): void;
22
+ export declare function setHorizontalPosition<TID extends UniqueIdentifier>(positionX: number, itemsCount: number, positions: SharedValue<Record<TID, number>>, id: TID, itemWidth: number, gap?: number, paddingHorizontal?: number): void;
32
23
  export declare function setHorizontalAutoScroll(positionX: number, leftBound: number, rightBound: number, scrollThreshold: number, autoScrollDirection: SharedValue<HorizontalScrollDirection>): void;
33
24
  export declare const dataHash: (data: any[]) => string;
@@ -1,2 +1,3 @@
1
1
  import { UseDroppableOptions, UseDroppableReturn } from "../types/droppable";
2
- export declare const useDroppable: <TData = unknown>(options: UseDroppableOptions<TData>) => UseDroppableReturn;
2
+ import { UniqueIdentifier } from "../types";
3
+ export declare const useDroppable: <TData = unknown, TID extends UniqueIdentifier = string>(options: UseDroppableOptions<TData, TID>) => UseDroppableReturn;
@@ -1,2 +1,2 @@
1
- import { UseHorizontalSortableOptions, UseHorizontalSortableReturn } from "../types/sortable";
2
- export declare function useHorizontalSortable<T>(options: UseHorizontalSortableOptions<T>): UseHorizontalSortableReturn;
1
+ import { UniqueIdentifier, UseHorizontalSortableOptions, UseHorizontalSortableReturn } from "../types/sortable";
2
+ export declare function useHorizontalSortable<T, TID extends UniqueIdentifier>(options: UseHorizontalSortableOptions<T, TID>): UseHorizontalSortableReturn;
@@ -1,4 +1,5 @@
1
+ import { UniqueIdentifier } from "../types/sortable";
1
2
  import { UseHorizontalSortableListOptions, UseHorizontalSortableListReturn } from "../types/sortable";
2
3
  export declare function useHorizontalSortableList<TData extends {
3
- id: string;
4
- }>(options: UseHorizontalSortableListOptions<TData>): UseHorizontalSortableListReturn<TData>;
4
+ id: TID;
5
+ }, TID extends UniqueIdentifier = string>(options: UseHorizontalSortableListOptions<TData, TID>): UseHorizontalSortableListReturn<TData, TID>;
@@ -2,42 +2,41 @@ import { StyleProp, ViewStyle } from "react-native";
2
2
  import React from "react";
3
3
  import { SharedValue } from "react-native-reanimated";
4
4
  import { GestureType } from "react-native-gesture-handler";
5
+ import { UniqueIdentifier } from "../types";
5
6
  export declare enum ScrollDirection {
6
7
  None = "none",
7
8
  Up = "up",
8
9
  Down = "down"
9
10
  }
10
11
  export declare function clamp(value: number, lowerBound: number, upperBound: number): number;
11
- export declare function objectMove(object: {
12
- [id: string]: number;
13
- }, from: number, to: number): {
14
- [id: string]: number;
15
- };
12
+ export declare function objectMove<TID extends UniqueIdentifier>(object: {
13
+ [id in TID]: number;
14
+ }, from: number, to: number): { [id in TID]: number; };
16
15
  export declare function listToObject<T extends {
17
16
  id: string;
18
17
  }>(list: T[]): {
19
18
  [id: string]: number;
20
19
  };
21
- export declare function setPosition(positionY: number, itemsCount: number, positions: SharedValue<{
22
- [id: string]: number;
23
- }>, id: string, itemHeight: number): void;
20
+ export declare function setPosition<TID extends UniqueIdentifier>(positionY: number, itemsCount: number, positions: SharedValue<{
21
+ [id in TID]: number;
22
+ }>, id: TID, itemHeight: number): void;
24
23
  export declare function setAutoScroll(positionY: number, lowerBound: number, upperBound: number, scrollThreshold: number, autoScroll: SharedValue<ScrollDirection>): void;
25
- export interface UseSortableOptions<T> {
26
- id: string;
24
+ export interface UseSortableOptions<T, TID extends UniqueIdentifier> {
25
+ id: TID;
27
26
  positions: SharedValue<{
28
- [id: string]: number;
27
+ [id in TID]: number;
29
28
  }>;
30
29
  lowerBound: SharedValue<number>;
31
30
  autoScrollDirection: SharedValue<ScrollDirection>;
32
31
  itemsCount: number;
33
32
  itemHeight: number;
34
33
  containerHeight?: number;
35
- onMove?: (id: string, from: number, to: number) => void;
36
- onDragStart?: (id: string, position: number) => void;
37
- onDrop?: (id: string, position: number, allPositions?: {
38
- [id: string]: number;
34
+ onMove?: (id: TID, from: number, to: number) => void;
35
+ onDragStart?: (id: TID, position: number) => void;
36
+ onDrop?: (id: TID, position: number, allPositions?: {
37
+ [id in TID]: number;
39
38
  }) => void;
40
- onDragging?: (id: string, overItemId: string | null, yPosition: number) => void;
39
+ onDragging?: (id: TID, overItemId: TID | null, yPosition: number) => void;
41
40
  children?: React.ReactNode;
42
41
  handleComponent?: React.ComponentType<any>;
43
42
  }
@@ -47,4 +46,4 @@ export interface UseSortableReturn {
47
46
  isMoving: boolean;
48
47
  hasHandle: boolean;
49
48
  }
50
- export declare function useSortable<T>(options: UseSortableOptions<T>): UseSortableReturn;
49
+ export declare function useSortable<T, TID extends UniqueIdentifier>(options: UseSortableOptions<T, TID>): UseSortableReturn;
@@ -1,10 +1,11 @@
1
+ import { UniqueIdentifier } from "../types/sortable";
1
2
  import { DropProviderRef } from "../types/context";
2
- export interface UseSortableListOptions<TData> {
3
+ export interface UseSortableListOptions<TData, TID extends UniqueIdentifier = string> {
3
4
  data: TData[];
4
5
  itemHeight: number;
5
- itemKeyExtractor?: (item: TData, index: number) => string;
6
+ itemKeyExtractor?: (item: TData, index: number) => TID;
6
7
  }
7
- export interface UseSortableListReturn<TData> {
8
+ export interface UseSortableListReturn<TData, TID extends UniqueIdentifier> {
8
9
  positions: any;
9
10
  scrollY: any;
10
11
  autoScroll: any;
@@ -14,7 +15,7 @@ export interface UseSortableListReturn<TData> {
14
15
  handleScrollEnd: () => void;
15
16
  contentHeight: number;
16
17
  getItemProps: (item: TData, index: number) => {
17
- id: string;
18
+ id: TID;
18
19
  positions: any;
19
20
  lowerBound: any;
20
21
  autoScrollDirection: any;
@@ -23,5 +24,5 @@ export interface UseSortableListReturn<TData> {
23
24
  };
24
25
  }
25
26
  export declare function useSortableList<TData extends {
26
- id: string;
27
- }>(options: UseSortableListOptions<TData>): UseSortableListReturn<TData>;
27
+ id: TID;
28
+ }, TID extends UniqueIdentifier = string>(options: UseSortableListOptions<TData, TID>): UseSortableListReturn<TData, TID>;
@@ -1,17 +1,18 @@
1
1
  import { ReactNode } from "react";
2
+ import { UniqueIdentifier } from "./sortable";
2
3
  export type DropAlignment = "center" | "top-left" | "top-center" | "top-right" | "center-left" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right";
3
4
  export interface DropOffset {
4
5
  x: number;
5
6
  y: number;
6
7
  }
7
- export interface DroppedItemsMap<TData = unknown> {
8
- [draggableId: string]: {
9
- droppableId: string;
8
+ export type DroppedItemsMap<TData = unknown, TID extends UniqueIdentifier = string> = {
9
+ [draggableId in TID]: {
10
+ droppableId: TID;
10
11
  data: TData;
11
12
  };
12
- }
13
- export interface DropSlot<TData = unknown> {
14
- id: string;
13
+ };
14
+ export interface DropSlot<TData = unknown, TID extends UniqueIdentifier = string> {
15
+ id: TID;
15
16
  x: number;
16
17
  y: number;
17
18
  width: number;
@@ -22,20 +23,20 @@ export interface DropSlot<TData = unknown> {
22
23
  capacity?: number;
23
24
  }
24
25
  export type PositionUpdateListener = () => void;
25
- export interface SlotsContextValue<TData = unknown> {
26
- register: (id: number, slot: DropSlot<TData>) => void;
26
+ export interface SlotsContextValue<TData = unknown, TID extends UniqueIdentifier = string> {
27
+ register: (id: number, slot: DropSlot<TData, TID>) => void;
27
28
  unregister: (id: number) => void;
28
- getSlots: () => Record<number, DropSlot<TData>>;
29
+ getSlots: () => Record<number, DropSlot<TData, TID>>;
29
30
  isRegistered: (id: number) => boolean;
30
31
  setActiveHoverSlot: (id: number | null) => void;
31
32
  activeHoverSlotId: number | null;
32
- registerPositionUpdateListener: (id: string, listener: PositionUpdateListener) => void;
33
- unregisterPositionUpdateListener: (id: string) => void;
33
+ registerPositionUpdateListener: (id: TID, listener: PositionUpdateListener) => void;
34
+ unregisterPositionUpdateListener: (id: TID) => void;
34
35
  requestPositionUpdate: () => void;
35
- registerDroppedItem: (draggableId: string, droppableId: string, itemData: any) => void;
36
- unregisterDroppedItem: (draggableId: string) => void;
36
+ registerDroppedItem: (draggableId: TID, droppableId: TID, itemData: any) => void;
37
+ unregisterDroppedItem: (draggableId: TID) => void;
37
38
  getDroppedItems: () => DroppedItemsMap<any>;
38
- hasAvailableCapacity: (droppableId: string) => boolean;
39
+ hasAvailableCapacity: (droppableId: TID) => boolean;
39
40
  onDragging?: (payload: {
40
41
  x: number;
41
42
  y: number;
@@ -46,7 +47,7 @@ export interface SlotsContextValue<TData = unknown> {
46
47
  onDragStart?: (data: any) => void;
47
48
  onDragEnd?: (data: any) => void;
48
49
  }
49
- export declare const SlotsContext: import("react").Context<SlotsContextValue<any>>;
50
+ export declare const SlotsContext: import("react").Context<SlotsContextValue<any, string>>;
50
51
  export interface DropProviderProps {
51
52
  children: ReactNode;
52
53
  onLayoutUpdateComplete?: () => void;
@@ -2,6 +2,7 @@ import { ViewStyle, View, StyleProp } from "react-native";
2
2
  import Animated, { AnimatedStyle, useAnimatedRef } from "react-native-reanimated";
3
3
  import { GestureType } from "react-native-gesture-handler";
4
4
  import { LayoutChangeEvent } from "react-native";
5
+ import { UniqueIdentifier } from "./sortable";
5
6
  export declare enum DraggableState {
6
7
  IDLE = "IDLE",
7
8
  DRAGGING = "DRAGGING",
@@ -9,9 +10,9 @@ export declare enum DraggableState {
9
10
  }
10
11
  export type AnimationFunction = (toValue: number) => number;
11
12
  export type CollisionAlgorithm = "center" | "intersect" | "contain";
12
- export interface UseDraggableOptions<TData = unknown> {
13
+ export interface UseDraggableOptions<TData = unknown, TID extends UniqueIdentifier = string> {
13
14
  data: TData;
14
- draggableId?: string;
15
+ draggableId?: TID;
15
16
  dragDisabled?: boolean;
16
17
  preDragDelay?: number;
17
18
  onDragStart?: (data: TData) => void;
@@ -43,7 +44,7 @@ export interface DraggableContextValue {
43
44
  gesture: any;
44
45
  state: DraggableState;
45
46
  }
46
- export interface DraggableProps<TData = unknown> extends UseDraggableOptions<TData> {
47
+ export interface DraggableProps<TData = unknown, TID extends UniqueIdentifier = string> extends UseDraggableOptions<TData, TID> {
47
48
  style?: StyleProp<ViewStyle>;
48
49
  children: React.ReactNode;
49
50
  onStateChange?: (state: DraggableState) => void;
@@ -1,14 +1,15 @@
1
1
  import { LayoutChangeEvent, StyleProp, ViewStyle } from "react-native";
2
2
  import Animated, { useAnimatedRef } from "react-native-reanimated";
3
3
  import { DropAlignment, DropOffset } from "./context";
4
- export interface UseDroppableOptions<TData = unknown> {
4
+ import { UniqueIdentifier } from "./sortable";
5
+ export interface UseDroppableOptions<TData = unknown, TID extends UniqueIdentifier = string> {
5
6
  onDrop: (data: TData) => void;
6
7
  dropDisabled?: boolean;
7
8
  onActiveChange?: (isActive: boolean) => void;
8
9
  dropAlignment?: DropAlignment;
9
10
  dropOffset?: DropOffset;
10
11
  activeStyle?: StyleProp<ViewStyle>;
11
- droppableId?: string;
12
+ droppableId?: TID;
12
13
  capacity?: number;
13
14
  }
14
15
  export interface UseDroppableReturn {
@@ -20,7 +21,7 @@ export interface UseDroppableReturn {
20
21
  activeStyle?: StyleProp<ViewStyle>;
21
22
  animatedViewRef: ReturnType<typeof useAnimatedRef<Animated.View>>;
22
23
  }
23
- export interface DroppableProps<TData = unknown> extends UseDroppableOptions<TData> {
24
+ export interface DroppableProps<TData = unknown, TID extends UniqueIdentifier = string> extends UseDroppableOptions<TData, TID> {
24
25
  style?: StyleProp<ViewStyle>;
25
26
  children: React.ReactNode;
26
27
  }
@@ -2,8 +2,9 @@ import { StyleProp, ViewStyle } from "react-native";
2
2
  import { SharedValue } from "react-native-reanimated";
3
3
  import { DropProviderRef } from "../types/context";
4
4
  import { ReactNode } from "react";
5
- export interface SortableData {
6
- id: string;
5
+ export type UniqueIdentifier = string | number;
6
+ export interface SortableData<TID extends UniqueIdentifier = string> {
7
+ id: TID;
7
8
  }
8
9
  export declare enum ScrollDirection {
9
10
  None = "none",
@@ -19,22 +20,20 @@ export declare enum SortableDirection {
19
20
  Vertical = "vertical",
20
21
  Horizontal = "horizontal"
21
22
  }
22
- export interface UseSortableOptions<T> {
23
- id: string;
24
- positions: SharedValue<{
25
- [id: string]: number;
26
- }>;
23
+ export interface UseSortableOptions<T, TID extends UniqueIdentifier = string> {
24
+ id: TID;
25
+ positions: SharedValue<Record<TID, number>>;
27
26
  lowerBound: SharedValue<number>;
28
27
  autoScrollDirection: SharedValue<ScrollDirection>;
29
28
  itemsCount: number;
30
29
  itemHeight: number;
31
30
  containerHeight?: number;
32
- onMove?: (id: string, from: number, to: number) => void;
33
- onDragStart?: (id: string, position: number) => void;
34
- onDrop?: (id: string, position: number, allPositions?: {
35
- [id: string]: number;
31
+ onMove?: (id: TID, from: number, to: number) => void;
32
+ onDragStart?: (id: TID, position: number) => void;
33
+ onDrop?: (id: TID, position: number, allPositions?: {
34
+ [id in TID]: number;
36
35
  }) => void;
37
- onDragging?: (id: string, overItemId: string | null, yPosition: number) => void;
36
+ onDragging?: (id: TID, overItemId: TID | null, yPosition: number) => void;
38
37
  }
39
38
  export interface UseSortableReturn {
40
39
  animatedStyle: StyleProp<ViewStyle>;
@@ -65,12 +64,10 @@ export interface UseSortableListReturn<TData extends SortableData> {
65
64
  itemHeight: number;
66
65
  };
67
66
  }
68
- export interface SortableItemProps<T> {
69
- id: string;
67
+ export interface SortableItemProps<T, TID extends UniqueIdentifier> {
68
+ id: TID;
70
69
  data: T;
71
- positions: SharedValue<{
72
- [id: string]: number;
73
- }>;
70
+ positions: SharedValue<Record<TID, number>>;
74
71
  lowerBound?: SharedValue<number>;
75
72
  leftBound?: SharedValue<number>;
76
73
  autoScrollDirection?: SharedValue<ScrollDirection>;
@@ -86,17 +83,15 @@ export interface SortableItemProps<T> {
86
83
  children: ReactNode;
87
84
  style?: StyleProp<ViewStyle>;
88
85
  animatedStyle?: StyleProp<ViewStyle>;
89
- onMove?: (id: string, from: number, to: number) => void;
90
- onDragStart?: (id: string, position: number) => void;
91
- onDrop?: (id: string, position: number, allPositions?: {
92
- [id: string]: number;
93
- }) => void;
94
- onDragging?: (id: string, overItemId: string | null, yPosition: number) => void;
95
- onDraggingHorizontal?: (id: string, overItemId: string | null, xPosition: number) => void;
86
+ onMove?: (id: TID, from: number, to: number) => void;
87
+ onDragStart?: (id: TID, position: number) => void;
88
+ onDrop?: (id: TID, position: number, allPositions?: Record<TID, number>) => void;
89
+ onDragging?: (id: TID, overItemId: TID | null, yPosition: number) => void;
90
+ onDraggingHorizontal?: (id: TID, overItemId: TID | null, xPosition: number) => void;
96
91
  }
97
- export interface SortableProps<TData extends SortableData> {
92
+ export interface SortableProps<TData extends SortableData<TID>, TID extends UniqueIdentifier> {
98
93
  data: TData[];
99
- renderItem: (props: SortableRenderItemProps<TData>) => ReactNode;
94
+ renderItem: (props: SortableRenderItemProps<TData, TID>) => ReactNode;
100
95
  direction?: SortableDirection;
101
96
  itemHeight?: number;
102
97
  itemWidth?: number;
@@ -104,16 +99,14 @@ export interface SortableProps<TData extends SortableData> {
104
99
  paddingHorizontal?: number;
105
100
  style?: StyleProp<ViewStyle>;
106
101
  contentContainerStyle?: StyleProp<ViewStyle>;
107
- itemKeyExtractor?: (item: TData, index: number) => string;
102
+ itemKeyExtractor?: (item: TData, index: number) => TID;
108
103
  useFlatList?: boolean;
109
104
  }
110
- export interface SortableRenderItemProps<TData extends SortableData> {
105
+ export interface SortableRenderItemProps<TData extends SortableData<TID>, TID extends UniqueIdentifier> {
111
106
  item: TData;
112
107
  index: number;
113
- id: string;
114
- positions: SharedValue<{
115
- [id: string]: number;
116
- }>;
108
+ id: TID;
109
+ positions: SharedValue<Record<TID, number>>;
117
110
  direction?: SortableDirection;
118
111
  lowerBound?: SharedValue<number>;
119
112
  leftBound?: SharedValue<number>;
@@ -132,11 +125,9 @@ export interface SortableHandleProps {
132
125
  children: React.ReactNode;
133
126
  style?: StyleProp<ViewStyle>;
134
127
  }
135
- export interface UseHorizontalSortableOptions<T> {
136
- id: string;
137
- positions: SharedValue<{
138
- [id: string]: number;
139
- }>;
128
+ export interface UseHorizontalSortableOptions<T, TID extends UniqueIdentifier = string> {
129
+ id: TID;
130
+ positions: SharedValue<Record<TID, number>>;
140
131
  leftBound: SharedValue<number>;
141
132
  autoScrollDirection: SharedValue<HorizontalScrollDirection>;
142
133
  itemsCount: number;
@@ -144,12 +135,10 @@ export interface UseHorizontalSortableOptions<T> {
144
135
  gap?: number;
145
136
  paddingHorizontal?: number;
146
137
  containerWidth?: number;
147
- onMove?: (id: string, from: number, to: number) => void;
148
- onDragStart?: (id: string, position: number) => void;
149
- onDrop?: (id: string, position: number, allPositions?: {
150
- [id: string]: number;
151
- }) => void;
152
- onDragging?: (id: string, overItemId: string | null, xPosition: number) => void;
138
+ onMove?: (id: TID, from: number, to: number) => void;
139
+ onDragStart?: (id: TID, position: number) => void;
140
+ onDrop?: (id: TID, position: number, allPositions?: Record<TID, number>) => void;
141
+ onDragging?: (id: TID, overItemId: TID | null, xPosition: number) => void;
153
142
  }
154
143
  export interface UseHorizontalSortableReturn {
155
144
  animatedStyle: StyleProp<ViewStyle>;
@@ -157,14 +146,14 @@ export interface UseHorizontalSortableReturn {
157
146
  isMoving: boolean;
158
147
  hasHandle: boolean;
159
148
  }
160
- export interface UseHorizontalSortableListOptions<TData extends SortableData> {
149
+ export interface UseHorizontalSortableListOptions<TData extends SortableData<TID>, TID extends UniqueIdentifier = string> {
161
150
  data: TData[];
162
151
  itemWidth: number;
163
152
  gap?: number;
164
153
  paddingHorizontal?: number;
165
- itemKeyExtractor?: (item: TData, index: number) => string;
154
+ itemKeyExtractor?: (item: TData, index: number) => TID;
166
155
  }
167
- export interface UseHorizontalSortableListReturn<TData extends SortableData> {
156
+ export interface UseHorizontalSortableListReturn<TData extends SortableData<TID>, TID extends UniqueIdentifier = string> {
168
157
  positions: any;
169
158
  scrollX: any;
170
159
  autoScroll: any;
@@ -174,7 +163,7 @@ export interface UseHorizontalSortableListReturn<TData extends SortableData> {
174
163
  handleScrollEnd: () => void;
175
164
  contentWidth: number;
176
165
  getItemProps: (item: TData, index: number) => {
177
- id: string;
166
+ id: TID;
178
167
  positions: any;
179
168
  leftBound: any;
180
169
  autoScrollDirection: any;
@@ -184,12 +173,10 @@ export interface UseHorizontalSortableListReturn<TData extends SortableData> {
184
173
  paddingHorizontal: number;
185
174
  };
186
175
  }
187
- export interface HorizontalSortableItemProps<T> {
188
- id: string;
176
+ export interface HorizontalSortableItemProps<T, TID extends UniqueIdentifier = string> {
177
+ id: TID;
189
178
  data: T;
190
- positions: SharedValue<{
191
- [id: string]: number;
192
- }>;
179
+ positions: SharedValue<Record<TID, number>>;
193
180
  leftBound: SharedValue<number>;
194
181
  autoScrollDirection: SharedValue<HorizontalScrollDirection>;
195
182
  itemsCount: number;
@@ -200,24 +187,22 @@ export interface HorizontalSortableItemProps<T> {
200
187
  children: ReactNode;
201
188
  style?: StyleProp<ViewStyle>;
202
189
  animatedStyle?: StyleProp<ViewStyle>;
203
- onMove?: (id: string, from: number, to: number) => void;
204
- onDragStart?: (id: string, position: number) => void;
205
- onDrop?: (id: string, position: number, allPositions?: {
206
- [id: string]: number;
207
- }) => void;
208
- onDragging?: (id: string, overItemId: string | null, xPosition: number) => void;
190
+ onMove?: (id: TID, from: number, to: number) => void;
191
+ onDragStart?: (id: TID, position: number) => void;
192
+ onDrop?: (id: TID, position: number, allPositions?: Record<TID, number>) => void;
193
+ onDragging?: (id: TID, overItemId: TID | null, xPosition: number) => void;
209
194
  }
210
- export interface HorizontalSortableProps<TData extends SortableData> {
195
+ export interface HorizontalSortableProps<TData extends SortableData<TID>, TID extends UniqueIdentifier = string> {
211
196
  data: TData[];
212
- renderItem: (props: HorizontalSortableRenderItemProps<TData>) => ReactNode;
197
+ renderItem: (props: HorizontalSortableRenderItemProps<TData, TID>) => ReactNode;
213
198
  itemWidth: number;
214
199
  gap?: number;
215
200
  paddingHorizontal?: number;
216
201
  style?: StyleProp<ViewStyle>;
217
202
  contentContainerStyle?: StyleProp<ViewStyle>;
218
- itemKeyExtractor?: (item: TData, index: number) => string;
203
+ itemKeyExtractor?: (item: TData, index: number) => TID;
219
204
  }
220
- export interface HorizontalSortableRenderItemProps<TData extends SortableData> {
205
+ export interface HorizontalSortableRenderItemProps<TData extends SortableData<TID>, TID extends UniqueIdentifier = string> {
221
206
  item: TData;
222
207
  index: number;
223
208
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btfash/react-native-reanimated-dnd",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "A powerful drag-and-drop library for React Native using Reanimated 3",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",