• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fluid sortable list for React Native

Sortable List Demo

Built with React-Motion.

React Native Sortable List

(proof-of-concept!)

This is the react-native port of the react-SortableList demo. It supports arbitrary number of items, and each item can have different heights. It also include some react-native specific tweaks:

  • The list of items are embedded in a ScrollView.
  • Long-Press to start sorting. During sorting, ScrollView is disabled.
  • Auto-scrolling when a dragged item is near the top or bottom of the screen.

This is just a demo, if you want to play around with it, your best bet (at the moment) is to copy it into your project.

Reusable component coming soon!

Performance

The animation can feel sluggish in development mode. On iPhone5 it runs at ~15fps if you randomly drag around an item as fast as you can. It turns out that most of the time is spent in dev-mode safety checks.

When running on device be sure to turn on production mode, and you'd get proper ~60fps.

See Using offline bundle.

API

<SortableList items={data}>
  {(key) => ... }
</SortableList>

Where data is a map of string to data (i.e. {[string]: any}). The data items can be polymorphic.

Like react-motion, we use the insertion order of the keys to determine the items ordering.

How it works

The sortable list tracks the height of its children, and lay them out vertically one after another.

Since we know the dimensions and locations of all children, it's easy to animate them using react-motion whenever the order of the children changes.

On drag, we look at the mouse position and iterates through the list to find an insertion point. Once we know the new ordering, the same code that does the layout animates everything into place.

Ditto with shuffling items.

React-Native ScrollResponder Patch

When your finger moves on the screen, are you trying to scroll the ScrollView or are you trying to drag an item? The react-native event responder system is used to distinguish between these two use cases.

The key question is "who is the responder?". If the responder is the ScrollView, then touch movement is a scroll. If the responder is a list item, then the touch movement is a drag. At any one time there can only be one responder, so you can't drag an item and scroll at the same time, which makes sense.

The responder negotiation process is pretty much a way to control "should it scroll or should it drag".

Now, ScrollView is special. Usually, it overrides responder precedence and hijack responder status from other components. Say if you press down on a button and start scrolling, it makes sense that the ScrollView should become the responder and cancel the button press.

In our case though, we don't EVER want ScrollView to hijack responder status while we are sorting. The way to do that is to set ScrollView's scrollEnabled property to false. This works except for a small bug where programmatic scrolling causes ScrollView to hijack responder status despite that scrollEnabled is false.

See: [ScrollView] Shouldn't become responder if scrollEnabled is false.

For now, package.json uses a custom react-native branch that includes this fix.

TODO

  • Can add and remove items.
  • Builtin pull-to-refresh.

More Repositories

1

playing-cards-assets

Playing Cards Image Assets (SVG+PNG)
Makefile
244
star
2

rubish

Ruby Interacive Shell
Ruby
60
star
3

FaceOff

Turn Off Facebook "Like" Button
CoffeeScript
55
star
4

react-motion-TransitionSpring-demo

JavaScript
52
star
5

xmd

extensible markdown format
TypeScript
31
star
6

ruby-bootcamp-mongoid

Lessons for Mongoid Clone for Ruby Bootcamp
30
star
7

react-SortableList

React sortable list . Fluid animation with react motion
JavaScript
29
star
8

react-native-bootcamp-pretraining

Go
26
star
9

donkey

Asynchronous Service Server
Ruby
22
star
10

design-resources

Some resources to get you started
20
star
11

matchmaker

A Ruby Pattern Matching Library
Ruby
14
star
12

ComaLisp

A Lispy Abuse of Ruby Syntax
Ruby
14
star
13

babel-fast-presets

JavaScript
12
star
14

dress

DOM transformation based on Nokogiri
Ruby
10
star
15

qtum-dapp-counter

TypeScript
9
star
16

evm-clojure

EVM Low Level Lisp compiler in Clojure
Clojure
8
star
17

rushcheck

Daisuke IKEGAMI's Ruby port of Quickcheck
7
star
18

quickpack

TypeScript
7
star
19

packpackgo

TypeScript
7
star
20

CryptoReaders

Material for crypto reading group
6
star
21

serl

Lisp Metaprogramming for Erlang
Erlang
5
star
22

SZRuby.org

Shenzhen Ruby Group
Ruby
5
star
23

