Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onDragItemActive #86

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ const styles = StyleSheet.create({
## Event Props


| parameter | type | required | description |
| :-------- | :---- | :------- | :---------- |
| onItemPress | (item) => void | no | Function will execute when item on press |
| onDragStart | (startDragItem) => void | no | Function will execute when item start drag |
| parameter | type | required | description |
| :-------- | :---- | :------- |:------------------------------------------------------------------------------|
| onItemPress | (item) => void | no | Function will execute when item on press |
| onDragStart | (startDragItem) => void | no | Function will execute when item start drag |
| onDragRelease | (data) => void | no | Function will execute when item release, and will return the new ordered data |
| onResetSort | (data) => void | no | Function will execute when dragged item change sort |
| onDragging | (gestureState: PanResponderGestureState) => void| no | Function will execute when dragging item |
| onResetSort | (data) => void | no | Function will execute when dragged item change sort |
| onDragging | (gestureState: PanResponderGestureState) => void| no | Function will execute when dragging item |
| onDragItemActive | (item) => void| no | Function will execute when any item active |

## Item Props

Expand Down
18 changes: 9 additions & 9 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ const styles = StyleSheet.create({
## Event Props


| 参数名 | 类型 | 是否必要 | 描述 |
| :-------- | :---- | :------- | :---------- |
| onItemPress | (item) => void | no | 子组件点击时的回调 |
| onDragStart | (startDragItem) => void | no | 开始拖动是的回调 |
| onDragRelease | (data) => void | no | 拖动释放时的回调,会返回排序之后的数据 |
| onResetSort | (data) => void | no | 拖动时重新排序的回调,会返回排序后的数据 |
| onDragging | (gestureState: PanResponderGestureState) => void| no | 拖动时的回调函数,返回拖动的组件的位置 |

| 参数名 | 类型 | 是否必要 | 描述 |
|:-----------------|:-------------------------------------------------| :------- |:---------------------|
| onItemPress | (item) => void | no | 子组件点击时的回调 |
| onDragStart | (startDragItem) => void | no | 开始拖动是的回调 |
| onDragRelease | (data) => void | no | 拖动释放时的回调,会返回排序之后的数据 |
| onResetSort | (data) => void | no | 拖动时重新排序的回调,会返回排序后的数据 |
| onDragging | (gestureState: PanResponderGestureState) => void | no | 拖动时的回调函数,返回拖动的组件的位置 |
| onDragItemActive | (item) => void | no | 当要拖动的选项被激活的时候触发 |
## Item Props

| parameter | type | required | description |
Expand Down Expand Up @@ -186,4 +186,4 @@ const styles = StyleSheet.create({

如果你想删除,或者添加,或者重新排序数据,你可以通过修改data来达到目的,组件会根据新的 props.data 来计算出如何排序,删除,添加子组件

> 需要注意的是,data 中的数据必须要有key,而且必须唯一
> 需要注意的是,data 中的数据必须要有key,而且必须唯一
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sortable",
"grid"
],
"version": "2.1.7",
"version": "2.1.8",
"description": "A draggable grid for react native",
"main": "built/src/index.js",
"types": "src/index.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/draggable-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export interface IDraggableGridProps<DataType extends IBaseItemType> {
itemHeight?: number
dragStartAnimation?: StyleProp<any>
onItemPress?: (item: DataType) => void
onDragItemActive?: (item: DataType) => void
onDragStart?: (item: DataType) => void
onDragging?: (gestureState: PanResponderGestureState) => void
onDragRelease?: (newSortedData: DataType[]) => void
onResetSort?: (newSortedData: DataType[]) => void
delayLongPress?:number
delayLongPress?: number
}
interface IMap<T> {
[key: string]: T
Expand Down Expand Up @@ -250,6 +251,8 @@ export const DraggableGrid = function<DataType extends IBaseItemType>(
function setActiveBlock(itemIndex: number, item: DataType) {
if (item.disabledDrag) return

props.onDragItemActive && props.onDragItemActive(item)

setPanResponderCapture(true)
setActiveItemIndex(itemIndex)
}
Expand Down