@@ -99,7 +99,7 @@ export class GesturesObserver {
9999 private _notifyTouch : boolean ;
100100
101101 private gestureHandler : Handler < any , any > ;
102- private _eventData : { [ k : number ] : CommonGestureEventData | TouchGestureEventData } = { } ;
102+ private _eventData : { [ k : number ] : CommonGestureEventData | AndroidTouchGestureEventData } = { } ;
103103
104104 private _onTargetLoaded : ( data : EventData ) => void ;
105105 private _onTargetUnloaded : ( data : EventData ) => void ;
@@ -154,7 +154,7 @@ export class GesturesObserver {
154154 }
155155 eventData . handler = this . gestureHandler ;
156156 }
157- eventData . prepare ( this . target , event . data ) ;
157+ eventData . prepare ( this . target , event ) ;
158158 _executeCallback ( this , eventData ) ;
159159 // this.callback.call(this._context, {
160160 // eventName: gestureToString(type),
@@ -209,7 +209,7 @@ export class GesturesObserver {
209209 gestureHandler = manager . createGestureHandler ( HandlerType . LONG_PRESS , target [ 'LONGPRESS_HANDLER_TAG' ] , {
210210 simultaneousHandlers : [ ROOT_GESTURE_HANDLER_TAG ]
211211 } ) ;
212- gestureHandler . on ( GestureHandlerStateEvent , this . onGestureStateChange ( GestureTypes . longPress , __IOS__ ? GestureState . BEGAN : GestureState . ACTIVE ) , this ) ;
212+ gestureHandler . on ( GestureHandlerStateEvent , this . onGestureStateChange ( GestureTypes . longPress , __IOS__ ? GestureState . BEGAN : GestureState . ACTIVE ) , this ) ;
213213 }
214214 if ( type & GestureTypes . doubleTap ) {
215215 gestureHandler = manager . createGestureHandler ( HandlerType . TAP , target [ 'DOUBLE_TAP_HANDLER_TAG' ] , {
@@ -258,7 +258,7 @@ export class GesturesObserver {
258258 if ( this . _notifyTouch ) {
259259 let eventData = this . _eventData [ GestureTypes . touch ] ;
260260 if ( ! eventData ) {
261- eventData = this . _eventData [ GestureTypes . touch ] = new TouchGestureEventData ( ) ;
261+ eventData = this . _eventData [ GestureTypes . touch ] = new AndroidTouchGestureEventData ( ) ;
262262 eventData . handler = this . gestureHandler ;
263263 }
264264 eventData . prepare ( this . target , motionEvent ) ;
@@ -267,11 +267,14 @@ export class GesturesObserver {
267267 }
268268}
269269
270- class Pointer implements Pointer {
270+ class AndroidPointer implements AndroidPointer {
271271 public android : number ;
272272 public ios : any = undefined ;
273273
274- constructor ( id : number , private event : android . view . MotionEvent ) {
274+ constructor (
275+ id : number ,
276+ private event : android . view . MotionEvent
277+ ) {
275278 this . android = id ;
276279 }
277280
@@ -287,7 +290,11 @@ class GesturePointer {
287290 android : number ;
288291 ios : number ;
289292 private event : any ;
290- constructor ( index : number , private x , private y ) {
293+ constructor (
294+ index : number ,
295+ private x ,
296+ private y
297+ ) {
291298 this . android = index ;
292299 }
293300
@@ -300,6 +307,32 @@ class GesturePointer {
300307 }
301308}
302309
310+ class Pointer {
311+ _location : CGPoint ;
312+ ios : GestureHandler ;
313+ _view : View ;
314+ get location ( ) {
315+ if ( ! this . _location ) {
316+ this . _location = this . ios . locationInView ( this . _view . nativeViewProtected ) ;
317+ }
318+
319+ return this . _location ;
320+ }
321+
322+ constructor ( touch , targetView , location ?) {
323+ this . _location = location ;
324+ this . ios = touch ;
325+ this . _view = targetView ;
326+ }
327+
328+ getX ( ) {
329+ return this . location . x ;
330+ }
331+
332+ getY ( ) {
333+ return this . location . y ;
334+ }
335+ }
303336class CommonGestureEventData implements GestureEventData {
304337 ios ;
305338 android ;
@@ -320,20 +353,22 @@ class CommonGestureEventData implements GestureEventData {
320353 state : GestureStateTypes ;
321354 handler : Handler < any , any > ;
322355
323- private _activePointers : GesturePointer [ ] ;
324- private _allPointers : GesturePointer [ ] ;
356+ private _activePointers : ( GesturePointer | Pointer ) [ ] ;
357+ private _allPointers : ( GesturePointer | Pointer ) [ ] ;
325358
326359 constructor ( type : GestureTypes ) {
327360 this . eventName = gestureToString ( type ) ;
328361 this . type = type ;
329362 }
330363
331- public prepare ( view : View , eventData ) {
364+ public prepare ( view : View , event ) {
332365 this . view = view ;
333366 this . object = view ;
367+ this . ios = event . ios ;
368+ this . android = event . android ;
334369 this . _activePointers = undefined ;
335370 this . _allPointers = undefined ;
336- this . eventData = eventData ;
371+ this . eventData = event . data ;
337372 switch ( this . eventData . state ) {
338373 case GestureState . BEGAN :
339374 this . state = GestureStateTypes . began ;
@@ -362,8 +397,12 @@ class CommonGestureEventData implements GestureEventData {
362397 getActivePointers ( ) {
363398 // Only one active pointer in Android
364399 if ( ! this . _activePointers ) {
365- const positions = this . extraData . positions ;
366- this . _activePointers = [ new GesturePointer ( 0 , positions [ 0 ] , positions [ 1 ] ) ] ;
400+ if ( __ANDROID__ ) {
401+ const positions = this . extraData . positions ;
402+ this . _activePointers = [ new GesturePointer ( 0 , positions [ 0 ] , positions [ 1 ] ) ] ;
403+ } else {
404+ this . _activePointers = [ new Pointer ( this . ios , this . view ) ] ;
405+ }
367406 }
368407 return this . _activePointers ;
369408 }
@@ -373,7 +412,11 @@ class CommonGestureEventData implements GestureEventData {
373412 this . _allPointers = [ ] ;
374413 const positions = this . extraData . positions ;
375414 for ( let i = 0 ; i < this . getPointerCount ( ) ; i ++ ) {
376- this . _allPointers . push ( new GesturePointer ( i , positions [ i * 2 ] , positions [ i * 2 + 1 ] ) ) ;
415+ if ( __ANDROID__ ) {
416+ this . _allPointers . push ( new GesturePointer ( i , positions [ i * 2 ] , positions [ i * 2 + 1 ] ) ) ;
417+ } else {
418+ this . _allPointers = [ new Pointer ( this . ios , this . view , { x : positions [ i * 2 ] , y : positions [ i * 2 + 1 ] } ) ] ;
419+ }
377420 }
378421 }
379422 return this . _allPointers ;
@@ -404,7 +447,7 @@ class CommonGestureEventData implements GestureEventData {
404447 return '' ;
405448 }
406449}
407- class TouchGestureEventData {
450+ class AndroidTouchGestureEventData {
408451 eventName : string = gestureToString ( GestureTypes . touch ) ;
409452 type : GestureTypes = GestureTypes . touch ;
410453 ios : any = undefined ;
@@ -415,8 +458,8 @@ class TouchGestureEventData {
415458 state : GestureStateTypes ;
416459 handler : Handler < any , any > ;
417460
418- private _activePointers : Pointer [ ] ;
419- private _allPointers : Pointer [ ] ;
461+ private _activePointers : AndroidPointer [ ] ;
462+ private _allPointers : AndroidPointer [ ] ;
420463
421464 public prepare ( view : View , e : android . view . MotionEvent ) {
422465 this . view = view ;
@@ -431,19 +474,19 @@ class TouchGestureEventData {
431474 return this . android . getPointerCount ( ) ;
432475 }
433476
434- getActivePointers ( ) : Pointer [ ] {
477+ getActivePointers ( ) : AndroidPointer [ ] {
435478 // Only one active pointer in Android
436479 if ( ! this . _activePointers ) {
437- this . _activePointers = [ new Pointer ( this . android . getActionIndex ( ) , this . android ) ] ;
480+ this . _activePointers = [ new AndroidPointer ( this . android . getActionIndex ( ) , this . android ) ] ;
438481 }
439482 return this . _activePointers ;
440483 }
441484
442- getAllPointers ( ) : Pointer [ ] {
485+ getAllPointers ( ) : AndroidPointer [ ] {
443486 if ( ! this . _allPointers ) {
444487 this . _allPointers = [ ] ;
445488 for ( let i = 0 ; i < this . getPointerCount ( ) ; i ++ ) {
446- this . _allPointers . push ( new Pointer ( i , this . android ) ) ;
489+ this . _allPointers . push ( new AndroidPointer ( i , this . android ) ) ;
447490 }
448491 }
449492 return this . _allPointers ;
0 commit comments