Coder Social home page Coder Social logo

ajayesivan / react-native-drag-sort Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mochixuan/react-native-drag-sort

1.0 1.0 0.0 34.45 MB

🔥🔥🔥Drag and drop sort control for react-native

License: Apache License 2.0

JavaScript 96.54% Java 0.69% Objective-C 1.92% Starlark 0.85%

react-native-drag-sort's Introduction

react-native-drag-sort

Drag and drop sort control for react-native

GitHub license npm

Version Iteration

Installation

yarn add react-native-drag-sort
or
npm i react-native-drag-sort --save 

export { DragSortableView, AutoDragSortableView, AnySizeDragSortableView }

Tip

Use priority: DragSortableView > AutoDragSortableView > AnySizeDragSortableView

  • 1、If the width and height are fixed and there is no need to slide, use DragSortableView.
  • 2、If the width and height are fixed and you need to slide, use AutoDragSortableView.
  • 3、If the width and height are arbitrary and need to slide, please use AnySizeDragSortableView.

Performance(GIF)

AnyThreePage AnyThreePage
Anysize Anysize
AutomaticSlidingOnePage AutomaticSlidingThreePage
ScrollFixedAddPage DragDeletePage
dragdelete.gif
SortAndFixedPage OneRowsPage
ezgif.com-resize.gif one-line.gif

API

AutoDragSortableView、DragSortableView

isRequired if there is a * in the name field

name Proptypes Description
dataSource * array
parentWidth number parent width
childrenHeight * number Each item height
childrenWidth * number Each item width
marginChildrenTop number So the item's outermost view adds margin, you can only use this method.
marginChildrenBottom number
marginChildrenLeft number
marginChildrenRight number
sortable bool Do not allow dragging
onClickItem func click
onDragStart func
onDragEnd func
onDataChange func This method is called every time the data changes.
renderItem * func render item view
fixedItems array no remove
keyExtractor func (item,index) => key
delayLongPress number
isDragFreely bool Whether to limit the drag space
onDragging func
maxScale number
minOpacity number

The following attributes belong only to AutoDragSortableView

name Proptypes Description
scaleDuration number
slideDuration number
autoThrottle number
autoThrottleDuration number
renderHeaderView element
headerViewHeight number
scrollIndicatorInsets ({top:number, left:number, bottom:number, right:number})
renderBottomView element
bottomViewHeight number
onScrollListener (event: NativeSyntheticEvent) => void
onScrollRef (ref: any) => void
AnySizeDragSortableView
name Proptypes Description
dataSource * array
keyExtractor func.isRequired (item,index) => key
renderItem * func render item view
onDataChange func This method is called every time the data changes.
renderHeaderView element
headerViewHeight number
renderBottomView element
bottomViewHeight number
autoThrottle number
autoThrottleDuration number
onDragEnd func
scrollIndicatorInsets ({top:number, left:number, bottom:number, right:number})
onScrollListener (event: NativeSyntheticEvent) => void
onScrollRef (ref: any) => void
areaOverlapRatio number Must be greater than 0.5
movedWrapStyle StyleProp style
childMarginTop number
childMarginBottom number
childMarginLeft number
childMarginRight number

Example

<DragSortableView
    dataSource={this.state.data}
    parentWidth={parentWidth}
    childrenWidth= {childrenWidth}
    childrenHeight={childrenHeight}
    keyExtractor={(item,index)=> item.id}
    renderItem={(item,index)=>{
        return this.renderItem(item,index)
    }}
/>
    
<AutoDragSortableView
    dataSource={this.state.data}
    parentWidth={parentWidth}
    childrenWidth= {childrenWidth}
    childrenHeight={childrenHeight}
    keyExtractor={(item,index)=> item.id}
    renderItem={(item,index)=>{
        return this.renderItem(item,index)
    }}
/>

// ====== AnySizeDragSortableView start =======

constructor(props) {
    super(props);
    this.sortableViewRef = createRef()
}

<AnySizeDragSortableView
    ref={this.sortableViewRef}
    dataSource={items}
    keyExtractor={(item) => item.text} // 1、isRequired
    renderItem={this._renderItem}
    onDataChange={(data, callback)=> {
        this.setState({items: data},()=>{
            callback() // isRequired
        })
    }}
/>

_renderItem = (item, index, isMoved) => {
    return (
    	<TouchableOpacity
	        onLongPress={() => {
	            this.sortableViewRef.current.startTouch(item, index) // 2、isRequired	        }}
	        onPressOut = {() => {
	        	this.sortableViewRef.current.onPressOut() 3、isRequired
	        }}
	      >
      	<...>
      </TouchableOpacity>
    )
}


// ====== AnySizeDragSortableView end =======

react-native-drag-sort's People

Contributors

ajayesivan avatar apgsn avatar avertin avatar fallenner avatar mochixuan avatar sevellion avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.