npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-draggable-dynamic-flatlist

v1.0.4

Published

A react native component that lets you drag and drop dynamic items of a FlatList.

Downloads

1,154

Readme

react-native-draggable-dynamic-flatlist

A react native component that lets you drag and drop dynamic items of a FlatList. Inspired by react-native-draggable-flatlist

Draggable FlatList demo

Install

  1. npm install react-native-draggable-dynamic-flatlist or yarn add react-native-draggable-dynamic-flatlist
  2. import DraggableFlatList from 'react-native-draggable-dynamic-flatlist'

Api

Props

All props are spread onto underlying FlatList

Name | Type | Description :--- | :--- | :--- data | Array | Items to be rendered. horizontal | Boolean | Orientation of list. renderItem | Function | ({ item, index, move, moveEnd, isActive }) => <Component />. Call move when the row should become active (in an onPress, onLongPress, etc). Call moveEnd when the gesture is complete (in onPressOut). keyExtractor | Function | (item, index) => string scrollPercent | Number | Sets where scrolling begins. A value of 5 will scroll up if the finger is in the top 5% of the FlatList container and scroll down in the bottom 5%. scaleSelectionFactor | Number | Sets the scale factor of the selected item. onMoveEnd | Function | ({ data, to, from, row }) => void Returns updated ordering of data onMoveBegin | Function | (index) => void Called when row becomes active. spacerStyle | View.style | Style of the spacer when an item is moved (ghost view) removeClippedSubviews | Boolean | Improve scroll performance for large lists. May have bugs (missing content) in some circumstances (Default false)

Example

import React, { Component } from 'react'
import { View, TouchableOpacity, Text } from 'react-native'
import DraggableFlatList from 'react-native-draggable-dynamic-flatlist'

class Example extends Component {

  state = {
    data: [...Array(20)].map((d, index) => ({
      key: `item-${index}`,
      label: index,
      backgroundColor: `rgb(${Math.floor(Math.random() * 255)}, ${index * 5}, ${132})`,
    }))
  }

  renderItem = ({ item, index, move, moveEnd, isActive }) => {
    return (
      <TouchableOpacity
        style={{ 
          height: 100, 
          backgroundColor: isActive ? 'blue' : item.backgroundColor,
          alignItems: 'center', 
          justifyContent: 'center' 
        }}
        onLongPress={move}
        onPressOut={moveEnd}>
        <Text style={{ 
          fontWeight: 'bold', 
          color: 'white',
          fontSize: 32,
        }}>{item.label}</Text>
      </TouchableOpacity>
    )
  }

  render() {
    return (
      <View style={{ flex: 1 }}>
        <DraggableFlatList
          data={this.state.data}
          renderItem={this.renderItem}
          keyExtractor={(item, index) => `draggable-item-${item.key}`}
          scrollPercent={5}
          onMoveEnd={({ data }) => this.setState({ data })}
        />
      </View>
    )
  }
}

export default Example

Main differences with react-native-draggable-flatlist

react-native-draggable-flatlist is good but it doesn't work when item's sizes are changing. The positions (x and y) are not calculated properly. It's using measure functions which doesn't work perfectly on react-native, lot of unsolvable bugs (especially on android). Also, the measure function doesn't work when the item is hidden on a flatlist (out of the screen), so if you have big items, it doesn't work really well. The whole measuring system has been refactored by calculating all the positions manually. This library is using the onLayout property on each item and scrollview which makes it more stable with dynamic content. onLayout works perfectly on react-native and there is no more problem with dynamic content.