deanmcpherson / react-native-sortable-listview

Drag drop capable wrapper of ListView for React Native
MIT License
917 stars 236 forks source link

FlatList support #84

Open vTrip opened 7 years ago

vTrip commented 7 years ago

Will this move to FlatList instead of ListView ??

FlatList has a handy feature scrollToItem that I would like to use with this library.

chetstone commented 7 years ago

As always, PR Is welcome.

Shinichi52 commented 7 years ago

I like this repository, it's awesome. I hope you will support FlatList :)

mrbrdo commented 7 years ago

Would be nice to see this since newer versions of React Native don't support ListView anymore.

nihgwu commented 6 years ago

@mrbrdo ListView is depreciated not removed, I haven't switched to FlatList because there are still some minor issues with it

vTrip commented 6 years ago

@nihgwu i'd love to hear about the issues you have found with FlatList. May help me with future tasks

vTrip commented 6 years ago

Will be uploading my FlatList version of this library to a repo soon. It is a WIP. Would love some assistance with finishing it off. For anyone interested I will post a link here when it is up.

vTrip commented 6 years ago

Hey everyone. I've uploaded to a repo. My version is a WIP.

I need help finishing off functionality. Specifically around the animation for empty row that appears between rows when you are dragging around.

https://github.com/vTrip/FlatListSortable

gazickil commented 6 years ago

@vTrip the scrollToItem can be easly done using current code.

you can use internal layoutMap which contains array of all rows layouts (xPos, yPox, height, width)

Example function:

scrollToIndex = (index, animated) => {
    const y = this._list.layoutMap[index.toString()].y
    this._list.scrollTo({ x: 0, y: y , animated: true });
};

I use it to scroll when adding new element or on load. I'm using setTimeout as i'm waiting for redux to update the store and for list to catch up with the data update.

  componentDidMount() {
    setTimeout(() => {
      this.scrollToIndex(this.props.selectedConfigIdx, false);
    }, 300);
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevProps.selectedConfigIdx !== this.props.selectedConfigIdx && this._areWeDuringAddNewConfig) {
      setTimeout(() => {
        this.scrollToIndex(this.props.selectedConfigIdx, true);
      }, 100);
    }
  }

  _addNewConfig = () => {
    if (this._areWeDuringAddNewConfig) {
      return;
    }

    this._areWeDuringAddNewConfig = true;
    this.props.onConfigAdd();
  };

  scrollToIndex = (index, animated) => {
    const y = this._list.layoutMap[index.toString()].y;
    this._areWeDuringAddNewConfig = false;
    this._list.scrollTo({ x: 0, y: y, animated: animated });
  };