Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements moving unexpectedly after an initial scroll in the main snack #516

Open
lParraBraze opened this issue Dec 19, 2023 · 2 comments
Open

Comments

@lParraBraze
Copy link

Describe the bug
When using the main snack example with small adjustments I see an element moving down and then stopping.

I think it would be expected that the element does not move if the conditions to active the scroll are not matched.

To Reproduce
Going to write the code here because is very similar to the main snack:

import React, {useState} from 'react';
import {Text, StyleSheet, TouchableOpacity} from 'react-native';
import DraggableFlatList from 'react-native-draggable-flatlist';

const NUM_ITEMS = 30;
function getColor(i: number) {
  const multiplier = 255 / (NUM_ITEMS - 1);
  const colorVal = i * multiplier;
  return `rgb(${colorVal}, ${Math.abs(128 - colorVal)}, ${255 - colorVal})`;
}

type Item = {
  key: string;
  label: string;
  height: number;
  width: number;
  backgroundColor: string;
};

const initialData: Item[] = [...Array(NUM_ITEMS)].map((d, index) => {
  const backgroundColor = getColor(index);
  return {
    key: `item-${index}`,
    label: String(index) + '',
    height: 100,
    width: 60 + Math.random() * 40,
    backgroundColor,
  };
});

export const MyRankings = () => {
  const [data, setData] = useState(initialData);

  const renderItem = ({item, drag, isActive}: RenderItemParams<Item>) => {
    return (
      <TouchableOpacity
        onLongPress={drag}
        disabled={isActive}
        style={[
          styles.rowItem,
          {backgroundColor: isActive ? 'red' : item.backgroundColor},
        ]}>
        <Text style={styles.text}>{item.label}</Text>
      </TouchableOpacity>
    );
  };

  return (
    <DraggableFlatList
      data={data}
      onDragEnd={({data}) => setData(data)}
      keyExtractor={item => item.key}
      renderItem={renderItem}
    />
  );
};

const styles = StyleSheet.create({
  rowItem: {
    height: 50,
    width: 50,
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    color: 'white',
    fontSize: 24,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});
Screen.Recording.2023-12-19.at.00.50.47.mov

Platform & Dependencies
Please list any applicable dependencies in addition to those below (react-navigation etc).

  • react-native-draggable-flatlist version: "^4.0.1"
  • Platform:iOS
  • React Native or Expo version: "0.72.2"
  • Reanimated version: "^3.3.0"
  • React Native Gesture Handler version: "^2.8.0"

Additional context
My app looks like this:

const App = () => {
  return (
    <React.StrictMode>
      <GestureHandlerRootView style={{flex: 1}}>
        <MyRankings />
      </GestureHandlerRootView>
    </React.StrictMode>
  );
};

I think this could be related to #509

@lParraBraze
Copy link
Author

Quick update here, if you create 200 instead of 30 you can get this behavior, which is another bug where the dragged row doesn't show the content:

Screen.Recording.2024-01-14.at.00.00.41.mov

@tomas1808
Copy link

tomas1808 commented Jun 8, 2024

Same problem. Did you manage to fix this?

Is there a better drag and drop list for React Native? I wanted to like this one but seems to be unstable and semi-abandoned. Not production ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants