Skip to content

Commit

Permalink
feat: add onDragBegin prop
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmydel committed Aug 24, 2023
1 parent 892d577 commit df90465
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export default function App() {
console.log('onDragEnd', data);
setItems(data);
}}
onDragBegin={() => {
console.log('onDragBegin');
}}
/>
</SafeAreaView>
</GestureHandlerRootView>
Expand Down
8 changes: 7 additions & 1 deletion src/MyDraggableList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import React from 'react';
import DraggableFlatList from 'react-native-draggable-flatlist';
import type { Props } from './types';

export const MyDraggableList = ({ items, renderItem, onDragEnd }: Props) => {
export const MyDraggableList = ({
items,
renderItem,
onDragEnd,
onDragBegin,
}: Props) => {
return (
<DraggableFlatList
data={items}
onDragEnd={onDragEnd}
onDragBegin={onDragBegin}
keyExtractor={(item) => item.id}
renderItem={renderItem}
/>
Expand Down
7 changes: 6 additions & 1 deletion src/MyDraggableList/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const MyDraggableList = ({
items,
renderItem,
onDragEnd: onDragEndCallback,
onDragBegin: onDragBegin,
}: Props) => {
const onDragEnd: OnDragEndResponder = useCallback(
(result) => {
Expand All @@ -49,8 +50,12 @@ export const MyDraggableList = ({
[items, onDragEndCallback]
);

const onDragStart = useCallback(() => {
onDragBegin && onDragBegin();
}, [onDragBegin]);

return (
<DragDropContext onDragEnd={onDragEnd}>
<DragDropContext onDragEnd={onDragEnd} onDragStart={onDragBegin}>
<Droppable droppableId="droppable">
{(droppableProvided) => (
<View
Expand Down
1 change: 1 addition & 0 deletions src/MyDraggableList/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type Props = {
items: Item[];
renderItem: (params: RenderItemParams<Item>) => React.ReactNode;
onDragEnd?: (params: { data: Item[] }) => void;
onDragBegin?: () => void;
};

0 comments on commit df90465

Please sign in to comment.