Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const styles = StyleSheet.create({
| itemHeight | number | no | if not set this, it will the same as itemWidth |
| dragStartAnimation | object | no | custom drag start animation |
| style | object | no | grid styles |
| readonly | boolean | no | It will disable drag for all items |

## Event Props

Expand Down
8 changes: 5 additions & 3 deletions src/draggable-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IDraggableGridProps<DataType extends IBaseItemType> {
onDragging?: (gestureState: PanResponderGestureState) => void
onDragRelease?: (newSortedData: DataType[]) => void
onResetSort?: (newSortedData: DataType[]) => void
readonly?: boolean
}
interface IMap<T> {
[key:string]: T
Expand Down Expand Up @@ -97,7 +98,7 @@ export const DraggableGrid = function<DataType extends IBaseItemType>(
})

function initBlockPositions() {
items.forEach((_, index) => {
items.forEach((item, index) => {
blockPositions[index] = getBlockPositionByOrder(index)
})
}
Expand All @@ -120,7 +121,7 @@ export const DraggableGrid = function<DataType extends IBaseItemType>(
function onBlockPress(itemIndex: number) {
props.onItemPress && props.onItemPress(items[itemIndex].itemData)
}
function onStartDrag(_: GestureResponderEvent, gestureState: PanResponderGestureState) {
function onStartDrag(nativeEvent: GestureResponderEvent, gestureState: PanResponderGestureState) {
const activeItem = getActiveItem()
if (!activeItem) return false
props.onDragStart && props.onDragStart(activeItem.itemData)
Expand All @@ -141,7 +142,7 @@ export const DraggableGrid = function<DataType extends IBaseItemType>(
y: moveY,
})
}
function onHandMove(_: GestureResponderEvent, gestureState: PanResponderGestureState) {
function onHandMove(nativeEvent: GestureResponderEvent, gestureState: PanResponderGestureState) {
const activeItem = getActiveItem()
if (!activeItem) return false
const { moveX, moveY } = gestureState
Expand Down Expand Up @@ -247,6 +248,7 @@ export const DraggableGrid = function<DataType extends IBaseItemType>(
return Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2))
}
function setActiveBlock(itemIndex: number, item: DataType) {
if (props.readonly) return
if (item.disabledDrag) return

setPanResponderCapture(true)
Expand Down