@@ -60,19 +60,20 @@ interface Props<T> extends VirtualizedListProps<T> {
6060 autoscrollThreshold : number ,
6161 horizontal : boolean ,
6262 data : T [ ] ,
63- onMoveBegin ?: ( index : number ) => void ,
63+ onDragBegin ?: ( index : number ) => void ,
6464 onRelease ?: ( index : number ) => void ,
65- onMoveEnd ?: ( params : {
65+ onDragEnd ?: ( params : {
6666 data : T [ ] ,
6767 from : number ,
6868 to : number ,
6969 } ) => void
7070 renderItem : ( params : {
7171 item : T ,
7272 index : number ,
73- move : ( index : number ) => void ,
73+ drag : ( index : number ) => void ,
7474 isActive : boolean ,
7575 } ) => React . ComponentType
76+ animationConfig : Partial < Animated . SpringConfig > ,
7677}
7778
7879type State = {
@@ -154,13 +155,8 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
154155 }
155156
156157 hoverAnimConfig = {
157- damping : 20 ,
158- mass : 0.2 ,
159- stiffness : 100 ,
160- overshootClamping : false ,
158+ ...this . props . animationConfig ,
161159 toValue : sub ( this . hoverTo , sub ( this . scrollOffset , this . hoverScrollSnapshot ) ) ,
162- restSpeedThreshold : 0.2 ,
163- restDisplacementThreshold : 0.2 ,
164160 }
165161
166162 distToTopEdge = max ( 0 , this . hoverAnim )
@@ -196,7 +192,15 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
196192
197193 static defaultProps = {
198194 autoscrollThreshold : 30 ,
199- autoScrollSpeed : 100
195+ autoScrollSpeed : 100 ,
196+ animationConfig : {
197+ damping : 20 ,
198+ mass : 0.2 ,
199+ stiffness : 100 ,
200+ overshootClamping : false ,
201+ restSpeedThreshold : 0.2 ,
202+ restDisplacementThreshold : 0.2 ,
203+ } ,
200204 }
201205
202206 constructor ( props : Props < T > ) {
@@ -239,10 +243,10 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
239243 this . queue = [ ]
240244 }
241245
242- move = ( hoverComponent : React . ComponentType , index : number , activeKey : string ) => {
246+ drag = ( hoverComponent : React . ComponentType , index : number , activeKey : string ) => {
243247
244248 if ( this . state . hoverComponent ) {
245- // We can't move more than one row at a time
249+ // We can't drag more than one row at a time
246250 // TODO: Put action on queue?
247251 console . log ( "## Can't set multiple active items" )
248252 } else {
@@ -255,8 +259,8 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
255259 activeKey,
256260 hoverComponent,
257261 } , ( ) => {
258- const { onMoveBegin } = this . props
259- onMoveBegin && onMoveBegin ( index )
262+ const { onDragBegin } = this . props
263+ onDragBegin && onDragBegin ( index )
260264 }
261265 )
262266 }
@@ -268,17 +272,17 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
268272 onRelease && onRelease ( index )
269273 }
270274
271- onMoveEnd = ( [ from , to ] : readonly number [ ] ) => {
272- const { onMoveEnd } = this . props
273- if ( onMoveEnd ) {
275+ onDragEnd = ( [ from , to ] : readonly number [ ] ) => {
276+ const { onDragEnd } = this . props
277+ if ( onDragEnd ) {
274278 const { data } = this . props
275279 let newData = [ ...data ]
276280 if ( from !== to ) {
277281 newData . splice ( from , 1 )
278282 newData . splice ( to , 0 , data [ from ] )
279283 }
280284
281- onMoveEnd ( { from, to, data : newData } )
285+ onDragEnd ( { from, to, data : newData } )
282286 }
283287
284288 const lo = Math . min ( from , to ) - 1
@@ -708,7 +712,7 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
708712 spring ( this . hoverClock , this . hoverAnimState , this . hoverAnimConfig ) ,
709713 cond ( eq ( this . hoverAnimState . finished , 1 ) , [
710714 stopClock ( this . hoverClock ) ,
711- call ( this . moveEndParams , this . onMoveEnd ) ,
715+ call ( this . moveEndParams , this . onDragEnd ) ,
712716 this . resetHoverSpring ,
713717 set ( this . hasMoved , 0 ) ,
714718 ] ) ,
@@ -751,7 +755,7 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
751755 index = { index }
752756 renderItem = { renderItem }
753757 item = { item }
754- move = { this . move }
758+ drag = { this . drag }
755759 />
756760 )
757761 }
@@ -855,7 +859,7 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
855859export default DraggableFlatList
856860
857861type RowItemProps = {
858- move : (
862+ drag : (
859863 hoverComponent : React . ComponentType ,
860864 index : number ,
861865 itemKey : string ,
@@ -868,15 +872,15 @@ type RowItemProps = {
868872
869873class RowItem extends React . PureComponent < RowItemProps > {
870874
871- move = ( ) => {
872- const { move , renderItem, item, index, itemKey } = this . props
875+ drag = ( ) => {
876+ const { drag , renderItem, item, index, itemKey } = this . props
873877 const hoverComponent = renderItem ( {
874878 isActive : true ,
875879 item,
876880 index,
877- move : ( ) => console . log ( '## attempt to call move on hovering component' ) ,
881+ drag : ( ) => console . log ( '## attempt to call drag() on hovering component' ) ,
878882 } )
879- move ( hoverComponent , index , itemKey )
883+ drag ( hoverComponent , index , itemKey )
880884 }
881885
882886 render ( ) {
@@ -885,7 +889,7 @@ class RowItem extends React.PureComponent<RowItemProps> {
885889 isActive : false ,
886890 item,
887891 index,
888- move : this . move ,
892+ drag : this . drag ,
889893 } )
890894 }
891895}
0 commit comments