diff --git a/README.md b/README.md index ef97dbf..a24afd9 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ import SortableGrid from 'react-native-sortable-grid' - ``` dragStartAnimation ``` **Object** Custom animation to override the default wiggle. Must be an object containing a key ```transform```, which is an array of transformations. Read about [transforms](https://facebook.github.io/react-native/docs/transforms.html) and [animations](https://facebook.github.io/react-native/docs/animated.html) and [see the example](example/customAnimationExample.js#L47) to learn how to use this. + + - ``` disabledBlocks ``` **Array** + + List of block indices that cannot be sorted. They cannot be dragged or displaced by dragging another block. ## SortableGrid methods diff --git a/index.js b/index.js index 1088680..d9f68bf 100644 --- a/index.js +++ b/index.js @@ -83,6 +83,7 @@ class SortableGrid extends Component { this.dragStartAnimation = null this.rows = null + this.disabledBlocks = [] this.dragPosition = null this.activeBlockOffset = null this.blockWidth = null @@ -183,7 +184,7 @@ class SortableGrid extends Component { closestDistance = distance } }) - if (closest !== this.state.activeBlock) { + if (this.disabledBlocks.indexOf(closest) === -1 && closest !== this.state.activeBlock) { Animated.timing( this._getBlock(closest).currentPosition, { @@ -336,6 +337,9 @@ class SortableGrid extends Component { } activateDrag = (key) => () => { + if (this.disabledBlocks.indexOf(key) !== -1) { + return + } this.panCapture = true this.onDragStart( this.itemOrder[key] ) this.setState({ activeBlock: key })