piperl

a reliable distributed piping system in erlang
Erlang
5
star
24

qtumjs

TypeScript
5
star
25

fork2-builder

Fork A Programmer - Programming Workshop Builder
JavaScript
4
star
26

let

memoized values, like rspec's let
Ruby
4
star
27

rn-ScrollViewContentInsetChangeJitter

UIScrollView setting contentInset causes jitter
Swift
4
star
28

rere

top secret project
JavaScript
3
star
29

electrocute

JavaScript
3
star
30

awesome-qtum

list of awesome resources for qtum
3
star
31

go-jsons

Expand JSON template with shell's brace expansion
Go
3
star
32

ios-FingerPaint

FingePaint App Reference Implementation
Swift
2
star
33

qtum-portal

Go
2
star
34

parcel-react-ts-boilerplate

TypeScript
2
star
35

sike-react-course

sike-react-course
JavaScript
2
star
36

gowatch

Turn file system events into text stream for processing
Go
2
star
37

transwink

transwink rails app
Ruby
2
star
38

js-learn-immutable

JavaScript
2
star
39

quiptool

Quip Tools
Go
2
star
40

rust-x86vm

Rust
2
star
41

react-markdown-renderer

Markdown Renderer For React
TypeScript
2
star
42

my_mongoid_spec

Spec Suite for MyMongoid
Ruby
2
star
43

fork2-myexpress-verify

Test Suite For My Express
JavaScript
2
star
44

metacircus-blog

blog content
1
star
45

typescript2-react-starter

TypeScript
1
star
46

fork2-rails

fork2 rails web app
JavaScript
1
star
47

Empty-TiddlyWiki

TiddlyWiki with my personal configuration
1
star
48

qtum-loopring

JavaScript
1
star
49

jsonql

Go
1
star
50

javascript-exercises

JavaScript
1
star
51

citywanders

Nadia's Project
Ruby
1
star
52

jscss-loader

TypeScript
1
star
53

metacircus-sinatra

My Blog, My Very Own
Ruby
1
star
54

LOBE

Glorified grep with Node.js
JavaScript
1
star
55

genii

TypeScript
1
star
56

normpath

Go
1
star
57

neutrino-react-ts-boilerplate

JavaScript
1
star
58

shadowsocks-rust

Rust implementation of ShadowSocks protocol (practice project)
Rust
1
star
59

lazydo

Lazy Objects for Node.js
JavaScript
1
star
60

rnplay-typescript-starter

TypeScript
1
star
61

gogogo

A command line utility that transforms a JSON stream into running processes.
Go
1
star
62

monitor-ss

monitor of shadowsocks proxies are still working
Go
1
star
63

neutrino-preset-react-typescript

JavaScript
1
star
64

qtum-abi-play

TypeScript
1
star
65

metacircus

me blog, me very own
CSS
1
star
66

go-kallax-bug

minimal test case for kallax buffer reuse bug
Go
1
star
67

V2EX-iOS

V2EX iOS Client
Swift
1
star
68

curly

my very own template language thing
Ruby
1
star
69

qtum-c-smartcontract-API

a proposal of lowlevel smart contract API
C
1
star
70

redmiso

ORM for Redis (more like access patterns)
Ruby
1
star
71

HNStat

Hacker News Statistics
Ruby
1
star
72

DaisyDiff

HTML Diffing and Comparison (JRuby Wrapper)
Ruby
1
star
73

qtumaddr

QTUM Address Converter
Go
1
star
74

POOP-el

javascript-style OOP system for Emacs
Emacs Lisp
1
star
75

react-native-workshop-starterkit

Objective-C
1
star
76

dot-emacs

My Emacs Config
Emacs Lisp
1
star
77

proteus-crypto-experiments

TypeScript
1
star
78

crypto-privacy-notes

1
star
79

FaceOff-Web

Web Site for FaceOff Chrome Extension
Ruby
1
star
80

rere-chef

chef deployment stuff for my top secret project
Ruby
1
star
81

my-bin

random scripts on my bin path
1
star
82

my_mongoid

Mongoid Clone for Ruby Bootcamp
Ruby
1
star
83

nolang

TypeScript
1
star
84

dot-files

my dot files
Shell
1
star