SHISME / react-native-draggable-grid

A draggable and sortable grid of react-native
320 stars 95 forks source link

How to disable the dragging? #50

Closed Ruzen1 closed 3 years ago

Ruzen1 commented 3 years ago

Hey am trying to disable the dragging feature after some certain conditions. Is is possible? Could anyone please guide me?

SHISME commented 3 years ago

You can set disabledDrag and disabledReSorted in the data like this

this.setState({
 data:[
 {
  disabledDrag: true,
  disabledReSorted: true,
},{
  disabledDrag: false,
  disabledReSorted: false,
 }
];

});
 render() {
    return (
      <View style={styles.wrapper}>
        <DraggableGrid
          numColumns={4}
          renderItem={this.render_item}
          data={this.state.data}
          onDragStart={this.onDragStart}
          dragStartAnimation={{
            transform:[
              {scale:this.state.animatedValue}
            ],
          }}
        />
      </View>
    );
  }

disabledDrag:true will let the item could not be drag, disabledReSorted: true will ignore item when resorted data

Ruzen1 commented 3 years ago

@SHISME WOW, thank you very much for your swift reply.Now I see, how to use that disabledDrag. I knew that would do the thing but was not sure how to use it.

It was so much nicer if there was any possibility to stop the whole grid at once. Anyways this shall work for me, thank you very much.

I have one other question, if you could please guide me. I thought it was css but it aint working.

Please look at this picture. Am using your library to drag. The book Facebook is actually being dragged but when I take it down, it seems as if it vanished. Anything from you is very hardly appreciated. Thank you. ` image-1d31e7ea-97af-4db3-958d-a895326de3ea

SHISME commented 3 years ago

@SHISME WOW, thank you very much for your swift reply.Now I see, how to use that disabledDrag. I knew that would do the thing but was not sure how to use it.

It was so much nicer if there was any possibility to stop the whole grid at once. Anyways this shall work for me, thank you very much.

I have one other question, if you could please guide me. I thought it was css but it aint working.

Please look at this picture. Am using your library to drag. The book Facebook is actually being dragged but when I take it down, it seems as if it vanished. Anything from you is very hardly appreciated. Thank you. ` image-1d31e7ea-97af-4db3-958d-a895326de3ea

i think maybe you should set itemHeight

< DraggableGrid
  itemHeight={yourItemHeight}
>
</DraggableGrid>
Ruzen1 commented 3 years ago

@SHISME Thank you for the advice. But it didnt work . I tried creating a new view outside the grid view and set the height. It did solve the problem but if there are more items, the height doesnt go dynamic resulting in incomplete grid. :/

Ruzen1 commented 3 years ago

@SHISME My bad, I solved it by setting minHeight to the device height in the view outside the grid view lol . Sorry for bothering you.

By the way, sometimes when I just start to drag it , it gets stuck. It's really sometimes. Do you know the cause for it? For example the below Toefel Test Book is stuck and cannot be dragged. However if i try again, its fine.

image-5f0ca519-ae3d-4a1b-98b5-0bbf34f9f098

Ruzen1 commented 3 years ago

I am closing the issue so that it be discussed somewhere other time.