@@ -18,6 +18,7 @@ import {
1818 paddingTopProperty ,
1919 profile ,
2020} from '@nativescript/core' ;
21+ import { Pointer } from '@nativescript/core/ui/gestures' ;
2122import { layout } from '@nativescript/core/utils/utils' ;
2223import { CollectionViewItemDisplayEventData , CollectionViewItemEventData , Orientation , reorderLongPressEnabledProperty , reorderingEnabledProperty , reverseLayoutProperty } from './collectionview' ;
2324import { CLog , CLogTypes , CollectionViewBase , ListViewViewTypes , isBounceEnabledProperty , isScrollEnabledProperty , itemTemplatesProperty , orientationProperty } from './collectionview-common' ;
@@ -203,9 +204,19 @@ export class CollectionView extends CollectionViewBase {
203204 }
204205 manualDragging = false ;
205206 scrollEnabledBeforeDragging = true ;
206- public startDragging ( index : number ) {
207+ draggingStartDelta : [ number , number ] ;
208+ public startDragging ( index : number , pointer ?: Pointer ) {
207209 if ( this . reorderEnabled && this . nativeViewProtected ) {
208210 this . manualDragging = true ;
211+ this . draggingStartDelta = null ;
212+ if ( pointer ) {
213+ const view = this . getViewForItemAtIndex ( index ) ;
214+ if ( view ) {
215+ const size = view . nativeViewProtected . bounds . size ;
216+ const point = ( pointer . ios as UITouch ) . locationInView ( view . nativeViewProtected ) ;
217+ this . draggingStartDelta = [ point . x - size . width / 2 , point . y - size . height / 2 ] ;
218+ }
219+ }
209220 this . nativeViewProtected . beginInteractiveMovementForItemAtIndexPath ( NSIndexPath . indexPathForRowInSection ( index , 0 ) ) ;
210221 this . scrollEnabledBeforeDragging = this . isScrollEnabled ;
211222 this . nativeViewProtected . scrollEnabled = false ;
@@ -219,7 +230,14 @@ export class CollectionView extends CollectionViewBase {
219230 const pointer = event . getActivePointers ( ) [ 0 ] ;
220231 switch ( event . action ) {
221232 case 'move' :
222- collectionView . updateInteractiveMovementTargetPosition ( ( pointer as any ) . location ) ;
233+ let x = pointer . getX ( ) ;
234+ let y = pointer . getY ( ) ;
235+ if ( this . draggingStartDelta ) {
236+ console . log ( 'updateInteractiveMovementTargetPosition' , x , y , this . draggingStartDelta ) ;
237+ x -= this . draggingStartDelta [ 0 ] ;
238+ y -= this . draggingStartDelta [ 1 ] ;
239+ }
240+ collectionView . updateInteractiveMovementTargetPosition ( CGPointMake ( x , y ) ) ;
223241 break ;
224242 case 'up' :
225243 this . manualDragging = false ;
0 commit comments