From 579ee0fbd2859c1895d6aae8356b5fcc0e8ac617 Mon Sep 17 00:00:00 2001 From: Essi Salmenkivi Date: Mon, 15 May 2017 15:56:32 +0300 Subject: [PATCH 1/3] add disabled blocks option --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 }) From 1c5a36d6c6a610cfcef1356429de46c69df70a53 Mon Sep 17 00:00:00 2001 From: Essi Salmenkivi Date: Mon, 15 May 2017 16:00:39 +0300 Subject: [PATCH 2/3] Add description of disabledBlocks prop --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ef97dbf..88339b1 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 From 09f257554c48d85a1789829bacb06c57176e7e1a Mon Sep 17 00:00:00 2001 From: Essi Salmenkivi Date: Mon, 15 May 2017 16:08:17 +0300 Subject: [PATCH 3/3] md styling --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 88339b1..a24afd9 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,9 @@ import SortableGrid from 'react-native-sortable-grid' 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** + - ``` disabledBlocks ``` **Array** - List of block indices that cannot be sorted. They cannot be dragged or displaced by dragging another block. + List of block indices that cannot be sorted. They cannot be dragged or displaced by dragging another block. ## SortableGrid methods