Socket
Socket
Sign inDemoInstall

react-native-yet-another-sortable

Package Overview
Dependencies
515
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-yet-another-sortable

Drag-and-drop sortable scrollable grid view for React Native.


Version published
Weekly downloads
62
decreased by-1.59%
Maintainers
1
Install size
1.37 MB
Created
Weekly downloads
 

Readme

Source

react-native-yet-another-sortable

Build Status

A sortable scrollable grid / list component for React Native.

  • Change number of columns and row height on the fly
  • Much better performance (especially in debug, compared to alternatives)
  • Fast updates
  • Controllable order
  • Auto-scroll when dragged item is close to the container's border Essentially based on react-native-sortable-grid, it has some improvements and changes, that made me publish it as a separate package instead of making a PR.

Getting Started

Installation

npm install react-native-yet-another-sortable --save

Usage

Check out example project.

import React, { useState, useCallback } from 'react';
import SortableGrid from 'react-native-yet-another-sortable';

const Example = () => {
  const [data] = useState([
    { value: 0, key: 'key0' },
    { value: 1, key: 'key1' },
    { value: 2, key: 'key2' },
  ]);

  const [order, setOrder] = useState(['key2', 'key1', 'key0']);

  const renderItem = useCallback(({ value, color }) => (
    <View style={{ flex: 1 }}>
      <Text>{value}</Text>
    </View>
  ), []);

  return (
    <View style={{ flex: 1 }}>
      <SortableGrid
        order={order}
        data={data}
        renderItem={renderItem}
        onDeactivateDrag={setOrder}
      />
    </View>
  );
};

Props

parametertyperequireddescription
orderarray of string keysyesarray of data key properties used to determine entry order
dataarray of objects with key propertyyesarray of items to be passed to renderItem
rowHeightnumbernorow height
columnsnumbernonumber of columns per row
activationTresholdnumbernotime in ms required to activate drag on hold
transitionDurationnumbernotime in ms required to move cell to its position on release
renderItemfunctionyesrender function for each entry, is passed a data item

Event props

parametertyperequireddescription
onActivateDrag(key, grid) => voidnoWill execute after one holds the item for activateTreshold, before onGrantBlock
onGrantBlock(event, gestureState, grid) => voidnoWill execute on drag start
onMoveBlock(event, gestureState, grid) => voidnoWill execute on each move
onReleaseBlock(event, gestureState, grid) => voidnoWill execute on drag release
onDeactivateDrag(order, grid) => voidnoWill execute on active item drop, after onReleaseBlock, with new order as an argument

Data item props

parametertyperequireddescription
inactivebooleannoMakes block not draggable
keystringyeskey used to order items

Development

In order to develop the application or build android .apk from the sources one should:

  1. Clone this repository
  2. Install package dependencies with npm install
  3. Navigate to example folder: cd example
  4. Install example project dependencies npm install
  5. Run Metro bundler with react-native start
  6. Connect an emulator or physical device via adb, like this (tested with mEMU):
    • adb connect 127.0.0.1:21503
    • adb reverse tcp:8081 tcp:8081
  7. Build and watch with react-native run-android, changes from src directory are picked automatically because of example's metro and babel configurations.

Contributions

PR are always welcome!

Todos

  • Better scroll-on-drag behaviour (smooth scroll without ugly timeouts and large scroll results in the dragged block trembling)
  • Refactoring while perserving the performance
  • Actual tests

Keywords

FAQs

Last updated on 16 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc