diff --git a/README.md b/README.md index d3fb448..a72810f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/draggable-grid.tsx b/src/draggable-grid.tsx index 59c9830..bc306db 100644 --- a/src/draggable-grid.tsx +++ b/src/draggable-grid.tsx @@ -34,6 +34,7 @@ export interface IDraggableGridProps { onDragging?: (gestureState: PanResponderGestureState) => void onDragRelease?: (newSortedData: DataType[]) => void onResetSort?: (newSortedData: DataType[]) => void + readonly?: boolean } interface IMap { [key:string]: T @@ -97,7 +98,7 @@ export const DraggableGrid = function( }) function initBlockPositions() { - items.forEach((_, index) => { + items.forEach((item, index) => { blockPositions[index] = getBlockPositionByOrder(index) }) } @@ -120,7 +121,7 @@ export const DraggableGrid = function( 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) @@ -141,7 +142,7 @@ export const DraggableGrid = function( y: moveY, }) } - function onHandMove(_: GestureResponderEvent, gestureState: PanResponderGestureState) { + function onHandMove(nativeEvent: GestureResponderEvent, gestureState: PanResponderGestureState) { const activeItem = getActiveItem() if (!activeItem) return false const { moveX, moveY } = gestureState @@ -247,6 +248,7 @@ export const DraggableGrid = function( 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)