ollija / react-native-sortable-grid

Drag-drop-sortable grid view for react native
MIT License
441 stars 173 forks source link

Drag-and-drop -style rearrangable grid view

Issue Stats

react-native-sortable-grid

Join the chat at https://gitter.im/react-native-sortable-grid/Lobby [npm]() Sponsored by Leonidas [npm]() [David]() [David]()

Installation

npm i react-native-sortable-grid --save

Usage

import SortableGrid from 'react-native-sortable-grid'

...

<SortableGrid>
  {
    ['a', 'b', 'c'].map( (letter, index) =>

      <View key={index}>
        <Text>{letter}</Text>
      </View>

    )
  }
</SortableGrid>

SortableGrid properties

SortableGrid methods

SortableGrid's children's properties

Flag to mark a child node as being inactive. If set, no touch events will be fired when users interact with the node.

onDragRelease return value looks like this:

Object {

  itemOrder: Array [
    0: Object {
      key: "1"
      order: 0
      ref: null
    }
    1: Object {
      key: "5"
      order: 1
      ref: null
    }
    n: Object ...
  ]

}

Full SortableGrid example:

 <SortableGrid
   blockTransitionDuration      = { 400 }
   activeBlockCenteringDuration = { 200 }
   itemsPerRow                  = { 4 }
   dragActivationTreshold       = { 200 }
   onDragRelease                = { (itemOrder) => console.log("Drag was released, the blocks are in the following order: ", itemOrder) }
   onDragStart                  = { ()          => console.log("Some block is being dragged now!") } >

   {
     ['a', 'b', 'c'].map( (letter, index) =>

       <View key={index} onTap={() => console.log("Item number:", index, "was tapped!") }>
         <Text>{letter}</Text>
       </View>

     )
   }

 </SortableGrid>

Demos

Basic item deletion
toggleDeleteMode() is called during onTap in this example

Issue Stats

Custom block animation can be passed to the grid

Custom animation

Smooth resizing of the grid when the last row becomes empty:

Issue Stats

No grid resizing if the grid has flex:1 assigned:

Issue Stats

The item drag is constrained within the grid:

Issue Stats

With flex:1 there is more space to drag:

Issue Stats