Spicy-Sparks / react-native-flashdrag-list

Draggable FlashList for react-native
MIT License
54 stars 2 forks source link

Unable to Drag and Drop Items Horizontally with FlashDragList in React Native. #5

Open Rootsalman opened 1 month ago

Rootsalman commented 1 month ago

Hello,

I am using FlashDragList in my React Native application to display a list of images in two columns and enable drag-and-drop functionality. Currently, I can drag and drop images vertically but not horizontally.

Code Snippets:

//Rendering Images (renderImage function):

const renderImage = (
  item: image,
  index: number,
  active: boolean,
  beginDrag: () => void,
) => (
  <TouchableOpacity
    onPress={() => {
      // Handle press event here
      if (!selectMode) {
        setModalIndex(index);
        setModalVisible(true);
      } else {
        onPhotoSelectionToggle(index);
      }
    }}
    onLongPress={() => {
      // Begin drag on long press
      beginDrag();
    }}
    style={{
      opacity: active ? 0.5 : 1,
      padding: 2,
    }}
  >
    <View style={styles.imageView}>
      <Image
        source={{ uri: 'file://' + item.image }}
        style={styles.image}
      />
    </View>
  </TouchableOpacity>
);

//Reordering Images (onReorder function):

const onReorder = (fromIndex: number, toIndex: number) => {
  if (
    fromIndex >= 0 &&
    toIndex >= 0 &&
    fromIndex < imageData.length &&
    toIndex < imageData.length
  ) {
    const copy = [...imageData];
    const [removed] = copy.splice(fromIndex, 1);
    copy.splice(toIndex, 0, removed);
    setImageData(copy); // Update imageData with reordered list
  }
};

//Using FlashDragList Component:

<FlashDragList
  data={imageData}
  renderItem={renderImage}
  keyExtractor={(_item, index) => index.toString()}
  onSort={onReorder}
  showsHorizontalScrollIndicator={false}
  numColumns={2} // Display items in two columns
  itemsSize={180} // Adjust item size as needed
/>
geroale commented 1 month ago

Hello, dragging between multiple lists is not supported at the moment. PRs are welcome and we can also support or suggest the implementation if needed.

Rootsalman commented 1 month ago

Hello, dragging between multiple lists is not supported at the moment. PRs are welcome and we can also support or suggest the implementation if needed.

Thank you for your response. Here, I am using a single list with 2 columns, and I want to drag and drop the items horizontally.